mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 13:17:55 +08:00
refactor account with clap derive api
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,2 +1 @@
|
||||
pub mod command;
|
||||
pub mod handler;
|
||||
|
||||
Reference in New Issue
Block a user