Made completions generation more generic
This commit is contained in:
parent
e345ca6abb
commit
33955fa836
@ -6,54 +6,40 @@ use {
|
|||||||
|
|
||||||
static PROGNAME: &str = "hpk";
|
static PROGNAME: &str = "hpk";
|
||||||
|
|
||||||
|
fn gencomp(outdir: PathBuf, gen:&str) -> Result<(), Box<dyn Error>> {
|
||||||
|
let mut cmd = cli::cli();
|
||||||
|
let path = match gen {
|
||||||
|
"bash" => generate_to(shells::Bash, &mut cmd, PROGNAME, outdir)?,
|
||||||
|
"fish" => generate_to(shells::Fish, &mut cmd, PROGNAME, outdir)?,
|
||||||
|
"nu" => generate_to(Nushell, &mut cmd, PROGNAME, outdir)?,
|
||||||
|
"pwsh" => generate_to(shells::PowerShell, &mut cmd, PROGNAME, outdir)?,
|
||||||
|
"zsh" => generate_to(shells::Zsh, &mut cmd, PROGNAME, outdir)?,
|
||||||
|
_ => unimplemented!(),
|
||||||
|
};
|
||||||
|
println!(" {}", path.display());
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn completions<P: Deref<Target = Path>>(dir: P) -> Result<(), Box<dyn Error>> {
|
fn completions<P: Deref<Target = Path>>(dir: P) -> Result<(), Box<dyn Error>> {
|
||||||
println!("Generating completions:");
|
println!("Generating completions:");
|
||||||
let mut cmd = cli::cli();
|
["bash", "fish", "nu", "pwsh", "zsh"]
|
||||||
let mut outdir = dir.to_path_buf();
|
|
||||||
["share", "bash-completion", "completions"]
|
|
||||||
.iter()
|
.iter()
|
||||||
.for_each(|d| outdir.push(d));
|
.try_for_each(|gen| {
|
||||||
|
let mut outdir = dir.to_path_buf();
|
||||||
|
let base = match *gen {
|
||||||
|
"bash" => ["share", "bash-completion", "completions"],
|
||||||
|
"zsh" => ["share", "zsh", "site-functions"],
|
||||||
|
"nu" => ["share", "nu", "completions"],
|
||||||
|
"pwsh" => ["share", "pwsh", "completions"],
|
||||||
|
"fish" => ["share", "fish", "completions"],
|
||||||
|
_ => unimplemented!(),
|
||||||
|
};
|
||||||
|
base.iter().for_each(|d| outdir.push(d));
|
||||||
if !outdir.exists() {
|
if !outdir.exists() {
|
||||||
fs::create_dir_all(&outdir)?;
|
fs::create_dir_all(&outdir)?;
|
||||||
}
|
}
|
||||||
let path = generate_to(shells::Bash, &mut cmd, PROGNAME, outdir)?;
|
gencomp(outdir, gen)
|
||||||
println!(" {}", path.display());
|
})?;
|
||||||
let mut outdir = dir.to_path_buf();
|
|
||||||
["share", "zsh", "site-functions"]
|
|
||||||
.iter()
|
|
||||||
.for_each(|d| outdir.push(d));
|
|
||||||
if !outdir.exists() {
|
|
||||||
fs::create_dir_all(&outdir)?;
|
|
||||||
}
|
|
||||||
let path = generate_to(shells::Zsh, &mut cmd, PROGNAME, outdir)?;
|
|
||||||
println!(" {}", path.display());
|
|
||||||
let mut outdir = dir.to_path_buf();
|
|
||||||
["share", "fish", "completions"]
|
|
||||||
.iter()
|
|
||||||
.for_each(|d| outdir.push(d));
|
|
||||||
if !outdir.exists() {
|
|
||||||
fs::create_dir_all(&outdir)?;
|
|
||||||
}
|
|
||||||
let path = generate_to(shells::Fish, &mut cmd, PROGNAME, outdir)?;
|
|
||||||
println!(" {}", path.display());
|
|
||||||
let mut outdir = dir.to_path_buf();
|
|
||||||
["share", "pwsh", "completions"]
|
|
||||||
.iter()
|
|
||||||
.for_each(|d| outdir.push(d));
|
|
||||||
if !outdir.exists() {
|
|
||||||
fs::create_dir_all(&outdir)?;
|
|
||||||
}
|
|
||||||
let path = generate_to(shells::PowerShell, &mut cmd, PROGNAME, outdir)?;
|
|
||||||
println!(" {}", path.display());
|
|
||||||
let mut outdir = dir.to_path_buf();
|
|
||||||
["share", "nu", "completions"]
|
|
||||||
.iter()
|
|
||||||
.for_each(|d| outdir.push(d));
|
|
||||||
if !outdir.exists() {
|
|
||||||
fs::create_dir_all(&outdir)?;
|
|
||||||
}
|
|
||||||
let path = generate_to(Nushell, &mut cmd, PROGNAME, outdir)?;
|
|
||||||
println!(" {}", path.display());
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user