diff --git a/src/main.rs b/src/main.rs index 3eba3b566..d904ffec8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -145,9 +145,9 @@ impl App { return; } - //ロゴと時間が表示さないように実行したい + //ロゴと時間が表示さないように実行したいので、この位置 if let Action::AutoComplete(_) = &stored_static.config.action.as_ref().unwrap() { - auto_complete(app); + auto_complete(app, stored_static.output_path.as_ref()); return; } diff --git a/src/options/auto_complete.rs b/src/options/auto_complete.rs index c5da47b2a..8a92979b7 100644 --- a/src/options/auto_complete.rs +++ b/src/options/auto_complete.rs @@ -1,13 +1,15 @@ -use clap_complete::{generate, Generator, Shell}; +use std::{env, path::PathBuf}; + +use clap_complete::{generate_to, Generator, Shell}; use dialoguer::Select; -pub fn auto_complete(app: &mut clap::Command) { +pub fn auto_complete(app: &mut clap::Command, output_path: Option<&PathBuf>) { let shell = select_shell(); - print_completer(shell, app); + print_completer(shell, app, output_path); } fn select_shell() -> Shell { - let items:Vec = vec![Shell::Bash, Shell::Elvish, Shell::Fish, Shell::PowerShell, Shell::Zsh]; + let items:Vec = vec![Shell::Bash, Shell::Elvish, Shell::Fish, Shell::PowerShell]; let selection = Select::new() .with_prompt("Which shell are you using?") @@ -17,8 +19,12 @@ fn select_shell() -> Shell { items[selection] } -fn print_completer(generator: G, app: &mut clap::Command) { - let name = app.get_name().to_owned(); +fn print_completer(generator: G, app: &mut clap::Command, output_path: Option<&PathBuf>) { + let mut name = "auto-complete".to_string(); + if output_path.is_some() { + name = output_path.unwrap().to_str().unwrap().to_string(); + } + let out_dir: PathBuf = env::current_dir().expect("can't get current directory"); - generate(generator, app, name, &mut std::io::stdout()); + let _ = generate_to(generator, app, name, out_dir); } \ No newline at end of file