Files
archived-interactive-clap/src/lib.rs
FroVolod 8593aba469 Changed library "dialoguer" to "inquire" (#3)
* start

* removed "dialoguer"

* modified example files

* modified "Select" for to_cli_args

* modified choose_variant
2022-12-13 17:47:50 +02:00

57 lines
1.4 KiB
Rust

//! 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 ToCli {
type CliVariant;
}
impl ToCli for String {
type CliVariant = String;
}
impl ToCli for u128 {
type CliVariant = u128;
}
impl ToCli for u64 {
type CliVariant = u64;
}
pub trait ToInteractiveClapContextScope {
type InteractiveClapContextScope;
}
pub trait ToCliArgs {
fn to_cli_args(&self) -> std::collections::VecDeque<String>;
}
pub trait FromCli {
type FromCliContext;
type FromCliError;
fn from_cli(
optional_clap_variant: Option<<Self as ToCli>::CliVariant>,
context: Self::FromCliContext,
) -> Result<Option<Self>, Self::FromCliError>
where
Self: Sized + ToCli;
}
pub enum SelectVariantOrBack<T: strum::EnumMessage> {
Variant(T),
Back,
}
impl<T: strum::EnumMessage> std::fmt::Display for SelectVariantOrBack<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Self::Variant(variant) = self {
f.write_str(variant.get_message().unwrap())
} else {
f.write_str("back")
}
}
}