Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Oct 10, 2023
1 parent 215c3ac commit fdd2df8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ use std::{
},
};

use anyhow::{Context, Result};
use anyhow::{anyhow, Context, Result};
use clap::{CommandFactory, Parser};
use clap_complete::{generate, generate_to};
use gitoxide_core as core;
use gitoxide_core::{pack::verify, repository::PathsOrPatterns};
use gix::bstr::{io::BufReadExt, BString};
Expand Down Expand Up @@ -1220,15 +1219,16 @@ pub fn main() -> Result<()> {
},
),
},
Subcommands::GenerateCompletions { shell, out_dir } => {
Subcommands::Completions { shell, out_dir } => {
let mut app = Args::command();

let shell = shell
.or_else(clap_complete::Shell::from_env)
.ok_or_else(|| anyhow!("The shell could not be derived from the environment"))?;
if let Some(out_dir) = out_dir {
generate_to(shell, &mut app, env!("CARGO_PKG_NAME"), &out_dir)?;
clap_complete::generate_to(shell, &mut app, env!("CARGO_PKG_NAME"), &out_dir)?;
} else {
generate(shell, &mut app, env!("CARGO_PKG_NAME"), &mut std::io::stdout());
clap_complete::generate(shell, &mut app, env!("CARGO_PKG_NAME"), &mut std::io::stdout());
}

Ok(())
}
}?;
Expand Down
12 changes: 6 additions & 6 deletions src/plumbing/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ pub enum Subcommands {
/// Subcommands that need no git repository to run.
#[clap(subcommand)]
Free(free::Subcommands),
/// Generate shell completions
GenerateCompletions {
/// Shell for generating completions.
#[clap(long, short)]
shell: Shell,
/// Output directory. If not provided, will write to stdout.
/// Generate shell completions to stdout or a directory.
#[clap(visible_alias = "generate-completions", visible_alias = "shell-completions")]
Completions {
/// The shell to generate completions for. Otherwise it's derived from the environment.
#[clap(long, short)]
shell: Option<Shell>,
/// The output directory in case multiple files are generated. If not provided, will write to stdout.
out_dir: Option<String>,
},
}
Expand Down

0 comments on commit fdd2df8

Please sign in to comment.