Skip to content

Commit fdd2df8

Browse files
committed
refactor
1 parent 215c3ac commit fdd2df8

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/plumbing/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ use std::{
77
},
88
};
99

10-
use anyhow::{Context, Result};
10+
use anyhow::{anyhow, Context, Result};
1111
use clap::{CommandFactory, Parser};
12-
use clap_complete::{generate, generate_to};
1312
use gitoxide_core as core;
1413
use gitoxide_core::{pack::verify, repository::PathsOrPatterns};
1514
use gix::bstr::{io::BufReadExt, BString};
@@ -1220,15 +1219,16 @@ pub fn main() -> Result<()> {
12201219
},
12211220
),
12221221
},
1223-
Subcommands::GenerateCompletions { shell, out_dir } => {
1222+
Subcommands::Completions { shell, out_dir } => {
12241223
let mut app = Args::command();
1225-
1224+
let shell = shell
1225+
.or_else(clap_complete::Shell::from_env)
1226+
.ok_or_else(|| anyhow!("The shell could not be derived from the environment"))?;
12261227
if let Some(out_dir) = out_dir {
1227-
generate_to(shell, &mut app, env!("CARGO_PKG_NAME"), &out_dir)?;
1228+
clap_complete::generate_to(shell, &mut app, env!("CARGO_PKG_NAME"), &out_dir)?;
12281229
} else {
1229-
generate(shell, &mut app, env!("CARGO_PKG_NAME"), &mut std::io::stdout());
1230+
clap_complete::generate(shell, &mut app, env!("CARGO_PKG_NAME"), &mut std::io::stdout());
12301231
}
1231-
12321232
Ok(())
12331233
}
12341234
}?;

src/plumbing/options/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ pub enum Subcommands {
135135
/// Subcommands that need no git repository to run.
136136
#[clap(subcommand)]
137137
Free(free::Subcommands),
138-
/// Generate shell completions
139-
GenerateCompletions {
140-
/// Shell for generating completions.
141-
#[clap(long, short)]
142-
shell: Shell,
143-
/// Output directory. If not provided, will write to stdout.
138+
/// Generate shell completions to stdout or a directory.
139+
#[clap(visible_alias = "generate-completions", visible_alias = "shell-completions")]
140+
Completions {
141+
/// The shell to generate completions for. Otherwise it's derived from the environment.
144142
#[clap(long, short)]
143+
shell: Option<Shell>,
144+
/// The output directory in case multiple files are generated. If not provided, will write to stdout.
145145
out_dir: Option<String>,
146146
},
147147
}

0 commit comments

Comments
 (0)