-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use clap::{Command, CommandFactory}; | ||
use clap_complete::Shell; | ||
use std::fs::File; | ||
use std::path::Path; | ||
|
||
include!("src/cli.rs"); | ||
const APP_NAME: &str = "unicom"; | ||
|
||
fn generate(s: Shell, app: &mut Command, outdir: &Path, file: &str) { | ||
let destfile = outdir.join(file); | ||
println!("dest: {}", destfile.display()); | ||
|
||
std::fs::create_dir_all(destfile.parent().unwrap()).unwrap(); | ||
let mut dest = File::create(destfile).unwrap(); | ||
clap_complete::generate(s, app, APP_NAME, &mut dest); | ||
} | ||
|
||
fn main() { | ||
let mut app = Args::command(); | ||
app.set_bin_name(APP_NAME); | ||
|
||
let outdir = Path::new(env!("CARGO_MANIFEST_DIR")).join("target/completions/"); | ||
generate(Shell::Bash, &mut app, &outdir, "unicom-completion.bash"); | ||
generate(Shell::Zsh, &mut app, &outdir, "_unicom"); | ||
generate(Shell::Fish, &mut app, &outdir, "unicom-completion.fish"); | ||
generate( | ||
Shell::PowerShell, | ||
&mut app, | ||
&outdir, | ||
"unicom-completion.ps1", | ||
); | ||
generate(Shell::Elvish, &mut app, &outdir, "unicom-completion.elv"); | ||
} |