Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compile time completion generation #328

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading