diff --git a/pkg/kn/commands/service/service_update.go b/pkg/kn/commands/service/service_update.go index 88eeb27669..e10000ec65 100644 --- a/pkg/kn/commands/service/service_update.go +++ b/pkg/kn/commands/service/service_update.go @@ -16,6 +16,7 @@ package service import ( "errors" + "fmt" "github.com/knative/client/pkg/kn/commands" "github.com/spf13/cobra" @@ -26,7 +27,7 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command { var editFlags ConfigurationEditFlags serviceUpdateCommand := &cobra.Command{ - Use: "update NAME", + Use: "update NAME [flags]", Short: "Update a service.", Example: ` # Updates a service 'mysvc' with new environment variables @@ -39,6 +40,10 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command { return errors.New("requires the service name.") } + if cmd.Flags().NFlag() == 0 { + return fmt.Errorf("Flag(s) not set\nUsage: %s", cmd.Use) + } + namespace, err := commands.GetNamespace(cmd) if err != nil { return err diff --git a/pkg/kn/commands/service/service_update_test.go b/pkg/kn/commands/service/service_update_test.go index fc1cd87d5e..0f1bb72747 100644 --- a/pkg/kn/commands/service/service_update_test.go +++ b/pkg/kn/commands/service/service_update_test.go @@ -18,6 +18,7 @@ import ( "errors" "fmt" "reflect" + "strings" "testing" "github.com/knative/client/pkg/kn/commands" @@ -63,6 +64,26 @@ func fakeServiceUpdate(original *v1alpha1.Service, args []string) ( return } +func TestServcieUpdateNoFlags(t *testing.T) { + orig := newEmptyService() + + action, _, _, err := fakeServiceUpdate(orig, []string{ + "service", "update", "foo"}) + + if action != nil { + t.Errorf("Unexpected action if no flag(s) set") + } + + if err != nil { + expectedErrMsg := "Flag(s) not set" + if !strings.Contains(err.Error(), expectedErrMsg) { + t.Errorf("Missing %s in %s", expectedErrMsg, err.Error()) + } + } else { + t.Errorf("Error is expected if no flag(s) set") + } +} + func TestServiceUpdateImage(t *testing.T) { orig := newEmptyService()