Skip to content

Commit 7dcb602

Browse files
committed
refactor(new): Group name and kind initialization
1 parent 68302bb commit 7dcb602

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/cargo/ops/cargo_new.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ fn calculate_new_project_kind(
439439

440440
pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<()> {
441441
let path = &opts.path;
442+
let name = get_name(path, opts)?;
442443

443444
if path.exists() {
444445
anyhow::bail!(
@@ -451,7 +452,6 @@ pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<()> {
451452

452453
let is_bin = opts.kind.is_bin();
453454

454-
let name = get_name(path, opts)?;
455455
check_name(name, opts.name.is_none(), is_bin, &mut config.shell())?;
456456

457457
let mkopts = MkOptions {
@@ -480,18 +480,16 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<NewProjectKind> {
480480
}
481481

482482
let path = &opts.path;
483+
let name = get_name(path, opts)?;
484+
let mut src_paths_types = vec![];
485+
detect_source_paths_and_types(path, name, &mut src_paths_types)?;
486+
let kind = calculate_new_project_kind(opts.kind, opts.auto_detect_kind, &src_paths_types);
483487

484488
if path.join("Cargo.toml").exists() {
485489
anyhow::bail!("`cargo init` cannot be run on existing Cargo packages")
486490
}
487491
check_path(path, &mut config.shell())?;
488492

489-
let name = get_name(path, opts)?;
490-
491-
let mut src_paths_types = vec![];
492-
detect_source_paths_and_types(path, name, &mut src_paths_types)?;
493-
494-
let kind = calculate_new_project_kind(opts.kind, opts.auto_detect_kind, &src_paths_types);
495493
let has_bin = kind.is_bin();
496494

497495
if src_paths_types.is_empty() {

0 commit comments

Comments
 (0)