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| {
|
||||||
if !outdir.exists() {
|
let mut outdir = dir.to_path_buf();
|
||||||
fs::create_dir_all(&outdir)?;
|
let base = match *gen {
|
||||||
}
|
"bash" => ["share", "bash-completion", "completions"],
|
||||||
let path = generate_to(shells::Bash, &mut cmd, PROGNAME, outdir)?;
|
"zsh" => ["share", "zsh", "site-functions"],
|
||||||
println!(" {}", path.display());
|
"nu" => ["share", "nu", "completions"],
|
||||||
let mut outdir = dir.to_path_buf();
|
"pwsh" => ["share", "pwsh", "completions"],
|
||||||
["share", "zsh", "site-functions"]
|
"fish" => ["share", "fish", "completions"],
|
||||||
.iter()
|
_ => unimplemented!(),
|
||||||
.for_each(|d| outdir.push(d));
|
};
|
||||||
if !outdir.exists() {
|
base.iter().for_each(|d| outdir.push(d));
|
||||||
fs::create_dir_all(&outdir)?;
|
if !outdir.exists() {
|
||||||
}
|
fs::create_dir_all(&outdir)?;
|
||||||
let path = generate_to(shells::Zsh, &mut cmd, PROGNAME, outdir)?;
|
}
|
||||||
println!(" {}", path.display());
|
gencomp(outdir, gen)
|
||||||
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