Skip to content

Commit 10a57b8

Browse files
bors[bot]matklad
andauthored
Merge #7835
7835: Use cli parser with auto-generated help r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
2 parents a6ee8e9 + d8f7f2d commit 10a57b8

File tree

8 files changed

+195
-134
lines changed

8 files changed

+195
-134
lines changed

Cargo.lock

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xtask/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ license = "MIT OR Apache-2.0"
99
[dependencies]
1010
anyhow = "1.0.26"
1111
flate2 = "1.0"
12-
pico-args = "0.4.0"
1312
proc-macro2 = "1.0.8"
1413
quote = "1.0.2"
1514
ungrammar = "=1.11"
1615
walkdir = "2.3.1"
1716
write-json = "0.1.0"
1817
xshell = "0.1"
18+
xflags = "0.1.2"
1919
# Avoid adding more dependencies to this crate

xtask/src/codegen.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::{
1818
};
1919
use xshell::{cmd, pushenv, read_file, write_file};
2020

21-
use crate::{ensure_rustfmt, project_root, Result};
21+
use crate::{ensure_rustfmt, flags, project_root, Result};
2222

2323
pub(crate) use self::{
2424
gen_assists_docs::{generate_assists_docs, generate_assists_tests},
@@ -35,11 +35,7 @@ pub(crate) enum Mode {
3535
Verify,
3636
}
3737

38-
pub(crate) struct CodegenCmd {
39-
pub(crate) features: bool,
40-
}
41-
42-
impl CodegenCmd {
38+
impl flags::Codegen {
4339
pub(crate) fn run(self) -> Result<()> {
4440
if self.features {
4541
generate_lint_completions(Mode::Overwrite)?;

xtask/src/flags.rs

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#![allow(unreachable_pub)]
2+
3+
xflags::args_parser! {
4+
/// Run custom build command.
5+
cmd xtask {
6+
default cmd help {
7+
/// Print help information.
8+
optional -h, --help
9+
}
10+
11+
/// Install rust-analyzer server or editor plugin.
12+
cmd install {
13+
/// Install only VS Code plugin.
14+
optional --client
15+
/// One of 'code', 'code-exploration', 'code-insiders', 'codium', or 'code-oss'.
16+
optional --code-bin name: String
17+
18+
/// Install only the language server.
19+
optional --server
20+
/// Use mimalloc allocator for server
21+
optional --mimalloc
22+
/// Use jemalloc allocator for server
23+
optional --jemalloc
24+
}
25+
26+
cmd codegen {
27+
optional --features
28+
}
29+
30+
cmd lint {}
31+
cmd fuzz-tests {}
32+
cmd pre-cache {}
33+
34+
cmd release {
35+
optional --dry-run
36+
}
37+
cmd promote {
38+
optional --dry-run
39+
}
40+
cmd dist {
41+
optional --nightly
42+
optional --client version: String
43+
}
44+
cmd metrics {
45+
optional --dry-run
46+
}
47+
/// Builds a benchmark version of rust-analyzer and puts it into `./target`.
48+
cmd bb
49+
required suffix: String
50+
{}
51+
}
52+
}
53+
54+
// generated start
55+
// The following code is generated by `xflags` macro.
56+
// Run `env XFLAGS_DUMP= cargo build` to regenerate.
57+
#[derive(Debug)]
58+
pub struct Xtask {
59+
pub subcommand: XtaskCmd,
60+
}
61+
62+
#[derive(Debug)]
63+
pub enum XtaskCmd {
64+
Help(Help),
65+
Install(Install),
66+
Codegen(Codegen),
67+
Lint(Lint),
68+
FuzzTests(FuzzTests),
69+
PreCache(PreCache),
70+
Release(Release),
71+
Promote(Promote),
72+
Dist(Dist),
73+
Metrics(Metrics),
74+
Bb(Bb),
75+
}
76+
77+
#[derive(Debug)]
78+
pub struct Help {
79+
pub help: bool,
80+
}
81+
82+
#[derive(Debug)]
83+
pub struct Install {
84+
pub client: bool,
85+
pub code_bin: Option<String>,
86+
pub server: bool,
87+
pub mimalloc: bool,
88+
pub jemalloc: bool,
89+
}
90+
91+
#[derive(Debug)]
92+
pub struct Codegen {
93+
pub features: bool,
94+
}
95+
96+
#[derive(Debug)]
97+
pub struct Lint {}
98+
99+
#[derive(Debug)]
100+
pub struct FuzzTests {}
101+
102+
#[derive(Debug)]
103+
pub struct PreCache {}
104+
105+
#[derive(Debug)]
106+
pub struct Release {
107+
pub dry_run: bool,
108+
}
109+
110+
#[derive(Debug)]
111+
pub struct Promote {
112+
pub dry_run: bool,
113+
}
114+
115+
#[derive(Debug)]
116+
pub struct Dist {
117+
pub nightly: bool,
118+
pub client: Option<String>,
119+
}
120+
121+
#[derive(Debug)]
122+
pub struct Metrics {
123+
pub dry_run: bool,
124+
}
125+
126+
#[derive(Debug)]
127+
pub struct Bb {
128+
pub suffix: String,
129+
}
130+
131+
impl Xtask {
132+
pub const HELP: &'static str = Self::_HELP;
133+
134+
pub fn from_env() -> xflags::Result<Self> {
135+
let mut p = xflags::rt::Parser::new_from_env();
136+
Self::_parse(&mut p)
137+
}
138+
}
139+
// generated end

0 commit comments

Comments
 (0)