Skip to content

Commit 0e0bd68

Browse files
committed
output to file
1 parent fe54bed commit 0e0bd68

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ impl App {
145145
return;
146146
}
147147

148-
//ロゴと時間が表示さないように実行したい
148+
//ロゴと時間が表示さないように実行したいので、この位置
149149
if let Action::AutoComplete(_) = &stored_static.config.action.as_ref().unwrap() {
150-
auto_complete(app);
150+
auto_complete(app, stored_static.output_path.as_ref());
151151
return;
152152
}
153153

src/options/auto_complete.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
use clap_complete::{generate, Generator, Shell};
1+
use std::{env, path::PathBuf};
2+
3+
use clap_complete::{generate_to, Generator, Shell};
24
use dialoguer::Select;
35

4-
pub fn auto_complete(app: &mut clap::Command) {
6+
pub fn auto_complete(app: &mut clap::Command, output_path: Option<&PathBuf>) {
57
let shell = select_shell();
6-
print_completer(shell, app);
8+
print_completer(shell, app, output_path);
79
}
810

911
fn select_shell() -> Shell {
10-
let items:Vec<Shell> = vec![Shell::Bash, Shell::Elvish, Shell::Fish, Shell::PowerShell, Shell::Zsh];
12+
let items:Vec<Shell> = vec![Shell::Bash, Shell::Elvish, Shell::Fish, Shell::PowerShell];
1113

1214
let selection = Select::new()
1315
.with_prompt("Which shell are you using?")
@@ -17,8 +19,12 @@ fn select_shell() -> Shell {
1719

1820
items[selection]
1921
}
20-
fn print_completer<G: Generator>(generator: G, app: &mut clap::Command) {
21-
let name = app.get_name().to_owned();
22+
fn print_completer<G: Generator>(generator: G, app: &mut clap::Command, output_path: Option<&PathBuf>) {
23+
let mut name = "auto-complete".to_string();
24+
if output_path.is_some() {
25+
name = output_path.unwrap().to_str().unwrap().to_string();
26+
}
27+
let out_dir: PathBuf = env::current_dir().expect("can't get current directory");
2228

23-
generate(generator, app, name, &mut std::io::stdout());
29+
let _ = generate_to(generator, app, name, out_dir);
2430
}

0 commit comments

Comments
 (0)