From 4ce20b80c5ca5e0523980aa8dd95b1cc76d78d59 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 1 Mar 2021 21:12:44 +0300 Subject: Use cli parser with auto-generated help --- xtask/src/flags.rs | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 xtask/src/flags.rs (limited to 'xtask/src/flags.rs') diff --git a/xtask/src/flags.rs b/xtask/src/flags.rs new file mode 100644 index 000000000..ce72879a1 --- /dev/null +++ b/xtask/src/flags.rs @@ -0,0 +1,139 @@ +#![allow(unreachable_pub)] + +xflags::args_parser! { + /// Run custom build command. + cmd xtask { + default cmd help { + /// Print help information. + optional -h, --help + } + + /// Install rust-analyzer server or editor plugin. + cmd install { + /// Install only VS Code plugin. + optional --client + /// One of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss'. + optional --code-bin name: String + + /// Install only the language server. + optional --server + /// Use mimalloc allocator for server + optional --mimalloc + /// Use jemalloc allocator for server + optional --jemalloc + } + + cmd codegen { + optional --features + } + + cmd lint {} + cmd fuzz-tests {} + cmd pre-cache {} + + cmd release { + optional --dry-run + } + cmd promote { + optional --dry-run + } + cmd dist { + optional --nightly + optional --client version: String + } + cmd metrics { + optional --dry-run + } + /// Builds a benchmark version of rust-analyzer and puts it into `./target`. + cmd bb + required suffix : String + {} + } +} + +// generated start +// The following code is generated by `xflags` macro. +// Run `env XFLAGS_DUMP= cargo build` to regenerate. +#[derive(Debug)] +pub struct Xtask { + pub subcommand: XtaskCmd, +} + +#[derive(Debug)] +pub enum XtaskCmd { + Help(Help), + Install(Install), + Codegen(Codegen), + Lint(Lint), + FuzzTests(FuzzTests), + PreCache(PreCache), + Release(Release), + Promote(Promote), + Dist(Dist), + Metrics(Metrics), + Bb(Bb), +} + +#[derive(Debug)] +pub struct Help { + pub help: bool, +} + +#[derive(Debug)] +pub struct Install { + pub client: bool, + pub code_bin: Option, + pub server: bool, + pub mimalloc: bool, + pub jemalloc: bool, +} + +#[derive(Debug)] +pub struct Codegen { + pub features: bool, +} + +#[derive(Debug)] +pub struct Lint {} + +#[derive(Debug)] +pub struct FuzzTests {} + +#[derive(Debug)] +pub struct PreCache {} + +#[derive(Debug)] +pub struct Release { + pub dry_run: bool, +} + +#[derive(Debug)] +pub struct Promote { + pub dry_run: bool, +} + +#[derive(Debug)] +pub struct Dist { + pub nightly: bool, + pub client: Option, +} + +#[derive(Debug)] +pub struct Metrics { + pub dry_run: bool, +} + +#[derive(Debug)] +pub struct Bb { + pub suffix: String, +} + +impl Xtask { + pub const HELP: &'static str = Self::_HELP; + + pub fn from_env() -> xflags::Result { + let mut p = xflags::rt::Parser::new_from_env(); + Self::_parse(&mut p) + } +} +// generated end -- cgit v1.2.3