diff options
| -rw-r--r-- | Cargo.lock | 7 | ||||
| -rw-r--r-- | Cargo.toml | 5 | ||||
| -rw-r--r-- | cli/Cargo.toml | 9 | ||||
| -rw-r--r-- | cli/src/main.rs | 24 | ||||
| -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"); |
