Make image flag mandatory for service create command (#60)

`service create` command always requires and specify `--image` to run.

This patch changes:
- Add validation check if image is empty or not.
- Add image to `MarkFlagRequired()`.
- to add `--image IMAGE` in help message
This commit is contained in:
Kenjiro Nakayama 2019-04-09 02:39:58 +09:00 committed by Knative Prow Robot
parent aa11ceab12
commit 58e478bba4
2 changed files with 5 additions and 1 deletions

View File

@ -33,6 +33,7 @@ func (p *ConfigurationEditFlags) AddFlags(command *cobra.Command) {
command.Flags().StringArrayVarP(&p.Env, "env", "e", []string{},
"Environment variable to set. NAME=value; you may provide this flag "+
"any number of times to set multiple environment variables.")
command.MarkFlagRequired("image")
}
func (p *ConfigurationEditFlags) Apply(config *servingv1alpha1.ConfigurationSpec) error {

View File

@ -29,12 +29,15 @@ func NewServiceCreateCommand(p *KnParams) *cobra.Command {
var editFlags ConfigurationEditFlags
serviceCreateCommand := &cobra.Command{
Use: "create NAME",
Use: "create NAME --image IMAGE",
Short: "Create a service.",
RunE: func(cmd *cobra.Command, args []string) (err error) {
if len(args) != 1 {
return errors.New("requires the service name.")
}
if editFlags.Image == "" {
return errors.New("requires the image name to run.")
}
namespace := cmd.Flag("namespace").Value.String()