@@ -12,11 +12,11 @@ use url_builder::URLBuilder;
1212
1313use crate :: input:: {
1414 clone_setup, config_all, config_editor, config_host, config_owner, create_workspace,
15- fork_setup, overwrite, select_repo,
15+ fork_setup, overwrite, select , select_repo,
1616} ;
1717use devmode:: fork:: ForkAction ;
1818use devmode:: host:: Host ;
19- use devmode:: project:: { find_paths , OpenAction } ;
19+ use devmode:: project:: { matching_paths_for , OpenAction } ;
2020use devmode:: settings:: Settings ;
2121use devmode:: { clone:: CloneAction , constants:: patterns:: GIT_URL } ;
2222
@@ -93,8 +93,6 @@ pub enum Commands {
9393 arg_required_else_help = true
9494 ) ]
9595 Config {
96- #[ clap( help = "Map your project paths." , short = 'm' , long = "map" ) ]
97- map : bool ,
9896 #[ clap( help = "Show the current configuration." , short = 's' , long = "show" ) ]
9997 show : bool ,
10098 #[ clap( help = "Configure your settings." , short = 'a' , long = "all" ) ]
@@ -141,6 +139,8 @@ pub enum Commands {
141139 remove : Option < String > ,
142140 #[ clap( help = "List all workspaces" , short = 'l' , long = "list" ) ]
143141 list : bool ,
142+ #[ clap( help = "Show information about a workspace" , long = "info" ) ]
143+ info : bool ,
144144 } ,
145145}
146146
@@ -153,20 +153,18 @@ impl Cli {
153153 Commands :: Update { project } => Cli :: update ( project) ,
154154 Commands :: Fork { args, upstream } => Cli :: fork ( args, upstream, rx) ,
155155 Commands :: Config {
156- map,
157156 show,
158157 all,
159158 editor,
160159 owner,
161160 host,
162161 } => Cli :: config ( Config {
163- map : * map,
164162 show : * show,
165163 all : * all,
166164 editor : * editor,
167165 owner : * owner,
168166 host : * host,
169- none : !map && ! show && !all && !editor && !owner && !host,
167+ none : !show && !all && !editor && !owner && !host,
170168 } ) ,
171169 Commands :: Workspace {
172170 name,
@@ -176,6 +174,7 @@ impl Cli {
176174 include,
177175 remove,
178176 list,
177+ info,
179178 } => Cli :: workspace ( WorkspaceOptions {
180179 name : name. to_owned ( ) ,
181180 add : * add,
@@ -184,6 +183,7 @@ impl Cli {
184183 include : include. to_owned ( ) ,
185184 remove : remove. to_owned ( ) ,
186185 list : * list,
186+ info : * info,
187187 } ) ,
188188 }
189189 }
@@ -253,11 +253,11 @@ impl Cli {
253253 }
254254
255255 fn open ( project : & str ) -> Result < ( ) , Error > {
256- let paths = find_paths ( project) ?;
256+ let paths = matching_paths_for ( project) ?;
257257 if paths. is_empty ( ) {
258258 Err ( Error :: Devmode ( DevmodeError :: NoProjectFound ) )
259259 } else if paths. len ( ) > 1 {
260- let path = select_repo ( project , None ) ?;
260+ let path = select_repo ( paths ) ?;
261261 OpenAction :: new ( project) . open ( path)
262262 } else {
263263 OpenAction :: new ( project) . open (
@@ -270,11 +270,11 @@ impl Cli {
270270 }
271271
272272 fn update ( project : & str ) -> Result < ( ) , Error > {
273- let paths = find_paths ( project) ?;
273+ let paths = matching_paths_for ( project) ?;
274274 if paths. is_empty ( ) {
275275 Err ( Error :: Devmode ( DevmodeError :: NoProjectFound ) )
276276 } else if paths. len ( ) > 1 {
277- let path = select_repo ( project , None ) ?;
277+ let path = select_repo ( paths ) ?;
278278 OpenAction :: new ( project) . update ( path)
279279 } else {
280280 OpenAction :: new ( project) . update (
@@ -323,9 +323,6 @@ impl Cli {
323323 let settings = config_all ( ) ?;
324324 settings. write ( false ) ?;
325325 }
326- if config. map {
327- OpenAction :: make_dev_paths ( ) ?
328- }
329326 if config. editor {
330327 let settings = config_editor ( ) ?;
331328 settings. write ( false ) ?
@@ -349,56 +346,90 @@ impl Cli {
349346 let mut settings =
350347 Settings :: current ( ) . ok_or ( Error :: Devmode ( DevmodeError :: AppSettingsNotFound ) ) ?;
351348 let Some ( ref workspace_name) = arguments. name else {
352- let workspaces = settings. workspaces . names ;
353- println ! ( "Currently available workspaces: {workspaces:?}" ) ;
354- return Ok ( ( ) ) ;
349+ return if arguments. list {
350+ let workspaces = settings. workspaces . names ;
351+ println ! ( "Currently available workspaces:" ) ;
352+ for workspace in workspaces {
353+ println ! ( "- {}" , workspace) ;
354+ }
355+ Ok ( ( ) )
356+ } else {
357+ Err ( Error :: Devmode ( DevmodeError :: WorkspaceRequired ) )
358+ } ;
355359 } ;
356- let mut workspace = Workspace :: new ( & workspace_name) ;
357- if settings. workspaces . names . contains ( workspace_name) {
360+ if arguments. add {
361+ if settings. workspaces . names . contains ( workspace_name) {
362+ return Err ( Error :: Devmode ( DevmodeError :: WorkspaceExists (
363+ workspace_name. clone ( ) ,
364+ ) ) ) ;
365+ }
366+ let create = create_workspace ( ) ?;
367+ if create {
368+ settings. workspaces . names . push ( workspace_name. clone ( ) ) ;
369+ settings. write ( true ) ?;
370+ println ! ( "Workspace {workspace_name} was added." )
371+ }
372+ } else if settings. workspaces . names . contains ( workspace_name) {
373+ let mut workspace = Workspace :: new ( & workspace_name) ;
358374 if arguments. delete {
359375 workspace. delete ( ) ?;
360376 println ! ( "Workspace {workspace_name} was successfully deleted." ) ;
361377 } else if let Some ( ref to) = arguments. rename {
362378 workspace. rename ( to) ?;
363379 println ! ( "Workspace renamed from {workspace_name} to {to}." ) ;
364- } else if let Some ( ref project ) = arguments. include {
365- let paths: Vec < PathBuf > = find_paths ( project ) ?
380+ } else if let Some ( ref project_name ) = arguments. include {
381+ let paths: Vec < PathBuf > = matching_paths_for ( project_name ) ?
366382 . iter ( )
383+ . cloned ( )
367384 . filter ( |path| !path. display ( ) . to_string ( ) . contains ( workspace_name) )
368- . map ( PathBuf :: from)
369385 . collect ( ) ;
370- let project = if paths. len ( ) > 0 {
371- select_repo ( project, Some ( workspace_name) ) ?
386+
387+ let project = if paths. len ( ) == 0 {
388+ return Err ( Error :: Devmode ( DevmodeError :: ProjectNotFound ) ) ;
389+ } else if paths. len ( ) > 1 {
390+ let paths: Vec < String > =
391+ paths. iter ( ) . map ( |s| s. display ( ) . to_string ( ) ) . collect ( ) ;
392+ PathBuf :: from ( select (
393+ "repo" ,
394+ "Select the repository you want to open:" ,
395+ paths,
396+ ) ?)
372397 } else {
373- paths
374- . get ( 0 )
375- . ok_or ( Error :: Devmode ( DevmodeError :: ProjectNotFound ) ) ?
376- . clone ( )
398+ paths[ 0 ] . clone ( )
377399 } ;
378400 let mut options = CopyOptions :: new ( ) ;
379401 let destination = project
380402 . parent ( )
381403 . ok_or ( Error :: Devmode ( DevmodeError :: PathNotFound ) ) ?
382404 . join ( & workspace_name) ;
383405
384- if destination. exists ( ) {
406+ if destination. join ( project_name ) . exists ( ) {
385407 options. overwrite = overwrite ( ) ?;
386408 }
387409
410+ if !destination. exists ( ) {
411+ std:: fs:: create_dir_all ( & destination) ?;
412+ }
413+
388414 move_items ( & [ project] , destination, & options) ?;
389415 } else if let Some ( ref project_name) = arguments. remove {
390- let paths: Vec < PathBuf > = find_paths ( project_name) ?
416+ let paths: Vec < PathBuf > = matching_paths_for ( project_name) ?
391417 . iter ( )
392- . filter ( |path| !path . display ( ) . to_string ( ) . contains ( workspace_name ) )
393- . map ( PathBuf :: from )
418+ . cloned ( )
419+ . filter ( |path| path . display ( ) . to_string ( ) . contains ( workspace_name ) )
394420 . collect ( ) ;
395- let project = if paths. len ( ) > 0 {
396- select_repo ( project_name, Some ( workspace_name) ) ?
421+ let project = if paths. len ( ) == 0 {
422+ return Err ( Error :: Devmode ( DevmodeError :: ProjectNotFound ) ) ;
423+ } else if paths. len ( ) > 1 {
424+ let paths: Vec < String > =
425+ paths. iter ( ) . map ( |s| s. display ( ) . to_string ( ) ) . collect ( ) ;
426+ PathBuf :: from ( select (
427+ "repo" ,
428+ "Select the repository you want to open:" ,
429+ paths,
430+ ) ?)
397431 } else {
398- paths
399- . get ( 0 )
400- . ok_or ( Error :: Devmode ( DevmodeError :: ProjectNotFound ) ) ?
401- . clone ( )
432+ paths[ 0 ] . clone ( )
402433 } ;
403434 let mut options = dir:: CopyOptions :: new ( ) ;
404435 let to = project
@@ -407,27 +438,16 @@ impl Cli {
407438 . parent ( )
408439 . ok_or ( Error :: Devmode ( DevmodeError :: PathNotFound ) ) ?;
409440
410- if to. join ( & project ) . exists ( ) {
441+ if to. join ( project_name ) . exists ( ) {
411442 options. overwrite = overwrite ( ) ?;
412443 }
413444
414445 move_items ( & [ project. clone ( ) ] , to, & options) ?;
446+ } else if arguments. info {
447+ workspace. info ( ) ?;
415448 } else {
416449 println ! ( "Workspace `{workspace_name}` found." ) ;
417450 }
418- } else if arguments. delete || arguments. rename . is_some ( ) {
419- return devmode:: error ( "Couldn't find a workspace that matches {name}." ) ;
420- } else if arguments. add {
421- settings. workspaces . names . push ( workspace_name. clone ( ) ) ;
422- settings. write ( true ) ?;
423- println ! ( "Workspace {workspace_name} was added." )
424- } else {
425- let create = create_workspace ( ) ?;
426- if create {
427- settings. workspaces . names . push ( workspace_name. clone ( ) ) ;
428- settings. write ( true ) ?;
429- println ! ( "Workspace {workspace_name} was added." )
430- }
431451 }
432452 Ok ( ( ) )
433453 }
0 commit comments