Skip to content

Commit

Permalink
output to file
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuminn committed Jul 20, 2024
1 parent fe54bed commit 0e0bd68
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check warning on line 151 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L150-L151

Added lines #L150 - L151 were not covered by tests
}

Expand Down
20 changes: 13 additions & 7 deletions src/options/auto_complete.rs
Original file line number Diff line number Diff line change
@@ -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);
}

Check warning on line 9 in src/options/auto_complete.rs

View check run for this annotation

Codecov / codecov/patch

src/options/auto_complete.rs#L6-L9

Added lines #L6 - L9 were not covered by tests

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

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

items[selection]
}
fn print_completer<G: Generator>(generator: G, app: &mut clap::Command) {
let name = app.get_name().to_owned();
fn print_completer<G: Generator>(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);
}

Check warning on line 30 in src/options/auto_complete.rs

View check run for this annotation

Codecov / codecov/patch

src/options/auto_complete.rs#L11-L30

Added lines #L11 - L30 were not covered by tests

0 comments on commit 0e0bd68

Please sign in to comment.