Skip to content

Commit 61504c8

Browse files
committed
Auto merge of rust-lang#13366 - matklad:xflags, r=lnicola
internal: ⬆️ xflags The main change here should be that flags are not inhereted, so $ rust-analyzer analysis-stats . -v -v would do what it should do We also no longer Don\'t
2 parents 8437e4b + 39fa8b5 commit 61504c8

File tree

7 files changed

+32
-48
lines changed

7 files changed

+32
-48
lines changed

Cargo.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rust-analyzer/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ itertools = "0.10.3"
2525
scip = "0.1.1"
2626
lsp-types = { version = "0.93.1", features = ["proposed"] }
2727
parking_lot = "0.12.1"
28-
xflags = "0.2.4"
28+
xflags = "0.3.0"
2929
oorandom = "11.1.3"
3030
rustc-hash = "1.1.0"
3131
serde = { version = "1.0.137", features = ["derive"] }

crates/rust-analyzer/src/bin/main.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,15 @@ fn main() {
3737
process::exit(code);
3838
}
3939

40-
if let Err(err) = try_main() {
40+
let flags = flags::RustAnalyzer::from_env_or_exit();
41+
if let Err(err) = try_main(flags) {
4142
tracing::error!("Unexpected error: {}", err);
4243
eprintln!("{}", err);
4344
process::exit(101);
4445
}
4546
}
4647

47-
fn try_main() -> Result<()> {
48-
let flags = flags::RustAnalyzer::from_env()?;
49-
48+
fn try_main(flags: flags::RustAnalyzer) -> Result<()> {
5049
#[cfg(debug_assertions)]
5150
if flags.wait_dbg || env::var("RA_WAIT_DBG").is_ok() {
5251
#[allow(unused_mut)]
@@ -76,10 +75,6 @@ fn try_main() -> Result<()> {
7675
println!("rust-analyzer {}", rust_analyzer::version());
7776
return Ok(());
7877
}
79-
if cmd.help {
80-
println!("{}", flags::RustAnalyzer::HELP);
81-
return Ok(());
82-
}
8378
with_extra_thread("LspServer", run_server)?;
8479
}
8580
flags::RustAnalyzerCmd::ProcMacro(flags::ProcMacro) => {

crates/rust-analyzer/src/cli/flags.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ xflags::xflags! {
3131
default cmd lsp-server {
3232
/// Print version.
3333
optional --version
34-
/// Print help.
35-
optional -h, --help
3634

3735
/// Dump a LSP config JSON schema.
3836
optional --print-config-schema
@@ -54,10 +52,10 @@ xflags::xflags! {
5452
}
5553

5654
/// Batch typecheck project and print summary statistics
57-
cmd analysis-stats
55+
cmd analysis-stats {
5856
/// Directory with Cargo.toml.
5957
required path: PathBuf
60-
{
58+
6159
optional --output format: OutputFormat
6260

6361
/// Randomize order in which crates, modules, and items are processed.
@@ -84,38 +82,37 @@ xflags::xflags! {
8482
optional --skip-inference
8583
}
8684

87-
cmd diagnostics
85+
cmd diagnostics {
8886
/// Directory with Cargo.toml.
8987
required path: PathBuf
90-
{
88+
9189
/// Don't run build scripts or load `OUT_DIR` values by running `cargo check` before analysis.
9290
optional --disable-build-scripts
9391
/// Don't use expand proc macros.
9492
optional --disable-proc-macros
9593
}
9694

97-
cmd ssr
95+
cmd ssr {
9896
/// A structured search replace rule (`$a.foo($b) ==> bar($a, $b)`)
9997
repeated rule: SsrRule
100-
{}
98+
}
10199

102-
cmd search
100+
cmd search {
103101
/// A structured search replace pattern (`$a.foo($b)`)
104102
repeated pattern: SsrPattern
105-
{
106103
/// Prints debug information for any nodes with source exactly equal to snippet.
107104
optional --debug snippet: String
108105
}
109106

110107
cmd proc-macro {}
111108

112-
cmd lsif
109+
cmd lsif {
113110
required path: PathBuf
114-
{}
111+
}
115112

116-
cmd scip
113+
cmd scip {
117114
required path: PathBuf
118-
{}
115+
}
119116
}
120117
}
121118

@@ -150,7 +147,6 @@ pub enum RustAnalyzerCmd {
150147
#[derive(Debug)]
151148
pub struct LspServer {
152149
pub version: bool,
153-
pub help: bool,
154150
pub print_config_schema: bool,
155151
}
156152

@@ -218,7 +214,10 @@ pub struct Scip {
218214
}
219215

220216
impl RustAnalyzer {
221-
pub const HELP: &'static str = Self::HELP_;
217+
#[allow(dead_code)]
218+
pub fn from_env_or_exit() -> Self {
219+
Self::from_env_or_exit_()
220+
}
222221

223222
#[allow(dead_code)]
224223
pub fn from_env() -> xflags::Result<Self> {

xtask/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ anyhow = "1.0.57"
1111
flate2 = "1.0.24"
1212
write-json = "0.1.2"
1313
xshell = "0.2.2"
14-
xflags = "0.2.4"
14+
xflags = "0.3.0"
1515
# Avoid adding more dependencies to this crate

xtask/src/flags.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ xflags::xflags! {
77

88
/// Run custom build command.
99
cmd xtask {
10-
default cmd help {
11-
/// Print help information.
12-
optional -h, --help
13-
}
1410

1511
/// Install rust-analyzer server or editor plugin.
1612
cmd install {
@@ -42,9 +38,9 @@ xflags::xflags! {
4238
optional --dry-run
4339
}
4440
/// Builds a benchmark version of rust-analyzer and puts it into `./target`.
45-
cmd bb
41+
cmd bb {
4642
required suffix: String
47-
{}
43+
}
4844
}
4945
}
5046

@@ -58,7 +54,6 @@ pub struct Xtask {
5854

5955
#[derive(Debug)]
6056
pub enum XtaskCmd {
61-
Help(Help),
6257
Install(Install),
6358
FuzzTests(FuzzTests),
6459
Release(Release),
@@ -68,11 +63,6 @@ pub enum XtaskCmd {
6863
Bb(Bb),
6964
}
7065

71-
#[derive(Debug)]
72-
pub struct Help {
73-
pub help: bool,
74-
}
75-
7666
#[derive(Debug)]
7767
pub struct Install {
7868
pub client: bool,
@@ -111,7 +101,10 @@ pub struct Bb {
111101
}
112102

113103
impl Xtask {
114-
pub const HELP: &'static str = Self::HELP_;
104+
#[allow(dead_code)]
105+
pub fn from_env_or_exit() -> Self {
106+
Self::from_env_or_exit_()
107+
}
115108

116109
#[allow(dead_code)]
117110
pub fn from_env() -> xflags::Result<Self> {

xtask/src/main.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,12 @@ use std::{
2525
use xshell::{cmd, Shell};
2626

2727
fn main() -> anyhow::Result<()> {
28+
let flags = flags::Xtask::from_env_or_exit();
29+
2830
let sh = &Shell::new()?;
2931
sh.change_dir(project_root());
3032

31-
let flags = flags::Xtask::from_env()?;
3233
match flags.subcommand {
33-
flags::XtaskCmd::Help(_) => {
34-
println!("{}", flags::Xtask::HELP);
35-
Ok(())
36-
}
3734
flags::XtaskCmd::Install(cmd) => cmd.run(sh),
3835
flags::XtaskCmd::FuzzTests(_) => run_fuzzer(sh),
3936
flags::XtaskCmd::Release(cmd) => cmd.run(sh),

0 commit comments

Comments
 (0)