Skip to content

Commit 2501df7

Browse files
committed
add completion for limactl disk
Signed-off-by: Nikita Vasilchenko <[email protected]>
1 parent e944541 commit 2501df7

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

cmd/limactl/completion.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ func bashCompleteTemplateNames(_ *cobra.Command) ([]string, cobra.ShellCompDirec
2323
}
2424
return comp, cobra.ShellCompDirectiveDefault
2525
}
26+
27+
func bashCompleteDiskNames(_ *cobra.Command) ([]string, cobra.ShellCompDirective) {
28+
disks, err := store.Disks()
29+
if err != nil {
30+
return nil, cobra.ShellCompDirectiveDefault
31+
}
32+
return disks, cobra.ShellCompDirectiveNoFileComp
33+
}

cmd/limactl/disk.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,11 @@ $ limactl disk delete DISK
203203
To delete multiple disks:
204204
$ limactl disk delete DISK1 DISK2 ...
205205
`,
206-
Aliases: []string{"remove", "rm"},
207-
Short: "Delete one or more Lima disks",
208-
Args: WrapArgsError(cobra.MinimumNArgs(1)),
209-
RunE: diskDeleteAction,
206+
Aliases: []string{"remove", "rm"},
207+
Short: "Delete one or more Lima disks",
208+
Args: WrapArgsError(cobra.MinimumNArgs(1)),
209+
RunE: diskDeleteAction,
210+
ValidArgsFunction: diskBashComplete,
210211
}
211212
diskDeleteCommand.Flags().BoolP("force", "f", false, "force delete")
212213
return diskDeleteCommand
@@ -294,9 +295,10 @@ $ limactl disk unlock DISK
294295
To unlock multiple disks:
295296
$ limactl disk unlock DISK1 DISK2 ...
296297
`,
297-
Short: "Unlock one or more Lima disks",
298-
Args: WrapArgsError(cobra.MinimumNArgs(1)),
299-
RunE: diskUnlockAction,
298+
Short: "Unlock one or more Lima disks",
299+
Args: WrapArgsError(cobra.MinimumNArgs(1)),
300+
RunE: diskUnlockAction,
301+
ValidArgsFunction: diskBashComplete,
300302
}
301303
return diskUnlockCommand
302304
}
@@ -342,9 +344,10 @@ func newDiskResizeCommand() *cobra.Command {
342344
Example: `
343345
Resize a disk:
344346
$ limactl disk resize DISK --size SIZE`,
345-
Short: "Resize existing Lima disk",
346-
Args: WrapArgsError(cobra.ExactArgs(1)),
347-
RunE: diskResizeAction,
347+
Short: "Resize existing Lima disk",
348+
Args: WrapArgsError(cobra.ExactArgs(1)),
349+
RunE: diskResizeAction,
350+
ValidArgsFunction: diskBashComplete,
348351
}
349352
diskResizeCommand.Flags().String("size", "", "Disk size")
350353
_ = diskResizeCommand.MarkFlagRequired("size")
@@ -390,3 +393,7 @@ func diskResizeAction(cmd *cobra.Command, args []string) error {
390393
logrus.Infof("Resized disk %q (%q)", diskName, disk.Dir)
391394
return nil
392395
}
396+
397+
func diskBashComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
398+
return bashCompleteDiskNames(cmd)
399+
}

0 commit comments

Comments
 (0)