client/iaas: update how iaas is provided by user
@@ -13,6 +13,7 @@ import (
"strings"
"github.com/cezarsa/form"
+ "github.com/tsuru/gnuflag"
"github.com/tsuru/tsuru/cmd"
"github.com/tsuru/tsuru/iaas"
)
@@ -225,20 +226,33 @@ func (c *TemplateRemove) Run(context *cmd.Context, client *cmd.Client) error {
return nil
}
-type TemplateUpdate struct{}
+type TemplateUpdate struct {
+ cmd.GuessingCommand
+ iaas string
+ fs *gnuflag.FlagSet
+}
func (c *TemplateUpdate) Info() *cmd.Info {
return &cmd.Info{
Name: "machine-template-update",
- Usage: "machine-template-update <name> <param>=<value>...",
+ Usage: "machine-template-update [-i/--iaas <iaas_name>] <param>=<value>...",
Desc: "Update an existing machine template.",
- MinArgs: 2,
+ MinArgs: 1,
+ }
+}
+func (c *TemplateUpdate) Flags() *gnuflag.FlagSet {
+ if c.fs == nil {
+ c.fs = c.GuessingCommand.Flags()
+ iaas := "The iaas used"
+ c.fs.StringVar(&c.iaas, "iaas", "", iaas)
+ c.fs.StringVar(&c.iaas, "i", "", iaas)
}
+ return c.fs
}
func (c *TemplateUpdate) Run(context *cmd.Context, client *cmd.Client) error {
- template := iaas.Template{Name: context.Args[0]}
- for _, param := range context.Args[1:] {
+ template := iaas.Template{Name: c.iaas}
+ for _, param := range context.Args[0:] {
if strings.Contains(param, "=") {
keyValue := strings.SplitN(param, "=", 2)
template.Data = append(template.Data, iaas.TemplateData{
