diff --git a/examples/advanced_struct.rs b/examples/advanced_struct.rs index 9679254..34ddaf1 100644 --- a/examples/advanced_struct.rs +++ b/examples/advanced_struct.rs @@ -1,13 +1,16 @@ -// cargo run --example simple_struct -- --age-full-years 30 --first-name QWE --second-name QWERTY => +// 1) build an example: cargo build --example advanced_struct +// 2) go to the `examples` folder: cd target/debug/examples +// 3) run an example: ./advanced_struct (without parameters) => entered interactive mode +// ./advanced_struct --age-full-years 30 --first-name QWE --second-name QWERTY => // => args: Ok(Args { age: 30, first_name: "QWE", second_name: "QWERTY" }) +// To learn more about the parameters, use "help" flag: ./advanced_struct --help -// cargo run --example simple_struct => entered interactive mode #[derive(Debug, interactive_clap_derive::InteractiveClap)] #[interactive_clap(skip_default_from_cli)] struct Args { #[interactive_clap(long = "age-full-years")] // hgfashdgfajdfsadajsdfh - #[interactive_clap(skip_default_from_cli)] // указать для чего этот атрибут нужен + #[interactive_clap(skip_default_from_cli_arg)] // указать для чего этот атрибут нужен #[interactive_clap(skip_default_input_arg)] age: u64, #[interactive_clap(long)] @@ -19,6 +22,40 @@ struct Args { } impl Args { + pub fn from_cli( + optional_clap_variant: Option, + context: (), + ) -> color_eyre::eyre::Result { + let age = Self::from_cli_age( + optional_clap_variant + .clone() + .and_then(|clap_variant| clap_variant.age), + &context, + )?; + let first_name = Self::from_cli_first_name( + optional_clap_variant + .clone() + .and_then(|clap_variant| clap_variant.first_name), + &context, + )?; + let second_name = Self::from_cli_second_name( + optional_clap_variant + .clone() + .and_then(|clap_variant| clap_variant.second_name), + &context, + )?; + let new_context_scope = InteractiveClapContextScopeForArgs { + age, + first_name, + second_name, + }; + Ok(Self { + age: new_context_scope.age, + first_name: new_context_scope.first_name, + second_name: new_context_scope.second_name, + }) + } + fn input_age(_context: &()) -> color_eyre::eyre::Result { Ok(dialoguer::Input::new() .with_prompt("How old are you?") diff --git a/examples/simple_enum.rs b/examples/simple_enum.rs index 7ee8d99..3d9fff8 100644 --- a/examples/simple_enum.rs +++ b/examples/simple_enum.rs @@ -1,8 +1,9 @@ -// 1) собрать пример: cargo build --example simple_enum -// 2) cd target/debug/examples -// 3) запустить пример: ./simple_enum (без параметров) => entered interactive mode -// ./simple_enum network => mode: Ok(Network) -// ./simple_enum offline => mode: Ok(Offline) +// 1) build an example: cargo build --example simple_enum +// 2) go to the `examples` folder: cd target/debug/examples +// 3) run an example: ./simple_enum (without parameters) => entered interactive mode +// ./simple_enum network => mode: Ok(Network) +// ./simple_enum offline => mode: Ok(Offline) +// To learn more about the parameters, use "help" flag: ./simple_enum --help use dialoguer::{theme::ColorfulTheme, Select}; diff --git a/examples/simple_struct.rs b/examples/simple_struct.rs index b727be9..2257e52 100644 --- a/examples/simple_struct.rs +++ b/examples/simple_struct.rs @@ -1,7 +1,9 @@ -// cargo run --example simple_struct -- --age-full-years 30 --first-name QWE --second-name QWERTY => -// => args: Ok(Args { age: 30, first_name: "QWE", second_name: "QWERTY" }) +// 1) build an example: cargo build --example simple_struct +// 2) go to the `examples` folder: cd target/debug/examples +// 3) run an example: ./simple_struct (without parameters) => entered interactive mode +// ./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 -// cargo run --example simple_struct => entered interactive mode #[derive(Debug, interactive_clap_derive::InteractiveClap)] struct Args { diff --git a/examples/struct_with_context.rs b/examples/struct_with_context.rs index 8bf3ebc..33a8e37 100644 --- a/examples/struct_with_context.rs +++ b/examples/struct_with_context.rs @@ -1,5 +1,9 @@ -// cargo run --example struct_with_context account QWERTY => offline_args: Ok(OfflineArgs { account: Sender { sender_account_id: "QWERTY" } }) -// cargo run --example struct_with_context => entered interactive mode +// 1) build an example: cargo build --example struct_with_context +// 2) go to the `examples` folder: cd target/debug/examples +// 3) run an example: ./struct_with_context (without parameters) => entered interactive mode +// ./struct_with_context account QWERTY => offline_args: Ok(OfflineArgs { account: Sender { sender_account_id: "QWERTY" } }) +// To learn more about the parameters, use "help" flag: ./struct_with_context --help + mod common; diff --git a/examples/struct_with_named_arg.rs b/examples/struct_with_named_arg.rs index d2f1ac2..112273d 100644 --- a/examples/struct_with_named_arg.rs +++ b/examples/struct_with_named_arg.rs @@ -1,5 +1,9 @@ -// cargo run --example struct_with_named_arg account QWERTY => account: Ok(Account { account: Sender { sender_account_id: "QWERTY" } }) -// cargo run --example struct_with_named_arg => entered interactive mode +// 1) build an example: cargo build --example struct_with_named_arg +// 2) go to the `examples` folder: cd target/debug/examples +// 3) run an example: ./struct_with_named_arg (without parameters) => entered interactive mode +// ./struct_with_named_arg account QWERTY => account: Ok(Account { account: Sender { sender_account_id: "QWERTY" } }) +// To learn more about the parameters, use "help" flag: ./struct_with_named_arg --help + use clap::Clap; #[derive(Debug, Clone, interactive_clap_derive::InteractiveClap)] diff --git a/examples/struct_with_subcommand.rs b/examples/struct_with_subcommand.rs index 658e007..5a98cda 100644 --- a/examples/struct_with_subcommand.rs +++ b/examples/struct_with_subcommand.rs @@ -1,6 +1,10 @@ -// cargo run --example struct_with_subcommand offline => operation_mode: Ok(OperationMode { mode: Offline }) -// cargo run --example struct_with_subcommand network => operation_mode: Ok(OperationMode { mode: Network }) -// cargo run --example struct_with_subcommand => entered interactive mode +// 1) build an example: cargo build --example struct_with_subcommand +// 2) go to the `examples` folder: cd target/debug/examples +// 3) run an example: ./struct_with_subcommand (without parameters) => entered interactive mode +// ./struct_with_subcommand network => operation_mode: Ok(OperationMode { mode: Network }) +// ./struct_with_subcommand offline => operation_mode: Ok(OperationMode { mode: Offline }) +// To learn more about the parameters, use "help" flag: ./struct_with_subcommand --help + mod simple_enum; diff --git a/examples/to_cli_args.rs b/examples/to_cli_args.rs index a0f28e0..2e27bef 100644 --- a/examples/to_cli_args.rs +++ b/examples/to_cli_args.rs @@ -1,8 +1,9 @@ -// 1) собрать пример: cargo build --example to_cli_args -// 2) cd target/debug/examples -// 3) запустить пример: ./to_cli_args (без параметров) => entered interactive mode -// ./to_cli_args send => Your console command: send -// ./to_cli_args display => Your console command: display +// 1) build an example: cargo build --example to_cli_args +// 2) go to the `examples` folder: cd target/debug/examples +// 3) run an example: ./to_cli_args (without parameters) => entered interactive mode +// ./to_cli_args send => Your console command: send +// ./to_cli_args display => Your console command: display +// To learn more about the parameters, use "help" flag: ./to_cli_args --help use dialoguer::{theme::ColorfulTheme, Select};