Skip to content

Commit 546212c

Browse files
committed
Auto merge of #3614 - matklad:simpler-cli-2, r=alexcrichton
Remove generic infrastrucure for printing json Only a couple of command really use this features, so it's clearer just to print json right on the spot rather then return it though the call stack. `CliResult` is now just a `Result<(), CliError>`.
2 parents 1aa510d + 0c7e73c commit 546212c

34 files changed

+100
-128
lines changed

src/bin/bench.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ not affect how many jobs are used when running the benchmarks.
7070
Compilation can be customized with the `bench` profile in the manifest.
7171
";
7272

73-
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
73+
pub fn execute(options: Options, config: &Config) -> CliResult {
7474
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
7575
config.configure(options.flag_verbose,
7676
options.flag_quiet,
@@ -105,7 +105,7 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
105105
let ws = Workspace::new(&root, config)?;
106106
let err = ops::run_benches(&ws, &ops, &options.arg_args)?;
107107
match err {
108-
None => Ok(None),
108+
None => Ok(()),
109109
Some(err) => {
110110
Err(match err.exit.as_ref().and_then(|e| e.code()) {
111111
Some(i) => CliError::new(human("bench failed"), i),

src/bin/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ the manifest. The default profile for this command is `dev`, but passing
7171
the --release flag will use the `release` profile instead.
7272
";
7373

74-
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
74+
pub fn execute(options: Options, config: &Config) -> CliResult {
7575
debug!("executing; cmd=cargo-build; args={:?}",
7676
env::args().collect::<Vec<_>>());
7777
config.configure(options.flag_verbose,
@@ -110,5 +110,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
110110

111111
let ws = Workspace::new(&root, config)?;
112112
ops::compile(&ws, &opts)?;
113-
Ok(None)
113+
Ok(())
114114
}

src/bin/cargo.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ fn main() {
8989

9090
match result {
9191
Err(e) => cargo::handle_cli_error(e, &mut *config.shell()),
92-
Ok(None) => {},
93-
Ok(Some(())) => unreachable!(),
92+
Ok(()) => {},
9493
}
9594
}
9695

@@ -139,7 +138,7 @@ each_subcommand!(declare_mod);
139138
because they are fundamental (and intertwined). Other commands can rely
140139
on this top-level information.
141140
*/
142-
fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
141+
fn execute(flags: Flags, config: &Config) -> CliResult {
143142
config.configure(flags.flag_verbose,
144143
flags.flag_quiet,
145144
&flags.flag_color,
@@ -162,21 +161,21 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
162161
}
163162
}
164163
}
165-
return Ok(None)
164+
return Ok(())
166165
}
167166

168167
if flags.flag_list {
169168
println!("Installed Commands:");
170169
for command in list_commands(config) {
171170
println!(" {}", command);
172171
};
173-
return Ok(None)
172+
return Ok(())
174173
}
175174

176175
if let Some(ref code) = flags.flag_explain {
177176
let mut procss = config.rustc()?.process();
178177
procss.arg("--explain").arg(code).exec().map_err(human)?;
179-
return Ok(None)
178+
return Ok(())
180179
}
181180

182181
let args = match &flags.arg_command[..] {
@@ -189,7 +188,7 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
189188
let r = cargo::call_main_without_stdin(execute, config, USAGE, args,
190189
false);
191190
cargo::process_executed(r, &mut config.shell());
192-
return Ok(None)
191+
return Ok(())
193192
}
194193

195194
// For `cargo help -h` and `cargo help --help`, print out the help
@@ -221,7 +220,7 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
221220
};
222221

223222
if try_execute(&config, &args) {
224-
return Ok(None)
223+
return Ok(())
225224
}
226225

227226
let alias_list = aliased_command(&config, &args[1])?;
@@ -233,15 +232,15 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
233232
.map(|s| s.to_string())
234233
.collect::<Vec<_>>();
235234
if try_execute(&config, &chain) {
236-
return Ok(None)
235+
return Ok(())
237236
} else {
238237
chain
239238
}
240239
}
241240
None => args,
242241
};
243242
execute_subcommand(config, &args[1], &args)?;
244-
Ok(None)
243+
Ok(())
245244
}
246245

247246
fn try_execute(config: &Config, args: &[String]) -> bool {
@@ -298,7 +297,7 @@ fn find_closest(config: &Config, cmd: &str) -> Option<String> {
298297

299298
fn execute_subcommand(config: &Config,
300299
cmd: &str,
301-
args: &[String]) -> CliResult<()> {
300+
args: &[String]) -> CliResult {
302301
let command_exe = format!("cargo-{}{}", cmd, env::consts::EXE_SUFFIX);
303302
let path = search_directories(config)
304303
.iter()

src/bin/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub struct Options {
6666
flag_frozen: bool,
6767
}
6868

69-
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
69+
pub fn execute(options: Options, config: &Config) -> CliResult {
7070
debug!("executing; cmd=cargo-check; args={:?}",
7171
env::args().collect::<Vec<_>>());
7272

@@ -100,5 +100,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
100100
};
101101

102102
ops::compile(&ws, &opts)?;
103-
Ok(None)
103+
Ok(())
104104
}

src/bin/clean.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ given, then all packages' artifacts are removed. For more information on SPEC
4242
and its format, see the `cargo help pkgid` command.
4343
";
4444

45-
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
45+
pub fn execute(options: Options, config: &Config) -> CliResult {
4646
debug!("executing; cmd=cargo-clean; args={:?}", env::args().collect::<Vec<_>>());
4747
config.configure(options.flag_verbose,
4848
options.flag_quiet,
@@ -59,5 +59,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
5959
};
6060
let ws = Workspace::new(&root, config)?;
6161
ops::clean(&ws, &opts)?;
62-
Ok(None)
62+
Ok(())
6363
}

src/bin/doc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ current package is documented. For more information on SPEC and its format, see
6666
the `cargo help pkgid` command.
6767
";
6868

69-
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
69+
pub fn execute(options: Options, config: &Config) -> CliResult {
7070
config.configure(options.flag_verbose,
7171
options.flag_quiet,
7272
&options.flag_color,
@@ -109,5 +109,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
109109

110110
let ws = Workspace::new(&root, config)?;
111111
ops::doc(&ws, &doc_opts)?;
112-
Ok(None)
112+
Ok(())
113113
}

src/bin/fetch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ If the lockfile is not available, then this is the equivalent of
3838
all updated.
3939
";
4040

41-
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
41+
pub fn execute(options: Options, config: &Config) -> CliResult {
4242
config.configure(options.flag_verbose,
4343
options.flag_quiet,
4444
&options.flag_color,
@@ -47,6 +47,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
4747
let root = find_root_manifest_for_wd(options.flag_manifest_path, config.cwd())?;
4848
let ws = Workspace::new(&root, config)?;
4949
ops::fetch(&ws)?;
50-
Ok(None)
50+
Ok(())
5151
}
5252

src/bin/generate_lockfile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Options:
3131
--locked Require Cargo.lock is up to date
3232
";
3333

34-
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
34+
pub fn execute(options: Options, config: &Config) -> CliResult {
3535
debug!("executing; cmd=cargo-generate-lockfile; args={:?}", env::args().collect::<Vec<_>>());
3636
config.configure(options.flag_verbose,
3737
options.flag_quiet,
@@ -42,5 +42,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
4242

4343
let ws = Workspace::new(&root, config)?;
4444
ops::generate_lockfile(&ws)?;
45-
Ok(None)
45+
Ok(())
4646
}

src/bin/git_checkout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Options:
2929
--locked Require Cargo.lock is up to date
3030
";
3131

32-
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
32+
pub fn execute(options: Options, config: &Config) -> CliResult {
3333
config.configure(options.flag_verbose,
3434
options.flag_quiet,
3535
&options.flag_color,
@@ -46,5 +46,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
4646

4747
source.update()?;
4848

49-
Ok(None)
49+
Ok(())
5050
}

src/bin/help.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Options:
1414
-h, --help Print this message
1515
";
1616

17-
pub fn execute(_: Options, _: &Config) -> CliResult<Option<()>> {
17+
pub fn execute(_: Options, _: &Config) -> CliResult {
1818
// This is a dummy command just so that `cargo help help` works.
1919
// The actual delegation of help flag to subcommands is handled by the
2020
// cargo command.

src/bin/init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Options:
3939
--locked Require Cargo.lock is up to date
4040
";
4141

42-
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
42+
pub fn execute(options: Options, config: &Config) -> CliResult {
4343
debug!("executing; cmd=cargo-init; args={:?}", env::args().collect::<Vec<_>>());
4444
config.configure(options.flag_verbose,
4545
options.flag_quiet,
@@ -63,6 +63,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
6363
if opts_lib { "library" }
6464
else {"binary (application)"}))?;
6565

66-
Ok(None)
66+
Ok(())
6767
}
6868

src/bin/install.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ the more explicit `install --path .`.
9494
The `--list` option will list all installed packages (and their versions).
9595
";
9696

97-
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
97+
pub fn execute(options: Options, config: &Config) -> CliResult {
9898
config.configure(options.flag_verbose,
9999
options.flag_quiet,
100100
&options.flag_color,
@@ -147,5 +147,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
147147
} else {
148148
ops::install(root, krate, &source, vers, &compile_opts, options.flag_force)?;
149149
}
150-
Ok(None)
150+
Ok(())
151151
}

src/bin/locate_project.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use cargo;
12
use cargo::util::{CliResult, CliError, human, ChainError, Config};
23
use cargo::util::important_paths::{find_root_manifest_for_wd};
34

@@ -23,7 +24,7 @@ pub struct ProjectLocation {
2324
}
2425

2526
pub fn execute(flags: LocateProjectFlags,
26-
config: &Config) -> CliResult<Option<ProjectLocation>> {
27+
config: &Config) -> CliResult {
2728
let root = find_root_manifest_for_wd(flags.flag_manifest_path, config.cwd())?;
2829

2930
let string = root.to_str()
@@ -32,5 +33,7 @@ pub fn execute(flags: LocateProjectFlags,
3233
Unicode"))
3334
.map_err(|e| CliError::new(e, 1))?;
3435

35-
Ok(Some(ProjectLocation { root: string.to_string() }))
36+
let location = ProjectLocation { root: string.to_string() };
37+
cargo::print_json(&location);
38+
Ok(())
3639
}

src/bin/login.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Options:
3434
3535
";
3636

37-
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
37+
pub fn execute(options: Options, config: &Config) -> CliResult {
3838
config.configure(options.flag_verbose,
3939
options.flag_quiet,
4040
&options.flag_color,
@@ -60,6 +60,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
6060

6161
let token = token.trim().to_string();
6262
ops::registry_login(config, token)?;
63-
Ok(None)
63+
Ok(())
6464
}
6565

src/bin/metadata.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
use cargo;
12
use cargo::core::Workspace;
2-
use cargo::ops::{output_metadata, OutputMetadataOptions, ExportInfo};
3+
use cargo::ops::{output_metadata, OutputMetadataOptions};
34
use cargo::util::important_paths::find_root_manifest_for_wd;
45
use cargo::util::{CliResult, Config};
56

@@ -42,7 +43,7 @@ Options:
4243
--locked Require Cargo.lock is up to date
4344
";
4445

45-
pub fn execute(options: Options, config: &Config) -> CliResult<Option<ExportInfo>> {
46+
pub fn execute(options: Options, config: &Config) -> CliResult {
4647
config.configure(options.flag_verbose,
4748
options.flag_quiet,
4849
&options.flag_color,
@@ -60,5 +61,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<ExportInfo
6061

6162
let ws = Workspace::new(&manifest, config)?;
6263
let result = output_metadata(&ws, &options)?;
63-
Ok(Some(result))
64+
cargo::print_json(&result);
65+
Ok(())
6466
}

src/bin/new.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Options:
3939
--locked Require Cargo.lock is up to date
4040
";
4141

42-
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
42+
pub fn execute(options: Options, config: &Config) -> CliResult {
4343
debug!("executing; cmd=cargo-new; args={:?}", env::args().collect::<Vec<_>>());
4444
config.configure(options.flag_verbose,
4545
options.flag_quiet,
@@ -63,6 +63,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
6363
else {"binary (application)"},
6464
arg_path))?;
6565

66-
Ok(None)
66+
Ok(())
6767
}
6868

src/bin/owner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ See http://doc.crates.io/crates-io.html#cargo-owner for detailed documentation
4444
and troubleshooting.
4545
";
4646

47-
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
47+
pub fn execute(options: Options, config: &Config) -> CliResult {
4848
config.configure(options.flag_verbose,
4949
options.flag_quiet,
5050
&options.flag_color,
@@ -59,6 +59,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
5959
list: options.flag_list,
6060
};
6161
ops::modify_owners(config, &opts)?;
62-
Ok(None)
62+
Ok(())
6363
}
6464

src/bin/package.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Options:
3939
--locked Require Cargo.lock is up to date
4040
";
4141

42-
pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
42+
pub fn execute(options: Options, config: &Config) -> CliResult {
4343
config.configure(options.flag_verbose,
4444
options.flag_quiet,
4545
&options.flag_color,
@@ -55,5 +55,5 @@ pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> {
5555
allow_dirty: options.flag_allow_dirty,
5656
jobs: options.flag_jobs,
5757
})?;
58-
Ok(None)
58+
Ok(())
5959
}

src/bin/pkgid.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Example Package IDs
5353
";
5454

5555
pub fn execute(options: Options,
56-
config: &Config) -> CliResult<Option<()>> {
56+
config: &Config) -> CliResult {
5757
config.configure(options.flag_verbose,
5858
options.flag_quiet,
5959
&options.flag_color,
@@ -72,6 +72,6 @@ pub fn execute(options: Options,
7272
let spec = spec.as_ref().map(|s| &s[..]);
7373
let spec = ops::pkgid(&ws, spec)?;
7474
println!("{}", spec);
75-
Ok(None)
75+
Ok(())
7676
}
7777

0 commit comments

Comments
 (0)