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

feat: add shell completion and manpage support #82

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ jobs:

- name: Shellcheck
uses: ludeeus/action-shellcheck@master
with:
ignore_names: >-
action-validator.bash

- name: Install shfmt
uses: mfinelli/setup-shfmt@master
Expand All @@ -75,7 +78,7 @@ jobs:
rust-toolchain:
- stable
- nightly
- 1.64.0
- 1.74.1
os:
- ubuntu-latest
- macos-latest
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "src/schemastore"]
path = src/schemastore
url = https://github.com/SchemaStore/schemastore
url = https://github.com/SchemaStore/schemastore.git
39 changes: 33 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ authors = ["Matt Palmer <matt@hezmatt.org>"]
edition = "2021"
# If this is changed, .github/workflows/qa.yml build matrix needs updating as well
rust-version = "1.60.0"
build = "build.rs"

[lib]
crate-type = ["cdylib", "rlib"]
Expand All @@ -23,7 +24,7 @@ crate-type = ["cdylib", "rlib"]
js = ["console_error_panic_hook", "valico/js"]

[dependencies]
clap = { version = "4.0", features = ["derive"] }
clap = { version = "4.5.23", features = ["derive"] }
glob = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand All @@ -41,6 +42,11 @@ console_error_panic_hook = { version = "0.1.6", optional = true }

serde-wasm-bindgen = "0.4.5"

[build-dependencies]
clap = { version = "4.5", features = ["derive"] }
clap_complete = "4.2"
clap_mangen = "0.2"

[dev-dependencies]
wasm-bindgen-test = "0.3.13"

Expand Down
40 changes: 40 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use std::{fs, io::Result, path::PathBuf};

use clap::{CommandFactory, ValueEnum};
use clap_complete::{generate_to, Shell};
use clap_mangen::generate_to as generate_manpage;

mod cli {
include!("src/cli.rs");
}

fn main() -> Result<()> {
println!("cargo:rerun-if-changed=src/cli.rs");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=GEN_DIR");

if let Some(out_path) = std::env::var_os("GEN_DIR").or(std::env::var_os("OUT_DIR")) {
let out_dir = PathBuf::from(out_path);

// Generate manpage
let man_dir = out_dir.join("man");
fs::create_dir_all(&man_dir)?;
let mut cmd = cli::CliConfig::command();
generate_manpage(cmd.clone(), &man_dir)?;

// Generate shell completions
let completions_dir = out_dir.join("completions");
fs::create_dir_all(&completions_dir)?;

for shell in Shell::value_variants() {
generate_to(*shell, &mut cmd, "action-validator", &completions_dir)?;
}
}

println!(
"cargo:rustc-env=TARGET={}",
std::env::var("TARGET").unwrap()
);

Ok(())
}
Loading