diff --git a/Cargo.toml b/Cargo.toml index 3d23c71..69b720f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,8 @@ +[workspace] +members = [ + "interactive_clap_derive", +] + [package] name = "interactive_clap" version = "0.1.0" @@ -6,7 +11,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -interactive_clap_derive = { path = "./interactive_clap_derive" } +interactive_clap_derive = { path = "interactive_clap_derive" } near-ledger = { version = "0.1.1", optional = true } diff --git a/examples/simple_struct.rs b/examples/simple_struct.rs index 673f9c7..cb55998 100644 --- a/examples/simple_struct.rs +++ b/examples/simple_struct.rs @@ -6,7 +6,7 @@ // ./simple_struct 30 QWE QWERTY => args: Ok(Args { age: 30, first_name: "QWE", second_name: "QWERTY" }) // To learn more about the parameters, use "help" flag: ./simple_struct --help -#[derive(Debug, interactive_clap_derive::InteractiveClap)] +#[derive(Debug, interactive_clap::InteractiveClap)] struct Args { age: u64, first_name: String, diff --git a/interactive_clap_derive/Cargo.lock b/interactive_clap_derive/Cargo_1.lock similarity index 100% rename from interactive_clap_derive/Cargo.lock rename to interactive_clap_derive/Cargo_1.lock diff --git a/src/helpers/mod.rs b/src/helpers/mod.rs new file mode 100644 index 0000000..970a12f --- /dev/null +++ b/src/helpers/mod.rs @@ -0,0 +1,2 @@ +pub mod snake_case_to_camel_case; +pub mod to_kebab_case; diff --git a/src/helpers/snake_case_to_camel_case.rs b/src/helpers/snake_case_to_camel_case.rs new file mode 100644 index 0000000..696b67b --- /dev/null +++ b/src/helpers/snake_case_to_camel_case.rs @@ -0,0 +1,8 @@ +pub fn snake_case_to_camel_case(s: String) -> String { + let s_vec: Vec = s + .to_lowercase() + .split("_") + .map(|s| s.replacen(&s[..1], &s[..1].to_ascii_uppercase(), 1)) + .collect(); + s_vec.join("") +} diff --git a/src/helpers/to_kebab_case.rs b/src/helpers/to_kebab_case.rs new file mode 100644 index 0000000..288e9df --- /dev/null +++ b/src/helpers/to_kebab_case.rs @@ -0,0 +1,10 @@ +pub fn to_kebab_case(s: String) -> String { + let mut snake = String::new(); + for (i, ch) in s.char_indices() { + if i > 0 && ch.is_uppercase() { + snake.push('-'); + } + snake.push(ch.to_ascii_lowercase()); + } + snake.as_str().replace("_", "-") +} diff --git a/src/lib.rs b/src/lib.rs index b584239..5504150 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,20 @@ +//! The Interactive-clap library is an add-on for the Command Line Argument +//! Parser (https://crates.io/crates/clap). Interactive-clap allows you to parse +//! command line options. The peculiarity of this macro is that in the absence +//! of command line parameters, the interactive mode of entering these data by +//! the user is activated. + + +pub use interactive_clap_derive::{InteractiveClap, ToCliArgs}; + +// pub trait InteractiveClap { +// fn interactive_clap(); +// } + +// pub trait ToCliArgs { +// fn to_cli_args(); +// } + pub trait ToCli { type CliVariant; }