@@ -64,23 +64,26 @@ Examples:
6464var wsRemoveRemote bool
6565
6666var workspaceRemoveCmd = & cobra.Command {
67- Use : "remove < name> " ,
67+ Use : "remove [ name|path] " ,
6868 Aliases : []string {"rm" },
6969 Short : "Remove a workspace from tracking" ,
7070 Long : `Remove a workspace from the local index or from the server.
7171
7272By default removes from the local index:
73+ - With no argument or ".", removes the workspace tracked in the current directory.
7374 - For global workspaces, the stored files are also deleted.
7475 - For local workspaces, only the tracking entry is removed; project files are untouched.
7576 - A bare name refers to a global workspace; use a path (with a slash) for a local workspace.
7677
7778With --remote, deletes the workspace from the configured server.
7879
7980Examples:
81+ nebi workspace remove # remove workspace in current directory
82+ nebi workspace remove . # same as above
8083 nebi workspace remove data-science # remove global workspace by name
8184 nebi workspace remove ./my-project # remove local workspace by path
8285 nebi workspace remove myenv --remote # delete workspace from server` ,
83- Args : cobra .ExactArgs (1 ),
86+ Args : cobra .MaximumNArgs (1 ),
8487 RunE : runWorkspaceRemove ,
8588}
8689
@@ -137,7 +140,7 @@ func runWorkspaceListLocal() error {
137140 var missing int
138141 for _ , ws := range wss {
139142 wsType := "local"
140- if ws . IsGlobal {
143+ if s . IsGlobalWorkspace ( & ws ) {
141144 wsType = "global"
142145 }
143146 path := ws .Path
@@ -290,9 +293,8 @@ func runWorkspacePromote(cmd *cobra.Command, args []string) error {
290293 }
291294
292295 ws := & store.LocalWorkspace {
293- Name : name ,
294- Path : wsDir ,
295- IsGlobal : true ,
296+ Name : name ,
297+ Path : wsDir ,
296298 }
297299 if err := s .CreateWorkspace (ws ); err != nil {
298300 return fmt .Errorf ("saving workspace: %w" , err )
@@ -303,10 +305,17 @@ func runWorkspacePromote(cmd *cobra.Command, args []string) error {
303305}
304306
305307func runWorkspaceRemove (cmd * cobra.Command , args []string ) error {
308+ arg := ""
309+ if len (args ) > 0 {
310+ arg = args [0 ]
311+ }
306312 if wsRemoveRemote {
307- return runWorkspaceRemoveServer (args [0 ])
313+ if arg == "" || arg == "." {
314+ return fmt .Errorf ("--remote requires a workspace name" )
315+ }
316+ return runWorkspaceRemoveServer (arg )
308317 }
309- return runWorkspaceRemoveLocal (args [ 0 ] )
318+ return runWorkspaceRemoveLocal (arg )
310319}
311320
312321func runWorkspaceRemoveServer (name string ) error {
@@ -338,7 +347,20 @@ func runWorkspaceRemoveLocal(arg string) error {
338347 defer s .Close ()
339348
340349 var ws * store.LocalWorkspace
341- if strings .Contains (arg , "/" ) || strings .Contains (arg , string (filepath .Separator )) {
350+ if arg == "" || arg == "." {
351+ // No argument or "." — remove workspace in current directory
352+ cwd , err := os .Getwd ()
353+ if err != nil {
354+ return fmt .Errorf ("getting current directory: %w" , err )
355+ }
356+ ws , err = s .FindWorkspaceByPath (cwd )
357+ if err != nil {
358+ return err
359+ }
360+ if ws == nil {
361+ return fmt .Errorf ("no tracked workspace in current directory; run 'nebi workspace list' to see available workspaces" )
362+ }
363+ } else if strings .Contains (arg , "/" ) || strings .Contains (arg , string (filepath .Separator )) {
342364 absPath , err := filepath .Abs (arg )
343365 if err != nil {
344366 return fmt .Errorf ("resolving path: %w" , err )
@@ -360,21 +382,28 @@ func runWorkspaceRemoveLocal(arg string) error {
360382 }
361383 }
362384
385+ isGlobal := s .IsGlobalWorkspace (ws )
386+
363387 // Delete directory for global workspaces
364- if ws . IsGlobal {
388+ if isGlobal {
365389 if err := os .RemoveAll (ws .Path ); err != nil {
366390 return fmt .Errorf ("removing global workspace directory: %w" , err )
367391 }
368392 }
369393
394+ displayName := ws .Name
395+ if arg != "" && arg != "." {
396+ displayName = arg
397+ }
398+
370399 if err := s .DeleteWorkspace (ws .ID ); err != nil {
371400 return fmt .Errorf ("removing workspace: %w" , err )
372401 }
373402
374- if ws . IsGlobal {
375- fmt .Fprintf (os .Stderr , "Removed global workspace %q\n " , arg )
403+ if isGlobal {
404+ fmt .Fprintf (os .Stderr , "Removed global workspace %q\n " , displayName )
376405 } else {
377- fmt .Fprintf (os .Stderr , "Removed workspace %q (project files untouched)\n " , arg )
406+ fmt .Fprintf (os .Stderr , "Removed workspace %q (project files untouched)\n " , displayName )
378407 }
379408 return nil
380409}
0 commit comments