-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add shell completion and manpage support
Signed-off-by: Rui Chen <rui@chenrui.dev>
- Loading branch information
1 parent
6573ff1
commit e41a9d9
Showing
8 changed files
with
106 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/main.rs"); | ||
println!("cargo:rerun-if-changed=src/config.rs"); | ||
|
||
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() | ||
); | ||
println!("cargo:rerun-if-env-changed=GEN_DIR"); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use clap::Parser; | ||
use std::path::PathBuf; | ||
|
||
/// Minimal struct for Clap usage, without Serde | ||
#[derive(Parser, Debug)] | ||
#[command( | ||
name = "action-validator", | ||
about = "A validator for GitHub Action and Workflow YAML files", | ||
version | ||
)] | ||
pub struct CliConfig { | ||
/// Be more verbose | ||
#[arg(short, long)] | ||
pub verbose: bool, | ||
|
||
/// Input file(s) | ||
#[arg(name = "path_to_action_yaml")] | ||
pub src: Vec<PathBuf>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule schemastore
updated
2252 files