-
Notifications
You must be signed in to change notification settings - Fork 983
cubemaster(cli): support positional template-id in tpl info/delete/redo #891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -449,9 +449,23 @@ var TemplateCreateCommand = cli.Command{ | |
| }, | ||
| } | ||
|
|
||
| // resolveTemplateID returns the template ID from the --template-id flag, | ||
| // falling back to the first positional argument to match docker/kubectl | ||
| // conventions (e.g. `cubemastercli tpl info <template-id>`). | ||
| func resolveTemplateID(c *cli.Context) string { | ||
| if id := c.String("template-id"); id != "" { | ||
| return id | ||
| } | ||
| if c.NArg() > 0 { | ||
| return c.Args().First() | ||
| } | ||
| return "" | ||
| } | ||
|
|
||
| var TemplateInfoCommand = cli.Command{ | ||
| Name: "info", | ||
| Usage: "show template metadata and node replicas", | ||
| Name: "info", | ||
| Usage: "show template metadata and node replicas", | ||
| ArgsUsage: "<template-id>", | ||
| Flags: []cli.Flag{ | ||
| cli.StringFlag{ | ||
| Name: "template-id", | ||
|
|
@@ -467,7 +481,7 @@ var TemplateInfoCommand = cli.Command{ | |
| }, | ||
| }, | ||
| Action: func(c *cli.Context) error { | ||
| templateID := c.String("template-id") | ||
| templateID := resolveTemplateID(c) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pre-existing note (not blocking): |
||
| if templateID == "" { | ||
| return errors.New("template-id is required") | ||
| } | ||
|
|
@@ -590,16 +604,17 @@ var TemplateRenderCommand = cli.Command{ | |
| } | ||
|
|
||
| var TemplateDeleteCommand = cli.Command{ | ||
| Name: "delete", | ||
| Usage: "delete template metadata and node replicas", | ||
| Name: "delete", | ||
| Usage: "delete template metadata and node replicas", | ||
| ArgsUsage: "<template-id>", | ||
| Flags: []cli.Flag{ | ||
| cli.StringFlag{ | ||
| Name: "template-id", | ||
| Usage: "template id to delete", | ||
| }, | ||
| }, | ||
| Action: func(c *cli.Context) error { | ||
| templateID := c.String("template-id") | ||
| templateID := resolveTemplateID(c) | ||
| if templateID == "" { | ||
| return errors.New("template-id is required") | ||
| } | ||
|
|
@@ -849,8 +864,9 @@ var TemplateCreateFromImageCommand = cli.Command{ | |
| } | ||
|
|
||
| var TemplateRedoCommand = cli.Command{ | ||
| Name: "redo", | ||
| Usage: "redo a template on all, specific, or failed nodes", | ||
| Name: "redo", | ||
| Usage: "redo a template on all, specific, or failed nodes", | ||
| ArgsUsage: "<template-id>", | ||
| Flags: []cli.Flag{ | ||
| cli.StringFlag{Name: "template-id", Usage: "template id to redo"}, | ||
| cli.StringSliceFlag{Name: "node", Usage: "redo only the specified node id or host ip; repeat to specify multiple nodes"}, | ||
|
|
@@ -861,7 +877,7 @@ var TemplateRedoCommand = cli.Command{ | |
| cli.BoolFlag{Name: "json", Usage: "print raw json response"}, | ||
| }, | ||
| Action: func(c *cli.Context) error { | ||
| templateID := c.String("template-id") | ||
| templateID := resolveTemplateID(c) | ||
| if templateID == "" { | ||
| return errors.New("template-id is required") | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c.Args().First()silently discards any additional positional arguments. A user typingcubemastercli tpl info tpl-abc extra-arggets no feedback about the extra arg. Consider either:Option A — Change signature to
(string, error)and add anNArg() > 1check.Option B (minimal) — At minimum log a warning when extra args are detected.