@@ -51,6 +51,7 @@ impl<'de> de::Deserialize<'de> for VersionControl {
51
51
pub struct NewOptions {
52
52
pub version_control : Option < VersionControl > ,
53
53
pub kind : NewProjectKind ,
54
+ pub auto_detect_kind : bool ,
54
55
/// Absolute path to the directory for the new package
55
56
pub path : PathBuf ,
56
57
pub name : Option < String > ,
@@ -62,25 +63,19 @@ pub struct NewOptions {
62
63
pub enum NewProjectKind {
63
64
Bin ,
64
65
Lib ,
65
- Auto ,
66
66
}
67
67
68
68
impl NewProjectKind {
69
69
fn is_bin ( self ) -> bool {
70
70
self == NewProjectKind :: Bin
71
71
}
72
-
73
- fn is_auto ( self ) -> bool {
74
- self == NewProjectKind :: Auto
75
- }
76
72
}
77
73
78
74
impl fmt:: Display for NewProjectKind {
79
75
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
80
76
match * self {
81
77
NewProjectKind :: Bin => "binary (application)" ,
82
78
NewProjectKind :: Lib => "library" ,
83
- NewProjectKind :: Auto => "auto-select type" ,
84
79
}
85
80
. fmt ( f)
86
81
}
@@ -112,16 +107,18 @@ impl NewOptions {
112
107
edition : Option < String > ,
113
108
registry : Option < String > ,
114
109
) -> CargoResult < NewOptions > {
110
+ let auto_detect_kind = !bin && !lib;
111
+
115
112
let kind = match ( bin, lib) {
116
113
( true , true ) => anyhow:: bail!( "can't specify both lib and binary outputs" ) ,
117
114
( false , true ) => NewProjectKind :: Lib ,
118
- ( true , false ) => NewProjectKind :: Bin ,
119
- ( false , false ) => NewProjectKind :: Auto ,
115
+ ( _, false ) => NewProjectKind :: Bin ,
120
116
} ;
121
117
122
118
let opts = NewOptions {
123
119
version_control,
124
120
kind,
121
+ auto_detect_kind,
125
122
path,
126
123
name,
127
124
edition,
@@ -397,6 +394,7 @@ fn plan_new_source_file(bin: bool, package_name: String) -> SourceFileInformatio
397
394
398
395
fn calculate_new_project_kind (
399
396
requested_kind : NewProjectKind ,
397
+ auto_detect_kind : bool ,
400
398
found_files : & Vec < SourceFileInformation > ,
401
399
) -> NewProjectKind {
402
400
let bin_file = found_files. iter ( ) . find ( |x| x. bin ) ;
@@ -407,14 +405,14 @@ fn calculate_new_project_kind(
407
405
NewProjectKind :: Bin
408
406
} ;
409
407
410
- if requested_kind . is_auto ( ) {
408
+ if auto_detect_kind {
411
409
return kind_from_files;
412
410
}
413
411
414
412
requested_kind
415
413
}
416
414
417
- pub fn new ( opts : & NewOptions , config : & Config ) -> CargoResult < NewProjectKind > {
415
+ pub fn new ( opts : & NewOptions , config : & Config ) -> CargoResult < ( ) > {
418
416
let path = & opts. path ;
419
417
if path. exists ( ) {
420
418
anyhow:: bail!(
@@ -424,12 +422,7 @@ pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<NewProjectKind> {
424
422
)
425
423
}
426
424
427
- let kind = match opts. kind {
428
- NewProjectKind :: Bin => NewProjectKind :: Bin ,
429
- NewProjectKind :: Auto => NewProjectKind :: Bin ,
430
- _ => NewProjectKind :: Lib ,
431
- } ;
432
- let is_bin = kind. is_bin ( ) ;
425
+ let is_bin = opts. kind . is_bin ( ) ;
433
426
434
427
let name = get_name ( path, opts) ?;
435
428
check_name ( name, opts. name . is_none ( ) , is_bin, & mut config. shell ( ) ) ?;
@@ -451,7 +444,7 @@ pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<NewProjectKind> {
451
444
path. display( )
452
445
)
453
446
} ) ?;
454
- Ok ( kind )
447
+ Ok ( ( ) )
455
448
}
456
449
457
450
pub fn init ( opts : & NewOptions , config : & Config ) -> CargoResult < NewProjectKind > {
@@ -472,7 +465,7 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<NewProjectKind> {
472
465
473
466
detect_source_paths_and_types ( path, name, & mut src_paths_types) ?;
474
467
475
- let kind = calculate_new_project_kind ( opts. kind , & src_paths_types) ;
468
+ let kind = calculate_new_project_kind ( opts. kind , opts . auto_detect_kind , & src_paths_types) ;
476
469
let has_bin = kind. is_bin ( ) ;
477
470
478
471
if src_paths_types. is_empty ( ) {
0 commit comments