@@ -10,7 +10,7 @@ use structopt::{
1010use url:: Url ;
1111
1212use crate :: {
13- config:: { GistRepository , GitHubRepository , GitProtocol , GitReference , RawPlugin } ,
13+ config:: { GistRepository , GitHubRepository , GitProtocol , GitReference , RawPlugin , Shell } ,
1414 context:: Settings ,
1515 edit:: Plugin ,
1616 log:: { Output , Verbosity } ,
@@ -93,6 +93,14 @@ struct Add {
9393
9494#[ derive( Debug , PartialEq , StructOpt ) ]
9595enum RawCommand {
96+ /// Initialize a new config file.
97+ #[ structopt( help_message = HELP_MESSAGE ) ]
98+ Init {
99+ /// The type of shell, accepted values are: bash, zsh.
100+ #[ structopt( long, value_name = "SHELL" ) ]
101+ shell : Option < Shell > ,
102+ } ,
103+
96104 /// Add a new plugin to the config file.
97105 #[ structopt( help_message = HELP_MESSAGE ) ]
98106 Add ( Box < Add > ) ,
@@ -182,6 +190,8 @@ struct RawOpt {
182190/// The resolved command.
183191#[ derive( Debug ) ]
184192pub enum Command {
193+ /// Initialize a new config file.
194+ Init { shell : Option < Shell > } ,
185195 /// Add a new plugin to the config file.
186196 Add { name : String , plugin : Box < Plugin > } ,
187197 /// Open up the config file in the default editor.
@@ -310,6 +320,7 @@ impl Opt {
310320 } ;
311321
312322 let command = match command {
323+ RawCommand :: Init { shell } => Command :: Init { shell } ,
313324 RawCommand :: Add ( add) => {
314325 let ( name, plugin) = Plugin :: from_add ( * add) ;
315326 Command :: Add {
@@ -413,6 +424,7 @@ OPTIONS:
413424 SHELDON_DOWNLOAD_DIR=]
414425
415426SUBCOMMANDS:
427+ init Initialize a new config file
416428 add Add a new plugin to the config file
417429 edit Open up the config file in the default editor
418430 remove Remove a plugin from the config file
@@ -507,6 +519,42 @@ For more information try --help",
507519 assert_eq ! ( err. info, None ) ;
508520 }
509521
522+ #[ test]
523+ fn raw_opt_init_help ( ) {
524+ setup ( ) ;
525+ let err = raw_opt_err ( & [ "init" , "--help" ] ) ;
526+ assert_eq ! (
527+ err. message,
528+ format!(
529+ "\
530+ {name}-init {version}
531+ Initialize a new config file
532+
533+ USAGE:
534+ sheldon init [OPTIONS]
535+
536+ FLAGS:
537+ -h, --help Show this message and exit
538+
539+ OPTIONS:
540+ --shell <SHELL> The type of shell, accepted values are: bash, zsh" ,
541+ name = crate_name!( ) ,
542+ version = crate_version!( )
543+ )
544+ ) ;
545+ assert_eq ! ( err. kind, structopt:: clap:: ErrorKind :: HelpDisplayed ) ;
546+ assert_eq ! ( err. info, None ) ;
547+ }
548+
549+ #[ test]
550+ fn raw_opt_init_with_invalid_shell ( ) {
551+ setup ( ) ;
552+ assert_eq ! (
553+ raw_opt_err( & [ "init" , "--shell" , "ksh" , ] ) . kind,
554+ structopt:: clap:: ErrorKind :: ValueValidation
555+ ) ;
556+ }
557+
510558 #[ test]
511559 fn raw_opt_add_help ( ) {
512560 setup ( ) ;
0 commit comments