mirror of
https://github.com/Drop-OSS/interactive-clap.git
synced 2026-01-30 20:55:25 +01:00
added help for using examples
This commit is contained in:
@@ -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<CliArgs>,
|
||||
context: (),
|
||||
) -> color_eyre::eyre::Result<Self> {
|
||||
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<u64> {
|
||||
Ok(dialoguer::Input::new()
|
||||
.with_prompt("How old are you?")
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)]
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user