use interactive_clap::{ResultFromCli, ToCliArgs};
#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
pub struct Args {
age: u64,
first_name: String,
second_name: String,
}
fn main() -> color_eyre::Result<()> {
let mut cli_args = Args::parse();
let context = (); loop {
let args = <Args as interactive_clap::FromCli>::from_cli(Some(cli_args), context);
match args {
ResultFromCli::Ok(cli_args) | ResultFromCli::Cancel(Some(cli_args)) => {
println!(
"Your console command: {}",
shell_words::join(cli_args.to_cli_args())
);
return Ok(());
}
ResultFromCli::Cancel(None) => {
println!("Goodbye!");
return Ok(());
}
ResultFromCli::Back => {
cli_args = Default::default();
}
ResultFromCli::Err(cli_args, err) => {
if let Some(cli_args) = cli_args {
println!(
"Your console command: {}",
shell_words::join(cli_args.to_cli_args())
);
}
return Err(err);
}
}
}
}