Skip to content

Commit

Permalink
Add compile time completion generation
Browse files Browse the repository at this point in the history
  • Loading branch information
willwill2will54 committed Jul 4, 2024
1 parent cf5ad2a commit c87bf2a
Show file tree
Hide file tree
Showing 10 changed files with 4,741 additions and 3 deletions.
7 changes: 7 additions & 0 deletions packages/perseus-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ walkdir = "2"
openssl = { version = "0.10.52", optional = true}
brotlic = "0.8"

[build-dependencies]
clap = { version = "4.2", features = ["color", "derive"], optional = true }
clap_complete = { version = "4.5.7", optional = true }
clap_complete_nushell = { version = "4.5.2", optional = true }

[dev-dependencies]
assert_cmd = "2"
assert_fs = "1"
Expand All @@ -70,5 +75,7 @@ name = "perseus"
path = "src/bin/main.rs"

[features]
default = ["completions"]
completions = ["clap", "clap_complete", "clap_complete_nushell"]
# `reqwest` uses the system-native transport layer by default, this is necessary in some environments
vendored-openssl = [ "openssl/vendored" ]
33 changes: 33 additions & 0 deletions packages/perseus-cli/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#[cfg(feature = "completions")]
mod completions {
#[path = "../src/parse.rs"]
mod parse;

use clap::{CommandFactory, ValueEnum};
use clap_complete::{generate_to, shells::Shell};
use clap_complete_nushell::Nushell;
use std::io::Error;

pub fn generate_completions() -> Result<(), Error> {
let out_dir = "completions";
let bin_name = "perseus";
// on windows, bin_name is "perseus.exe"
#[cfg(windows)]
let bin_name = "perseus.exe";

let mut cmd = parse::Opts::command();

for shell in Shell::value_variants() {
generate_to(*shell, &mut cmd, bin_name, out_dir)?;
}
generate_to(Nushell, &mut cmd, bin_name, out_dir)?;

Ok(())
}
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "completions")]
completions::generate_completions()?;
Ok(())
}
878 changes: 878 additions & 0 deletions packages/perseus-cli/completions/_perseus

Large diffs are not rendered by default.

589 changes: 589 additions & 0 deletions packages/perseus-cli/completions/_perseus.ps1

Large diffs are not rendered by default.

Loading

0 comments on commit c87bf2a

Please sign in to comment.