@@ -11,7 +11,7 @@ pub mod args;
1111pub  mod  commands; 
1212
1313pub  use  args:: GlobalArgs ; 
14- pub  use  commands:: Commands ; 
14+ pub  use  commands:: { Commands ,   CreateAction } ; 
1515
1616/// Command-line interface for Torrust Tracker Deployer 
1717/// 
@@ -168,40 +168,57 @@ mod tests {
168168    } 
169169
170170    #[ test]  
171-     fn  it_should_parse_create_subcommand ( )  { 
171+     fn  it_should_parse_create_environment_subcommand ( )  { 
172172        let  args = vec ! [ 
173173            "torrust-tracker-deployer" , 
174174            "create" , 
175+             "environment" , 
175176            "--env-file" , 
176177            "config.json" , 
177178        ] ; 
178179        let  cli = Cli :: try_parse_from ( args) . unwrap ( ) ; 
179180
180181        assert ! ( cli. command. is_some( ) ) ; 
181182        match  cli. command . unwrap ( )  { 
182-             Commands :: Create  {  env_file }  => { 
183-                 assert_eq ! ( env_file,  std:: path:: PathBuf :: from( "config.json" ) ) ; 
184-             } 
183+             Commands :: Create  {  action }  => match  action { 
184+                 crate :: presentation:: cli:: CreateAction :: Environment  {  env_file }  => { 
185+                     assert_eq ! ( env_file,  std:: path:: PathBuf :: from( "config.json" ) ) ; 
186+                 } 
187+                 crate :: presentation:: cli:: CreateAction :: Template  {  .. }  => { 
188+                     panic ! ( "Expected Environment action" ) 
189+                 } 
190+             } , 
185191            Commands :: Destroy  {  .. }  => panic ! ( "Expected Create command" ) , 
186192        } 
187193    } 
188194
189195    #[ test]  
190-     fn  it_should_parse_create_with_short_flag ( )  { 
191-         let  args = vec ! [ "torrust-tracker-deployer" ,  "create" ,  "-f" ,  "env.json" ] ; 
196+     fn  it_should_parse_create_environment_with_short_flag ( )  { 
197+         let  args = vec ! [ 
198+             "torrust-tracker-deployer" , 
199+             "create" , 
200+             "environment" , 
201+             "-f" , 
202+             "env.json" , 
203+         ] ; 
192204        let  cli = Cli :: try_parse_from ( args) . unwrap ( ) ; 
193205
194206        match  cli. command . unwrap ( )  { 
195-             Commands :: Create  {  env_file }  => { 
196-                 assert_eq ! ( env_file,  std:: path:: PathBuf :: from( "env.json" ) ) ; 
197-             } 
207+             Commands :: Create  {  action }  => match  action { 
208+                 crate :: presentation:: cli:: CreateAction :: Environment  {  env_file }  => { 
209+                     assert_eq ! ( env_file,  std:: path:: PathBuf :: from( "env.json" ) ) ; 
210+                 } 
211+                 crate :: presentation:: cli:: CreateAction :: Template  {  .. }  => { 
212+                     panic ! ( "Expected Environment action" ) 
213+                 } 
214+             } , 
198215            Commands :: Destroy  {  .. }  => panic ! ( "Expected Create command" ) , 
199216        } 
200217    } 
201218
202219    #[ test]  
203-     fn  it_should_require_env_file_parameter_for_create ( )  { 
204-         let  args = vec ! [ "torrust-tracker-deployer" ,  "create" ] ; 
220+     fn  it_should_require_env_file_parameter_for_create_environment ( )  { 
221+         let  args = vec ! [ "torrust-tracker-deployer" ,  "create" ,   "environment" ] ; 
205222        let  result = Cli :: try_parse_from ( args) ; 
206223
207224        assert ! ( result. is_err( ) ) ; 
@@ -214,12 +231,13 @@ mod tests {
214231    } 
215232
216233    #[ test]  
217-     fn  it_should_parse_working_dir_global_option ( )  { 
234+     fn  it_should_parse_working_dir_global_option_with_create_environment ( )  { 
218235        let  args = vec ! [ 
219236            "torrust-tracker-deployer" , 
220237            "--working-dir" , 
221238            "/tmp/workspace" , 
222239            "create" , 
240+             "environment" , 
223241            "--env-file" , 
224242            "config.json" , 
225243        ] ; 
@@ -231,16 +249,27 @@ mod tests {
231249        ) ; 
232250
233251        match  cli. command . unwrap ( )  { 
234-             Commands :: Create  {  env_file }  => { 
235-                 assert_eq ! ( env_file,  std:: path:: PathBuf :: from( "config.json" ) ) ; 
236-             } 
252+             Commands :: Create  {  action }  => match  action { 
253+                 crate :: presentation:: cli:: CreateAction :: Environment  {  env_file }  => { 
254+                     assert_eq ! ( env_file,  std:: path:: PathBuf :: from( "config.json" ) ) ; 
255+                 } 
256+                 crate :: presentation:: cli:: CreateAction :: Template  {  .. }  => { 
257+                     panic ! ( "Expected Environment action" ) 
258+                 } 
259+             } , 
237260            Commands :: Destroy  {  .. }  => panic ! ( "Expected Create command" ) , 
238261        } 
239262    } 
240263
241264    #[ test]  
242265    fn  it_should_use_default_working_dir_when_not_specified ( )  { 
243-         let  args = vec ! [ "torrust-tracker-deployer" ,  "create" ,  "-f" ,  "config.json" ] ; 
266+         let  args = vec ! [ 
267+             "torrust-tracker-deployer" , 
268+             "create" , 
269+             "environment" , 
270+             "-f" , 
271+             "config.json" , 
272+         ] ; 
244273        let  cli = Cli :: try_parse_from ( args) . unwrap ( ) ; 
245274
246275        assert_eq ! ( cli. global. working_dir,  std:: path:: PathBuf :: from( "." ) ) ; 
@@ -255,10 +284,91 @@ mod tests {
255284        let  error = result. unwrap_err ( ) ; 
256285        assert_eq ! ( error. kind( ) ,  clap:: error:: ErrorKind :: DisplayHelp ) ; 
257286
287+         let  help_text = error. to_string ( ) ; 
288+         assert ! ( 
289+             help_text. contains( "environment" )  || help_text. contains( "template" ) , 
290+             "Help text should mention subcommands: {help_text}" 
291+         ) ; 
292+     } 
293+ 
294+     #[ test]  
295+     fn  it_should_parse_create_template_without_path ( )  { 
296+         let  args = vec ! [ "torrust-tracker-deployer" ,  "create" ,  "template" ] ; 
297+         let  cli = Cli :: try_parse_from ( args) . unwrap ( ) ; 
298+ 
299+         match  cli. command . unwrap ( )  { 
300+             Commands :: Create  {  action }  => match  action { 
301+                 crate :: presentation:: cli:: CreateAction :: Template  {  output_path }  => { 
302+                     assert ! ( output_path. is_none( ) ) ; 
303+                 } 
304+                 crate :: presentation:: cli:: CreateAction :: Environment  {  .. }  => { 
305+                     panic ! ( "Expected Template action" ) 
306+                 } 
307+             } , 
308+             Commands :: Destroy  {  .. }  => panic ! ( "Expected Create command" ) , 
309+         } 
310+     } 
311+ 
312+     #[ test]  
313+     fn  it_should_parse_create_template_with_custom_path ( )  { 
314+         let  args = vec ! [ 
315+             "torrust-tracker-deployer" , 
316+             "create" , 
317+             "template" , 
318+             "./config/my-env.json" , 
319+         ] ; 
320+         let  cli = Cli :: try_parse_from ( args) . unwrap ( ) ; 
321+ 
322+         match  cli. command . unwrap ( )  { 
323+             Commands :: Create  {  action }  => match  action { 
324+                 crate :: presentation:: cli:: CreateAction :: Template  {  output_path }  => { 
325+                     assert_eq ! ( 
326+                         output_path, 
327+                         Some ( std:: path:: PathBuf :: from( "./config/my-env.json" ) ) 
328+                     ) ; 
329+                 } 
330+                 crate :: presentation:: cli:: CreateAction :: Environment  {  .. }  => { 
331+                     panic ! ( "Expected Template action" ) 
332+                 } 
333+             } , 
334+             Commands :: Destroy  {  .. }  => panic ! ( "Expected Create command" ) , 
335+         } 
336+     } 
337+ 
338+     #[ test]  
339+     fn  it_should_show_create_environment_help ( )  { 
340+         let  args = vec ! [ 
341+             "torrust-tracker-deployer" , 
342+             "create" , 
343+             "environment" , 
344+             "--help" , 
345+         ] ; 
346+         let  result = Cli :: try_parse_from ( args) ; 
347+ 
348+         assert ! ( result. is_err( ) ) ; 
349+         let  error = result. unwrap_err ( ) ; 
350+         assert_eq ! ( error. kind( ) ,  clap:: error:: ErrorKind :: DisplayHelp ) ; 
351+ 
258352        let  help_text = error. to_string ( ) ; 
259353        assert ! ( 
260354            help_text. contains( "env-file" )  || help_text. contains( "configuration" ) , 
261355            "Help text should mention env-file parameter" 
262356        ) ; 
263357    } 
358+ 
359+     #[ test]  
360+     fn  it_should_show_create_template_help ( )  { 
361+         let  args = vec ! [ "torrust-tracker-deployer" ,  "create" ,  "template" ,  "--help" ] ; 
362+         let  result = Cli :: try_parse_from ( args) ; 
363+ 
364+         assert ! ( result. is_err( ) ) ; 
365+         let  error = result. unwrap_err ( ) ; 
366+         assert_eq ! ( error. kind( ) ,  clap:: error:: ErrorKind :: DisplayHelp ) ; 
367+ 
368+         let  help_text = error. to_string ( ) ; 
369+         assert ! ( 
370+             help_text. contains( "template" )  || help_text. contains( "placeholder" ) , 
371+             "Help text should mention template generation" 
372+         ) ; 
373+     } 
264374} 
0 commit comments