func (command *commandCreate) HandleFlags(resource *handler.Resource) error { c := command.Ctx.CLIContext err := command.Ctx.CheckFlagsSet([]string{"name"}) if err != nil { return err } opts := &osServers.CreateImageOpts{ Name: c.String("name"), } if c.IsSet("metadata") { metadata, err := command.Ctx.CheckKVFlag("metadata") if err != nil { return err } opts.Metadata = metadata } resource.Params = ¶msCreate{ opts: opts, } if c.IsSet("server-id") { resource.Params.(*paramsCreate).serverID = c.String("server-id") return nil } serverID, err := osServers.IDFromName(command.Ctx.ServiceClient, c.String("server-name")) resource.Params.(*paramsCreate).serverID = serverID return err }
func volumeIDorName(ctx *handler.Context) (string, error) { if ctx.CLIContext.IsSet("volume-id") { if ctx.CLIContext.IsSet("volume-name") { return "", fmt.Errorf("Only one of either --volume-id or --volume-name may be provided.") } return ctx.CLIContext.String("volume-id"), nil } else if ctx.CLIContext.IsSet("volume-name") { name := ctx.CLIContext.String("volume-name") id, err := osServers.IDFromName(ctx.ServiceClient, name) if err != nil { return "", fmt.Errorf("Error converting name [%s] to ID: %s", name, err) } return id, nil } else { return "", output.ErrMissingFlag{Msg: "One of either --volume-id or --volume-name must be provided."} } }