about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2021-09-20 17:36:40 +0200
committerMel <einebeere@gmail.com>2021-09-20 17:36:40 +0200
commit8bcbf51cf4f7924600eae39db67ff653b48ad95d (patch)
tree6ee9ea655c1c983938d9dde63bb68dcb26342b89
parent7667695eba44f94c064708f5f4c54f78d685b024 (diff)
downloadka-8bcbf51cf4f7924600eae39db67ff653b48ad95d.tar.zst
ka-8bcbf51cf4f7924600eae39db67ff653b48ad95d.zip
Extract CLI
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml5
-rw-r--r--cli/Cargo.toml9
-rw-r--r--cli/src/main.rs24
-rw-r--r--src/lib.rs (renamed from src/main.rs)28
5 files changed, 47 insertions, 26 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 66a29be..b3292b2 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -24,6 +24,13 @@ dependencies = [
 ]
 
 [[package]]
+name = "ka-cli"
+version = "0.1.0"
+dependencies = [
+ "ka",
+]
+
+[[package]]
 name = "proc-macro2"
 version = "1.0.29"
 source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 8e83cc7..6c055ec 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -8,4 +8,7 @@ edition = "2018"
 [dependencies]
 serde = {version = "1.0", features = ["derive"] }
 serde_json = "1.0"
-difference = "2.0.0"
\ No newline at end of file
+difference = "2.0.0"
+
+[workspace]
+members = ["cli"]
\ No newline at end of file
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
new file mode 100644
index 0000000..a1d090c
--- /dev/null
+++ b/cli/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "ka-cli"
+version = "0.1.0"
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+ka = { path = "../" }
\ No newline at end of file
diff --git a/cli/src/main.rs b/cli/src/main.rs
new file mode 100644
index 0000000..945da3a
--- /dev/null
+++ b/cli/src/main.rs
@@ -0,0 +1,24 @@
+use std::env;
+
+use ka::{create_command, shift_command, update_command};
+
+fn main() {
+    let args: Vec<String> = env::args().collect();
+    let command = args[1].as_str();
+    match command {
+        "create" => {
+            create_command().unwrap();
+        }
+        "update" => {
+            update_command().unwrap();
+        }
+        "shift" => {
+            let file_path = args[2].as_str();
+
+            let new_cursor: usize = args[3].as_str().parse().expect("Invalid cursor.");
+
+            shift_command(file_path, new_cursor);
+        }
+        _ => println!("Unknown command: {}", command),
+    }
+}
diff --git a/src/main.rs b/src/lib.rs
index fcbb4d0..3a05db5 100644
--- a/src/main.rs
+++ b/src/lib.rs
@@ -1,35 +1,13 @@
 use difference::{Changeset, Difference};
 use serde::{Deserialize, Serialize};
 use std::{
-    env,
     fs::{self, DirEntry, File, OpenOptions},
     io::{self, Read, Seek, Write},
     path::{Path, PathBuf},
     vec,
 };
 
-fn main() {
-    let args: Vec<String> = env::args().collect();
-    let command = args[1].as_str();
-    match command {
-        "create" => {
-            create_command().unwrap();
-        }
-        "update" => {
-            update_command().unwrap();
-        }
-        "shift" => {
-            let file_path = args[2].as_str();
-
-            let new_cursor: usize = args[3].as_str().parse().expect("Invalid cursor.");
-
-            shift_command(file_path, new_cursor);
-        }
-        _ => println!("Unknown command: {}", command),
-    }
-}
-
-fn create_command() -> io::Result<()> {
+pub fn create_command() -> io::Result<()> {
     let repository_directory = Path::new("./repository");
 
     let ka_directory = repository_directory.join(".ka");
@@ -47,7 +25,7 @@ fn create_command() -> io::Result<()> {
     Ok(())
 }
 
-fn update_command() -> io::Result<()> {
+pub fn update_command() -> io::Result<()> {
     let repository_directory = Path::new("./repository");
 
     let ka_directory = repository_directory.join(".ka");
@@ -65,7 +43,7 @@ fn update_command() -> io::Result<()> {
     Ok(())
 }
 
-fn shift_command(path: &str, new_cursor: usize) {
+pub fn shift_command(path: &str, new_cursor: usize) {
     let repository_directory = Path::new("./repository");
 
     let ka_directory = repository_directory.join(".ka");