Skip to content

Commit 82a7972

Browse files
committed
In cargo new, reuse calculated name rather than recalculate
1 parent a866976 commit 82a7972

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

src/bin/cargo/commands/new.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ pub fn cli() -> App {
1212
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
1313
let opts = args.new_options(config)?;
1414

15-
ops::new(&opts, config)?;
16-
let path = args.value_of("path").unwrap();
17-
let package_name = if let Some(name) = args.value_of("name") {
18-
name
19-
} else {
20-
path
21-
};
15+
let package_name = ops::new(&opts, config)?;
2216
config.shell().status(
2317
"Created",
2418
format!("{} `{}` package", opts.kind, package_name),

src/cargo/ops/cargo_new.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ fn plan_new_source_file(bin: bool, package_name: String) -> SourceFileInformatio
299299
}
300300
}
301301

302-
pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<()> {
302+
pub fn new<'a>(opts: &'a NewOptions, config: &Config) -> CargoResult<&'a str> {
303303
let path = &opts.path;
304304
if fs::metadata(path).is_ok() {
305305
failure::bail!(
@@ -329,7 +329,7 @@ pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<()> {
329329
path.display()
330330
)
331331
})?;
332-
Ok(())
332+
Ok(name)
333333
}
334334

335335
pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<()> {

0 commit comments

Comments
 (0)