-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improved 'xtask' experience, removed old commands.
This commit removes some minimally useful commands from `xtask`, and also rewrites the `xtask` CLI and printing to be more consistent, more helpful, and easier to control. We now use `clap-verbosity-flag` to auto-handle verbosity through the `log` crate, and all printing (outside of auto-printing by `duct`) is handled through `log` and `env_logger`, with `clap-verbosity-flag` applying filtering based on CLI flags. Signed-off-by: Andrew Lilley Brinker <[email protected]>
- Loading branch information
1 parent
4e37ed9
commit f0a5a57
Showing
11 changed files
with
275 additions
and
606 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,132 +1,39 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
mod exit; | ||
mod task; | ||
mod workspace; | ||
|
||
use crate::exit::EXIT_FAILURE; | ||
use crate::exit::EXIT_SUCCESS; | ||
use crate::task::doc::OpenDoc; | ||
use anyhow::Error; | ||
use anyhow::Result; | ||
use clap::crate_version; | ||
use clap::Arg; | ||
use clap::ArgAction; | ||
use clap::ArgMatches; | ||
use clap::Command; | ||
use std::process::exit; | ||
use clap::Parser; | ||
use std::process::ExitCode; | ||
|
||
fn main() { | ||
let matches = Command::new("xtask") | ||
.about("Hipcheck development task runner.") | ||
.version(crate_version!()) | ||
.disable_version_flag(true) | ||
.arg( | ||
Arg::new("help") | ||
.short('h') | ||
.long("help") | ||
.action(ArgAction::SetTrue), | ||
) | ||
.arg( | ||
Arg::new("version") | ||
.short('V') | ||
.long("version") | ||
.action(ArgAction::SetTrue), | ||
) | ||
.subcommand(Command::new("ci")) | ||
.subcommand( | ||
Command::new("doc").arg( | ||
Arg::new("open") | ||
.short('o') | ||
.long("open") | ||
.action(ArgAction::SetTrue), | ||
), | ||
) | ||
.subcommand( | ||
Command::new("bench").arg( | ||
Arg::new("build") | ||
.value_name("build") | ||
.index(1) | ||
.default_value(""), | ||
), | ||
) | ||
.subcommand(Command::new("install")) | ||
.subcommand(Command::new("validate")) | ||
.get_matches(); | ||
fn main() -> ExitCode { | ||
let args = Args::parse(); | ||
|
||
if matches.get_flag("help") { | ||
print_help(); | ||
} | ||
|
||
if matches.get_flag("version") { | ||
print_version(); | ||
} | ||
|
||
if let Err(err) = dispatch(matches) { | ||
print_error(err); | ||
exit(EXIT_FAILURE); | ||
} | ||
} | ||
|
||
fn print_error(err: Error) { | ||
let mut chain = err.chain(); | ||
|
||
// PANIC: First error is guaranteed to be present. | ||
eprintln!("error: {}", chain.next().unwrap()); | ||
env_logger::Builder::new() | ||
.filter_level(args.verbose.log_level_filter()) | ||
.init(); | ||
|
||
for err in chain { | ||
eprintln!(" {}", err); | ||
match args.command { | ||
Commands::Validate => task::validate::run(), | ||
Commands::Ci => task::ci::run(), | ||
} | ||
} | ||
|
||
fn dispatch(matches: ArgMatches) -> Result<()> { | ||
match matches.subcommand() { | ||
Some(("validate", _)) => task::validate::run(), | ||
Some(("install", _)) => task::install::run(), | ||
Some(("ci", _)) => task::ci::run(), | ||
Some(("bench", _)) => task::bench::build(), | ||
Some(("doc", doc)) => { | ||
// PANIC: Should be safe to unwrap, because there is a default value | ||
let open = OpenDoc::from(doc.get_flag("open")); | ||
task::doc::run(open) | ||
} | ||
Some((_, _)) | None => print_help(), | ||
} | ||
} | ||
|
||
fn print_help() -> ! { | ||
let raw_version = env!("CARGO_PKG_VERSION", "can't find xtask package version"); | ||
|
||
let help_text = format!( | ||
"\ | ||
cargo {} {} | ||
{} | ||
USAGE: | ||
cargo {} [FLAGS] [<TASK>] | ||
FLAGS: | ||
-h, --help print help information | ||
-v, --version print version information | ||
TASKS: | ||
ci simulate a CI run locally | ||
doc [open] generate docs for all crates in the workspace | ||
install install hipcheck | ||
bench [build] run time benchmarks to get duration on events | ||
validate analyze workspace for expected configuration", | ||
env!("CARGO_PKG_NAME"), | ||
raw_version, | ||
env!("CARGO_PKG_DESCRIPTION"), | ||
env!("CARGO_BIN_NAME") | ||
); | ||
/// Hipcheck development task runner. | ||
#[derive(Debug, clap::Parser)] | ||
#[clap(about, version)] | ||
struct Args { | ||
#[clap(flatten)] | ||
verbose: clap_verbosity_flag::Verbosity, | ||
|
||
println!("{}", help_text); | ||
exit(EXIT_FAILURE); | ||
#[clap(subcommand)] | ||
command: Commands, | ||
} | ||
|
||
fn print_version() -> ! { | ||
let version_text = crate_version!(); | ||
println!("{}", version_text); | ||
exit(EXIT_SUCCESS); | ||
#[derive(Debug, clap::Subcommand)] | ||
enum Commands { | ||
/// Run a variety of quality checks. | ||
Validate, | ||
/// Simulate a CI run locally. | ||
Ci, | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.