refactor account with clap derive api

This commit is contained in:
Clément DOUIN
2023-12-06 18:09:49 +01:00
parent d2308221d7
commit abe4c7f4ea
21 changed files with 1056 additions and 1029 deletions
+24 -2
View File
@@ -1,10 +1,32 @@
use clap::{value_parser, Parser};
use anyhow::Result;
use clap::{value_parser, CommandFactory, Parser};
use clap_complete::Shell;
use log::info;
use std::io;
use crate::{cli::Cli, printer::Printer};
/// Print completion script for the given shell to stdout
#[derive(Debug, Parser)]
pub struct Generate {
pub struct Command {
/// Shell that completion script should be generated for
#[arg(value_parser = value_parser!(Shell))]
pub shell: Shell,
}
impl Command {
pub async fn execute(self, printer: &mut impl Printer) -> Result<()> {
info!("executing completion generate command");
let mut cmd = Cli::command();
let name = cmd.get_name().to_string();
clap_complete::generate(self.shell, &mut cmd, name, &mut io::stdout());
printer.print(format!(
"Shell script successfully generated for shell {}!",
self.shell
))?;
Ok(())
}
}
-18
View File
@@ -1,18 +0,0 @@
use anyhow::Result;
use clap::Command;
use clap_complete::Shell;
use std::io::stdout;
use crate::printer::Printer;
pub fn generate(printer: &mut impl Printer, mut cmd: Command, shell: Shell) -> Result<()> {
let name = cmd.get_name().to_string();
clap_complete::generate(shell, &mut cmd, name, &mut stdout());
printer.print(format!(
"Shell script successfully generated for shell {shell}!"
))?;
Ok(())
}
-1
View File
@@ -1,2 +1 @@
pub mod command;
pub mod handler;