aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_tools/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_tools/src')
-rw-r--r--crates/ra_tools/src/help.rs27
-rw-r--r--crates/ra_tools/src/main.rs64
2 files changed, 37 insertions, 54 deletions
diff --git a/crates/ra_tools/src/help.rs b/crates/ra_tools/src/help.rs
index 5bfe65734..6dde6c2d2 100644
--- a/crates/ra_tools/src/help.rs
+++ b/crates/ra_tools/src/help.rs
@@ -1,6 +1,4 @@
1pub fn print_global_help() { 1pub const GLOBAL_HELP: &str = "tasks
2 println!(
3 "tasks
4 2
5USAGE: 3USAGE:
6 ra_tools <SUBCOMMAND> 4 ra_tools <SUBCOMMAND>
@@ -15,13 +13,9 @@ SUBCOMMANDS:
15 gen-syntax 13 gen-syntax
16 gen-tests 14 gen-tests
17 install-ra 15 install-ra
18 lint" 16 lint";
19 )
20}
21 17
22pub fn print_install_ra_help() { 18pub const INSTALL_RA_HELP: &str = "ra_tools-install-ra
23 println!(
24 "ra_tools-install-ra
25 19
26USAGE: 20USAGE:
27 ra_tools.exe install-ra [FLAGS] 21 ra_tools.exe install-ra [FLAGS]
@@ -30,12 +24,10 @@ FLAGS:
30 --client-code 24 --client-code
31 -h, --help Prints help information 25 -h, --help Prints help information
32 --jemalloc 26 --jemalloc
33 --server" 27 --server";
34 )
35}
36 28
37pub fn print_no_param_subcommand_help(subcommand: &str) { 29pub fn print_no_param_subcommand_help(subcommand: &str) {
38 println!( 30 eprintln!(
39 "ra_tools-{} 31 "ra_tools-{}
40 32
41USAGE: 33USAGE:
@@ -47,10 +39,7 @@ FLAGS:
47 ); 39 );
48} 40}
49 41
50pub fn print_install_ra_conflict() { 42pub const INSTALL_RA_CONFLICT: &str =
51 println!( 43 "error: The argument `--server` cannot be used with `--client-code`
52 "error: The argument `--server` cannot be used with `--client-code`
53 44
54For more information try --help" 45For more information try --help";
55 )
56}
diff --git a/crates/ra_tools/src/main.rs b/crates/ra_tools/src/main.rs
index 5410edea9..f96f1875f 100644
--- a/crates/ra_tools/src/main.rs
+++ b/crates/ra_tools/src/main.rs
@@ -23,84 +23,78 @@ struct ServerOpt {
23} 23}
24 24
25fn main() -> Result<()> { 25fn main() -> Result<()> {
26 let subcommand = std::env::args_os().nth(1); 26 let subcommand = match std::env::args_os().nth(1) {
27 if subcommand.is_none() { 27 None => {
28 help::print_global_help(); 28 eprintln!("{}", help::GLOBAL_HELP);
29 return Ok(()); 29 return Ok(());
30 } 30 }
31 let subcommand = subcommand.unwrap(); 31 Some(s) => s,
32 };
32 let mut matches = Arguments::from_vec(std::env::args_os().skip(2).collect()); 33 let mut matches = Arguments::from_vec(std::env::args_os().skip(2).collect());
33 let subcommand = &*subcommand.to_string_lossy(); 34 let subcommand = &*subcommand.to_string_lossy();
34 match subcommand { 35 match subcommand {
35 "install-ra" | "install-code" => { 36 "install-ra" | "install-code" => {
36 if matches.contains(["-h", "--help"]) { 37 if matches.contains(["-h", "--help"]) {
37 help::print_install_ra_help(); 38 eprintln!("{}", help::INSTALL_RA_HELP);
39 return Ok(());
40 }
41 let server = matches.contains("--server");
42 let client_code = matches.contains("--client-code");
43 if server && client_code {
44 eprintln!("{}", help::INSTALL_RA_CONFLICT);
38 return Ok(()); 45 return Ok(());
39 } else {
40 let server = matches.contains("--server");
41 let client_code = matches.contains("--client-code");
42 if server && client_code {
43 help::print_install_ra_conflict();
44 return Ok(());
45 }
46 let jemalloc = matches.contains("--jemalloc");
47 matches.finish().or_else(handle_extra_flags)?;
48 let opts = InstallOpt {
49 client: if server { None } else { Some(ClientOpt::VsCode) },
50 server: if client_code { None } else { Some(ServerOpt { jemalloc: jemalloc }) },
51 };
52 install(opts)?
53 } 46 }
47 let jemalloc = matches.contains("--jemalloc");
48 matches.finish().or_else(handle_extra_flags)?;
49 let opts = InstallOpt {
50 client: if server { None } else { Some(ClientOpt::VsCode) },
51 server: if client_code { None } else { Some(ServerOpt { jemalloc: jemalloc }) },
52 };
53 install(opts)?
54 } 54 }
55 "gen-tests" => { 55 "gen-tests" => {
56 if matches.contains(["-h", "--help"]) { 56 if matches.contains(["-h", "--help"]) {
57 help::print_no_param_subcommand_help(&subcommand); 57 help::print_no_param_subcommand_help(&subcommand);
58 return Ok(()); 58 return Ok(());
59 } else {
60 gen_tests(Overwrite)?
61 } 59 }
60 gen_tests(Overwrite)?
62 } 61 }
63 "gen-syntax" => { 62 "gen-syntax" => {
64 if matches.contains(["-h", "--help"]) { 63 if matches.contains(["-h", "--help"]) {
65 help::print_no_param_subcommand_help(&subcommand); 64 help::print_no_param_subcommand_help(&subcommand);
66 return Ok(()); 65 return Ok(());
67 } else {
68 generate_boilerplate(Overwrite)?
69 } 66 }
67 generate_boilerplate(Overwrite)?
70 } 68 }
71 "format" => { 69 "format" => {
72 if matches.contains(["-h", "--help"]) { 70 if matches.contains(["-h", "--help"]) {
73 help::print_no_param_subcommand_help(&subcommand); 71 help::print_no_param_subcommand_help(&subcommand);
74 return Ok(()); 72 return Ok(());
75 } else {
76 run_rustfmt(Overwrite)?
77 } 73 }
74 run_rustfmt(Overwrite)?
78 } 75 }
79 "format-hook" => { 76 "format-hook" => {
80 if matches.contains(["-h", "--help"]) { 77 if matches.contains(["-h", "--help"]) {
81 help::print_no_param_subcommand_help(&subcommand); 78 help::print_no_param_subcommand_help(&subcommand);
82 return Ok(()); 79 return Ok(());
83 } else {
84 install_format_hook()?
85 } 80 }
81 install_format_hook()?
86 } 82 }
87 "lint" => { 83 "lint" => {
88 if matches.contains(["-h", "--help"]) { 84 if matches.contains(["-h", "--help"]) {
89 help::print_no_param_subcommand_help(&subcommand); 85 help::print_no_param_subcommand_help(&subcommand);
90 return Ok(()); 86 return Ok(());
91 } else {
92 run_clippy()?
93 } 87 }
88 run_clippy()?
94 } 89 }
95 "fuzz-tests" => { 90 "fuzz-tests" => {
96 if matches.contains(["-h", "--help"]) { 91 if matches.contains(["-h", "--help"]) {
97 help::print_no_param_subcommand_help(&subcommand); 92 help::print_no_param_subcommand_help(&subcommand);
98 return Ok(()); 93 return Ok(());
99 } else {
100 run_fuzzer()?
101 } 94 }
95 run_fuzzer()?
102 } 96 }
103 _ => help::print_global_help(), 97 _ => eprintln!("{}", help::GLOBAL_HELP),
104 } 98 }
105 Ok(()) 99 Ok(())
106} 100}
@@ -109,7 +103,7 @@ fn handle_extra_flags(e: pico_args::Error) -> Result<()> {
109 if let pico_args::Error::UnusedArgsLeft(flags) = e { 103 if let pico_args::Error::UnusedArgsLeft(flags) = e {
110 let mut invalid_flags = String::new(); 104 let mut invalid_flags = String::new();
111 for flag in flags { 105 for flag in flags {
112 write!(&mut invalid_flags, "{}, ", flag).expect("Error on write"); 106 write!(&mut invalid_flags, "{}, ", flag)?;
113 } 107 }
114 let (invalid_flags, _) = invalid_flags.split_at(invalid_flags.len() - 2); 108 let (invalid_flags, _) = invalid_flags.split_at(invalid_flags.len() - 2);
115 Err(format!("Invalid flags: {}", invalid_flags).into()) 109 Err(format!("Invalid flags: {}", invalid_flags).into())