@@ -51,6 +51,7 @@ impl<'de> de::Deserialize<'de> for VersionControl {
5151pub struct NewOptions {
5252 pub version_control : Option < VersionControl > ,
5353 pub kind : NewProjectKind ,
54+ pub auto_detect_kind : bool ,
5455 /// Absolute path to the directory for the new package
5556 pub path : PathBuf ,
5657 pub name : Option < String > ,
@@ -62,25 +63,19 @@ pub struct NewOptions {
6263pub enum NewProjectKind {
6364 Bin ,
6465 Lib ,
65- Auto ,
6666}
6767
6868impl NewProjectKind {
6969 fn is_bin ( self ) -> bool {
7070 self == NewProjectKind :: Bin
7171 }
72-
73- fn is_auto ( self ) -> bool {
74- self == NewProjectKind :: Auto
75- }
7672}
7773
7874impl fmt:: Display for NewProjectKind {
7975 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
8076 match * self {
8177 NewProjectKind :: Bin => "binary (application)" ,
8278 NewProjectKind :: Lib => "library" ,
83- NewProjectKind :: Auto => "auto-select type" ,
8479 }
8580 . fmt ( f)
8681 }
@@ -112,16 +107,18 @@ impl NewOptions {
112107 edition : Option < String > ,
113108 registry : Option < String > ,
114109 ) -> CargoResult < NewOptions > {
110+ let auto_detect_kind = !bin && !lib;
111+
115112 let kind = match ( bin, lib) {
116113 ( true , true ) => anyhow:: bail!( "can't specify both lib and binary outputs" ) ,
117114 ( false , true ) => NewProjectKind :: Lib ,
118- ( true , false ) => NewProjectKind :: Bin ,
119- ( false , false ) => NewProjectKind :: Auto ,
115+ ( _, false ) => NewProjectKind :: Bin ,
120116 } ;
121117
122118 let opts = NewOptions {
123119 version_control,
124120 kind,
121+ auto_detect_kind,
125122 path,
126123 name,
127124 edition,
@@ -397,6 +394,7 @@ fn plan_new_source_file(bin: bool, package_name: String) -> SourceFileInformatio
397394
398395fn calculate_new_project_kind (
399396 requested_kind : NewProjectKind ,
397+ auto_detect_kind : bool ,
400398 found_files : & Vec < SourceFileInformation > ,
401399) -> NewProjectKind {
402400 let bin_file = found_files. iter ( ) . find ( |x| x. bin ) ;
@@ -407,14 +405,14 @@ fn calculate_new_project_kind(
407405 NewProjectKind :: Bin
408406 } ;
409407
410- if requested_kind . is_auto ( ) {
408+ if auto_detect_kind {
411409 return kind_from_files;
412410 }
413411
414412 requested_kind
415413}
416414
417- pub fn new ( opts : & NewOptions , config : & Config ) -> CargoResult < NewProjectKind > {
415+ pub fn new ( opts : & NewOptions , config : & Config ) -> CargoResult < ( ) > {
418416 let path = & opts. path ;
419417 if path. exists ( ) {
420418 anyhow:: bail!(
@@ -424,12 +422,7 @@ pub fn new(opts: &NewOptions, config: &Config) -> CargoResult<NewProjectKind> {
424422 )
425423 }
426424
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 ( ) ;
433426
434427 let name = get_name ( path, opts) ?;
435428 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> {
451444 path. display( )
452445 )
453446 } ) ?;
454- Ok ( kind )
447+ Ok ( ( ) )
455448}
456449
457450pub fn init ( opts : & NewOptions , config : & Config ) -> CargoResult < NewProjectKind > {
@@ -472,7 +465,7 @@ pub fn init(opts: &NewOptions, config: &Config) -> CargoResult<NewProjectKind> {
472465
473466 detect_source_paths_and_types ( path, name, & mut src_paths_types) ?;
474467
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) ;
476469 let has_bin = kind. is_bin ( ) ;
477470
478471 if src_paths_types. is_empty ( ) {
0 commit comments