Skip to content

Commit 60b4c3c

Browse files
authored
chore(workflow-cli): Optimize command flags (#82)
1 parent 16207d3 commit 60b4c3c

8 files changed

Lines changed: 34 additions & 15 deletions

File tree

internal/parser/domains.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func domainsAddCommand(cmdr *commands.DryccCmd) *cobra.Command {
5959
},
6060
}
6161

62-
cmd.Flags().StringVarP(&flags.ptype, "ptype", "p", "web", i18n.T("The ptype for domain"))
62+
cmd.Flags().StringVarP(&flags.ptype, "ptype", "p", "", i18n.T("The ptype for domain"))
63+
cmd.MarkFlagRequired("ptype")
6364

6465
ptypeCompletion := completion.PtsCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile, AppID: &app}
6566
cmd.RegisterFlagCompletionFunc("ptype", ptypeCompletion.CompletionFunc)

internal/parser/healthchecks.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func NewHealthchecksCommand(cmdr *commands.DryccCmd) *cobra.Command {
2727
}
2828

2929
cmd.PersistentFlags().StringVarP(&app, "app", "a", "", i18n.T("The uniquely identifiable name of the application"))
30-
cmd.PersistentFlags().StringVarP(&healthchecksFlags.ptype, "ptype", "p", "web", i18n.T("The ptype for which the health check needs to be removed"))
30+
cmd.PersistentFlags().StringVarP(&healthchecksFlags.ptype, "ptype", "p", "", i18n.T("The ptype for which the health check needs to be listed"))
3131
cmd.Flags().IntVarP(&version, "version", "v", 0, i18n.T("The version for which the health check needs to be listed"))
3232

3333
appCompletion := completion.AppCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile}
@@ -78,7 +78,7 @@ func healthchecksSet(cmdr *commands.DryccCmd) *cobra.Command {
7878

7979
healthChecksCompletion := completion.HealthChecksCompletion{ConfigFile: &cmdr.ConfigFile}
8080
cmd := &cobra.Command{
81-
Use: "set <health-type> <probe-type> [--] <args>...",
81+
Use: "set <health-type> <probe-type> [flags] [--] <args>...",
8282
Args: cobra.MinimumNArgs(2),
8383
Example: template.CustomExample(
8484
"drycc healthchecks set readinessProbe httpGet --path=/health -- 8000",
@@ -177,6 +177,10 @@ port number to perform the socket connection on the Container.
177177
},
178178
}
179179

180+
cmd.Flags().StringVarP(&healthchecksFlags.ptype, "ptype", "p", "", i18n.T("The ptype for which the health check needs to be applied"))
181+
ptypeCompletion := completion.PtsCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile, AppID: &app}
182+
cmd.RegisterFlagCompletionFunc("ptype", ptypeCompletion.CompletionFunc)
183+
180184
cmd.Flags().StringVar(&flags.path, "path", "/", i18n.T("The relative URL path for 'httpGet' probes"))
181185
cmd.Flags().StringVar(&flags.headers, "headers", "", i18n.T("The HTTP headers to send for 'httpGet' probes, separated by commas"))
182186
cmd.Flags().IntVar(&flags.initialDelay, "initial-delay-timeout", 50, i18n.T("The initial delay timeout for the probe"))
@@ -218,6 +222,10 @@ func healthchecksUnset(cmdr *commands.DryccCmd) *cobra.Command {
218222
return cmdr.HealthchecksUnset(app, healthchecksFlags.ptype, flags.healths)
219223
},
220224
}
225+
cmd.Flags().StringVarP(&healthchecksFlags.ptype, "ptype", "p", "", i18n.T("The ptype for which the health check needs to be removed"))
226+
ptypeCompletion := completion.PtsCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile, AppID: &app}
227+
cmd.RegisterFlagCompletionFunc("ptype", ptypeCompletion.CompletionFunc)
228+
221229
return cmd
222230
}
223231

internal/parser/perms.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package parser
22

33
import (
4+
"strings"
5+
46
"github.com/drycc/workflow-cli/internal/commands"
57
"github.com/drycc/workflow-cli/internal/completion"
68
"github.com/drycc/workflow-cli/internal/template"
@@ -70,7 +72,7 @@ func permAddCommand(cmdr *commands.DryccCmd) *cobra.Command {
7072
ValidArgsFunction: userPermsArgsCompletion.CompletionFunc,
7173
RunE: func(_ *cobra.Command, args []string) error {
7274
flags.username = args[0]
73-
flags.permissions = args[1]
75+
flags.permissions = strings.Join(args[1:], ",")
7476
return cmdr.PermCreate(app, flags.username, flags.permissions)
7577
},
7678
}
@@ -100,7 +102,7 @@ func permUpdateCommand(cmdr *commands.DryccCmd) *cobra.Command {
100102
ValidArgsFunction: permUpdateCompletion.CompletionFunc,
101103
RunE: func(_ *cobra.Command, args []string) error {
102104
flags.username = args[0]
103-
flags.permissions = args[1]
105+
flags.permissions = strings.Join(args[1:], ",")
104106
return cmdr.PermUpdate(app, flags.username, flags.permissions)
105107
},
106108
}

internal/parser/ps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func psDescribeCommand(cmdr *commands.DryccCmd) *cobra.Command {
142142
}
143143

144144
func psDeleteCommand(cmdr *commands.DryccCmd) *cobra.Command {
145-
psCompletion := completion.PsCompletion{AppID: &app, ArgsLen: 0, ConfigFile: &cmdr.ConfigFile}
145+
psCompletion := completion.PsCompletion{AppID: &app, ArgsLen: -1, ConfigFile: &cmdr.ConfigFile}
146146
cmd := &cobra.Command{
147147
Use: "delete <pod>...",
148148
Args: cobra.MinimumNArgs(1),

internal/parser/registry.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ func registrySetCommand(cmdr *commands.DryccCmd) *cobra.Command {
8282
},
8383
}
8484

85-
cmd.Flags().StringVarP(&flags.ptype, "ptype", "p", "web", i18n.T("The ptype for registry"))
85+
cmd.Flags().StringVarP(&flags.ptype, "ptype", "p", "", i18n.T("The ptype for registry"))
86+
cmd.MarkFlagRequired("ptype")
8687

8788
ptypeCompletion := completion.PtsCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile, AppID: &app}
8889
cmd.RegisterFlagCompletionFunc("ptype", ptypeCompletion.CompletionFunc)
@@ -103,7 +104,8 @@ func registryUnsetCommand(cmdr *commands.DryccCmd) *cobra.Command {
103104
},
104105
}
105106

106-
cmd.Flags().StringVarP(&flags.ptype, "ptype", "p", "web", i18n.T("The ptype for registry"))
107+
cmd.Flags().StringVarP(&flags.ptype, "ptype", "p", "", i18n.T("The ptype for registry"))
108+
cmd.MarkFlagRequired("ptype")
107109

108110
ptypeCompletion := completion.PtsCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile, AppID: &app}
109111
cmd.RegisterFlagCompletionFunc("ptype", ptypeCompletion.CompletionFunc)

internal/parser/resources.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ func resourcesServicesCommand(cmdr *commands.DryccCmd) *cobra.Command {
4848
},
4949
}
5050

51-
cmd.Flags().IntVarP(&limit, "limit", "l", 0, i18n.T("The maximum number of results to display"))
52-
5351
return cmd
5452
}
5553

@@ -73,8 +71,6 @@ func resourcesPlansCommand(cmdr *commands.DryccCmd) *cobra.Command {
7371
},
7472
}
7573

76-
cmd.Flags().IntVarP(&limit, "limit", "l", 0, i18n.T("The maximum number of results to display"))
77-
7874
return cmd
7975
}
8076

internal/parser/tags.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func tagsListCommand(cmdr *commands.DryccCmd) *cobra.Command {
5757
},
5858
}
5959

60-
cmd.Flags().StringVarP(&flags.ptype, "ptype", "p", "web", i18n.T("The process name as defined in your Procfile"))
60+
cmd.Flags().StringVarP(&flags.ptype, "ptype", "p", "", i18n.T("The process name as defined in your Procfile"))
6161
cmd.Flags().IntVarP(&version, "version", "v", 0, i18n.T("The version for which the tag needs to be listed"))
6262

6363
ptypeCompletion := completion.PtsCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile, AppID: &app}
@@ -97,7 +97,8 @@ scheduler-configured metadata.`),
9797
},
9898
}
9999

100-
cmd.Flags().StringVarP(&flags.ptype, "ptype", "p", "web", i18n.T("The process name as defined in your Procfile"))
100+
cmd.Flags().StringVarP(&flags.ptype, "ptype", "p", "", i18n.T("The process name as defined in your Procfile"))
101+
cmd.MarkFlagRequired("ptype")
101102

102103
ptypeCompletion := completion.PtsCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile, AppID: &app}
103104
cmd.RegisterFlagCompletionFunc("ptype", ptypeCompletion.CompletionFunc)
@@ -127,7 +128,8 @@ func tagsUnsetCommand(cmdr *commands.DryccCmd) *cobra.Command {
127128
},
128129
}
129130

130-
cmd.Flags().StringVarP(&flags.ptype, "ptype", "p", "web", i18n.T("The process name as defined in your Procfile"))
131+
cmd.Flags().StringVarP(&flags.ptype, "ptype", "p", "", i18n.T("The process name as defined in your Procfile"))
132+
cmd.MarkFlagRequired("ptype")
131133

132134
ptypeCompletion := completion.PtsCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile, AppID: &app}
133135
cmd.RegisterFlagCompletionFunc("ptype", ptypeCompletion.CompletionFunc)

pkg/i18n/translations/drycc/zh_CN/LC_MESSAGES/cli.po

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,14 @@ msgid "The ptype for which the config needs to be unset"
14181418
msgstr "要清除配置的进程类型"
14191419

14201420
#: internal/parser/healthchecks.go:30
1421+
msgid "The ptype for which the health check needs to be listed"
1422+
msgstr "要列出健康检查的进程类型"
1423+
1424+
#: internal/parser/healthchecks.go:180
1425+
msgid "The ptype for which the health check needs to be applied"
1426+
msgstr "要应用健康检查的进程类型"
1427+
1428+
#: internal/parser/healthchecks.go:225
14211429
msgid "The ptype for which the health check needs to be removed"
14221430
msgstr "要移除健康检查的进程类型"
14231431

0 commit comments

Comments
 (0)