Skip to content

Commit 19e6b5f

Browse files
committed
chore(volume): change client use subcommand
1 parent 60b4c3c commit 19e6b5f

File tree

8 files changed

+493
-457
lines changed

8 files changed

+493
-457
lines changed

internal/completion/completion.go

-21
Original file line numberDiff line numberDiff line change
@@ -847,24 +847,3 @@ func (c *VolumesUnmountCompletion) CompletionFunc(cmd *cobra.Command, args []str
847847
}
848848
return ptsArgCompletion.CompletionFunc(cmd, args, toComplete)
849849
}
850-
851-
type VolumesCmdCompletion struct {
852-
ArgsLen int
853-
ConfigFile *string
854-
}
855-
856-
func (c *VolumesCmdCompletion) CompletionFunc(_ *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
857-
cmds := []string{"ls", "cp", "rm"}
858-
if c.ArgsLen < 0 || len(args) == c.ArgsLen {
859-
860-
var results []string
861-
for _, cmd := range cmds {
862-
if strings.HasPrefix(cmd, toComplete) {
863-
results = append(results, cmd)
864-
}
865-
}
866-
return results, cobra.ShellCompDirectiveNoFileComp
867-
868-
}
869-
return nil, cobra.ShellCompDirectiveNoFileComp
870-
}

internal/parser/limits.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func limitSetCommand(cmdr *commands.DryccCmd) *cobra.Command {
6262
Example: template.CustomExample(
6363
"drycc limits set web=std1.large.c1m2",
6464
map[string]string{
65-
"<ptype>": i18n.T("The process type as defined in your Procfile, such as 'web' or 'worker'."),
65+
"<ptype>": i18n.T("The process type as defined in your Procfile, such as 'web' or 'worker'"),
6666
"<value>": i18n.T("The limit plan id to apply to the process type"),
6767
},
6868
),

internal/parser/volumes.go

+41-15
Original file line numberDiff line numberDiff line change
@@ -196,29 +196,55 @@ func volumesRemoveCommand(cmdr *commands.DryccCmd) *cobra.Command {
196196
}
197197

198198
func volumesClientCommand(cmdr *commands.DryccCmd) *cobra.Command {
199-
volumesCmdCompletion := completion.VolumesCmdCompletion{ArgsLen: 0, ConfigFile: &cmdr.ConfigFile}
200199
cmd := &cobra.Command{
201-
Use: "client <cmd> <args>...",
200+
Use: "client",
201+
Short: i18n.T("The client used to manage volume files"),
202+
}
203+
cmd.AddCommand(&cobra.Command{
204+
Use: "ls <target>",
202205
Example: template.CustomExample(
203-
"drycc volumes client ls vol://myvolume/",
206+
"drycc volumes client ls vol://myvolume/tmp",
204207
map[string]string{
205-
"<cmd>": i18n.T(`ls list volume files
206-
cp copy volume files
207-
rm remove volume files`),
208-
"<args>": i18n.T(`arguments for running commands, when cmd is 'cp', args should be '[source] [dest]'.
209-
volume path format 'vol://volumename/', '/' is equivalent to the mount path.`),
208+
"<target>": i18n.T("The target path of volume"),
210209
},
211210
),
211+
Short: i18n.T("List volume objects"),
212+
Args: cobra.ExactArgs(1),
213+
RunE: func(_ *cobra.Command, args []string) error {
214+
return cmdr.VolumesClient(app, "ls", args...)
215+
},
216+
})
212217

213-
Short: i18n.T("The client used to manage volume files"),
214-
Args: cobra.MinimumNArgs(2),
215-
ValidArgsFunction: volumesCmdCompletion.CompletionFunc,
218+
cmd.AddCommand(&cobra.Command{
219+
Use: "cp <source> <target>",
220+
Example: template.CustomExample(
221+
"drycc volumes client cp vol://myvolume/tmp /tmp",
222+
map[string]string{
223+
"<source>": i18n.T("The volume or local source path"),
224+
"<target>": i18n.T("The volume or local target path"),
225+
},
226+
),
227+
Short: i18n.T("Copy volume objects"),
228+
Args: cobra.ExactArgs(2),
216229
RunE: func(_ *cobra.Command, args []string) error {
217-
cmdType := args[0]
218-
cmdArgs := args[1:]
219-
return cmdr.VolumesClient(app, cmdType, cmdArgs...)
230+
return cmdr.VolumesClient(app, "cp", args...)
220231
},
221-
}
232+
})
233+
234+
cmd.AddCommand(&cobra.Command{
235+
Use: "rm <target>",
236+
Example: template.CustomExample(
237+
"drycc volumes client rm vol://myvolume/tmp",
238+
map[string]string{
239+
"<target>": i18n.T("The target path of volume"),
240+
},
241+
),
242+
Short: i18n.T("Remove volume objects"),
243+
Args: cobra.ExactArgs(1),
244+
RunE: func(_ *cobra.Command, args []string) error {
245+
return cmdr.VolumesClient(app, "rm", args...)
246+
},
247+
})
222248

223249
return cmd
224250
}
Binary file not shown.

0 commit comments

Comments
 (0)