Skip to content

Commit

Permalink
Errors out if json machine output has not been implemented
Browse files Browse the repository at this point in the history
This PR:

 - Moves annotations to `&cobra.Command` struct creation rather than
 using the command to add it
 - Errors out if `-o json` has been passed, but json support has not
 been added
 - Hides the `-o json` command if it's not impemented
 - Solves the issue of #2031

Closes #2031
  • Loading branch information
cdrage committed Oct 8, 2019
1 parent f7c4db3 commit cbf1b4e
Show file tree
Hide file tree
Showing 25 changed files with 186 additions and 120 deletions.
12 changes: 7 additions & 5 deletions pkg/odo/cli/application/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,19 @@ func (o *DescribeOptions) Run() (err error) {
func NewCmdDescribe(name, fullName string) *cobra.Command {
o := NewDescribeOptions()
command := &cobra.Command{
Use: fmt.Sprintf("%s [application_name]", name),
Short: "Describe the given application",
Long: "Describe the given application",
Example: fmt.Sprintf(describeExample, fullName),
Args: cobra.MaximumNArgs(1),
Use: fmt.Sprintf("%s [application_name]", name),
Short: "Describe the given application",
Long: "Describe the given application",
Example: fmt.Sprintf(describeExample, fullName),
Args: cobra.MaximumNArgs(1),
Annotations: map[string]string{"machineoutput": "json"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(o, cmd, args)
},
}

completion.RegisterCommandHandler(command, completion.AppCompletionHandler)

project.AddProjectFlag(command)
return command
}
11 changes: 6 additions & 5 deletions pkg/odo/cli/application/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,12 @@ func (o *ListOptions) Run() (err error) {
func NewCmdList(name, fullName string) *cobra.Command {
o := NewListOptions()
command := &cobra.Command{
Use: name,
Short: "List all applications in the current project",
Long: "List all applications in the current project",
Example: fmt.Sprintf(listExample, fullName),
Args: cobra.NoArgs,
Use: name,
Short: "List all applications in the current project",
Long: "List all applications in the current project",
Example: fmt.Sprintf(listExample, fullName),
Args: cobra.NoArgs,
Annotations: map[string]string{"machineoutput": "json"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(o, cmd, args)
},
Expand Down
9 changes: 5 additions & 4 deletions pkg/odo/cli/catalog/list/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ func NewCmdCatalogListComponents(name, fullName string) *cobra.Command {
o := NewListComponentsOptions()

return &cobra.Command{
Use: name,
Short: "List all components",
Long: "List all available component types from OpenShift's Image Builder",
Example: fmt.Sprintf(componentsExample, fullName),
Use: name,
Short: "List all components",
Long: "List all available component types from OpenShift's Image Builder",
Example: fmt.Sprintf(componentsExample, fullName),
Annotations: map[string]string{"machineoutput": "json"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(o, cmd, args)
},
Expand Down
11 changes: 6 additions & 5 deletions pkg/odo/cli/catalog/list/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ func (o *ListServicesOptions) Run() (err error) {
func NewCmdCatalogListServices(name, fullName string) *cobra.Command {
o := NewListServicesOptions()
return &cobra.Command{
Use: name,
Short: "Lists all available services",
Long: "Lists all available services",
Example: fmt.Sprintf(servicesExample, fullName),
Args: cobra.ExactArgs(0),
Use: name,
Short: "Lists all available services",
Long: "Lists all available services",
Example: fmt.Sprintf(servicesExample, fullName),
Args: cobra.ExactArgs(0),
Annotations: map[string]string{"machineoutput": "json"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(o, cmd, args)
},
Expand Down
1 change: 1 addition & 0 deletions pkg/odo/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func NewCmdOdo(name, fullName string) *cobra.Command {

rootCmd.SetUsageTemplate(rootUsageTemplate)
cobra.AddTemplateFunc("CapitalizeFlagDescriptions", odoutil.CapitalizeFlagDescriptions)
cobra.AddTemplateFunc("ModifyAdditionalFlags", odoutil.ModifyAdditionalFlags)

rootCmd.AddCommand(
application.NewCmdApplication(application.RecommendedCommandName, util.GetFullName(fullName, application.RecommendedCommandName)),
Expand Down
12 changes: 6 additions & 6 deletions pkg/odo/cli/component/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,11 +546,12 @@ func ensureAndLogProperResourceUsage(resource, resourceMin, resourceMax, resourc
func NewCmdCreate(name, fullName string) *cobra.Command {
co := NewCreateOptions()
var componentCreateCmd = &cobra.Command{
Use: fmt.Sprintf("%s <component_type> [component_name] [flags]", name),
Short: "Create a new component",
Long: createLongDesc,
Example: fmt.Sprintf(createExample, fullName),
Args: cobra.RangeArgs(0, 2),
Use: fmt.Sprintf("%s <component_type> [component_name] [flags]", name),
Short: "Create a new component",
Long: createLongDesc,
Example: fmt.Sprintf(createExample, fullName),
Args: cobra.RangeArgs(0, 2),
Annotations: map[string]string{"machineoutput": "json", "component": "component"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(co, cmd, args)
},
Expand All @@ -568,7 +569,6 @@ func NewCmdCreate(name, fullName string) *cobra.Command {
componentCreateCmd.Flags().StringSliceVarP(&co.componentPorts, "port", "p", []string{}, "Ports to be used when the component is created (ex. 8080,8100/tcp,9100/udp)")
componentCreateCmd.Flags().StringSliceVar(&co.componentEnvVars, "env", []string{}, "Environmental variables for the component. For example --env VariableName=Value")
// Add a defined annotation in order to appear in the help menu
componentCreateCmd.Annotations = map[string]string{"command": "component"}
componentCreateCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)

// Adding `--now` flag
Expand Down
12 changes: 6 additions & 6 deletions pkg/odo/cli/component/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ func NewCmdDelete(name, fullName string) *cobra.Command {
do := NewDeleteOptions()

var componentDeleteCmd = &cobra.Command{
Use: fmt.Sprintf("%s <component_name>", name),
Short: "Delete component",
Long: "Delete component.",
Example: fmt.Sprintf(deleteExample, fullName),
Args: cobra.MaximumNArgs(1),
Use: fmt.Sprintf("%s <component_name>", name),
Short: "Delete component",
Long: "Delete component.",
Example: fmt.Sprintf(deleteExample, fullName),
Args: cobra.MaximumNArgs(1),
Annotations: map[string]string{"command": "component"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(do, cmd, args)
},
Expand All @@ -133,7 +134,6 @@ func NewCmdDelete(name, fullName string) *cobra.Command {
componentDeleteCmd.Flags().BoolVarP(&do.componentDeleteAllFlag, "all", "a", false, "Delete component and local config")

// Add a defined annotation in order to appear in the help menu
componentDeleteCmd.Annotations = map[string]string{"command": "component"}
componentDeleteCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
completion.RegisterCommandHandler(componentDeleteCmd, completion.ComponentNameCompletionHandler)
//Adding `--context` flag
Expand Down
12 changes: 6 additions & 6 deletions pkg/odo/cli/component/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,18 @@ func NewCmdDescribe(name, fullName string) *cobra.Command {
do := NewDescribeOptions()

var describeCmd = &cobra.Command{
Use: fmt.Sprintf("%s [component_name]", name),
Short: "Describe component",
Long: `Describe component.`,
Example: fmt.Sprintf(describeExample, fullName),
Args: cobra.RangeArgs(0, 1),
Use: fmt.Sprintf("%s [component_name]", name),
Short: "Describe component",
Long: `Describe component.`,
Example: fmt.Sprintf(describeExample, fullName),
Args: cobra.RangeArgs(0, 1),
Annotations: map[string]string{"machineoutput": "json", "command": "component"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(do, cmd, args)
},
}

// Add a defined annotation in order to appear in the help menu
describeCmd.Annotations = map[string]string{"command": "component"}
describeCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
completion.RegisterCommandHandler(describeCmd, completion.ComponentNameCompletionHandler)
// Adding --context flag
Expand Down
12 changes: 6 additions & 6 deletions pkg/odo/cli/component/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ func NewCmdLink(name, fullName string) *cobra.Command {
o := NewLinkOptions()

linkCmd := &cobra.Command{
Use: fmt.Sprintf("%s <service> --component [component] OR %s <component> --component [component]", name, name),
Short: "Link component to a service or component",
Long: linkLongDesc,
Example: fmt.Sprintf(linkExample, fullName),
Args: cobra.ExactArgs(1),
Use: fmt.Sprintf("%s <service> --component [component] OR %s <component> --component [component]", name, name),
Short: "Link component to a service or component",
Long: linkLongDesc,
Example: fmt.Sprintf(linkExample, fullName),
Args: cobra.ExactArgs(1),
Annotations: map[string]string{"command": "component"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(o, cmd, args)
},
Expand All @@ -134,7 +135,6 @@ func NewCmdLink(name, fullName string) *cobra.Command {
linkCmd.PersistentFlags().BoolVar(&o.waitForTarget, "wait-for-target", false, "If enabled, the link command will wait for the service to be provisioned (has no effect when linking to a component)")

// Add a defined annotation in order to appear in the help menu
linkCmd.Annotations = map[string]string{"command": "component"}
linkCmd.SetUsageTemplate(util.CmdUsageTemplate)
//Adding `--project` flag
projectCmd.AddProjectFlag(linkCmd)
Expand Down
12 changes: 6 additions & 6 deletions pkg/odo/cli/component/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,17 @@ func NewCmdList(name, fullName string) *cobra.Command {
o := NewListOptions()

var componentListCmd = &cobra.Command{
Use: name,
Short: "List all components in the current application",
Long: "List all components in the current application.",
Example: fmt.Sprintf(listExample, fullName),
Args: cobra.NoArgs,
Use: name,
Short: "List all components in the current application",
Long: "List all components in the current application.",
Example: fmt.Sprintf(listExample, fullName),
Args: cobra.NoArgs,
Annotations: map[string]string{"machineoutput": "json", "command": "component"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(o, cmd, args)
},
}
// Add a defined annotation in order to appear in the help menu
componentListCmd.Annotations = map[string]string{"command": "component"}
genericclioptions.AddContextFlag(componentListCmd, &o.componentContext)
componentListCmd.Flags().StringVar(&o.pathFlag, "path", "", "path of the directory to scan for odo component directories")
componentListCmd.Flags().BoolVar(&o.allFlag, "all", false, "lists all components")
Expand Down
12 changes: 6 additions & 6 deletions pkg/odo/cli/component/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ func NewCmdLog(name, fullName string) *cobra.Command {
o := NewLogOptions()

var logCmd = &cobra.Command{
Use: fmt.Sprintf("%s [component_name]", name),
Short: "Retrieve the log for the given component",
Long: `Retrieve the log for the given component`,
Example: fmt.Sprintf(logExample, fullName),
Args: cobra.RangeArgs(0, 1),
Use: fmt.Sprintf("%s [component_name]", name),
Short: "Retrieve the log for the given component",
Long: `Retrieve the log for the given component`,
Example: fmt.Sprintf(logExample, fullName),
Args: cobra.RangeArgs(0, 1),
Annotations: map[string]string{"command": "component"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(o, cmd, args)
},
Expand All @@ -74,7 +75,6 @@ func NewCmdLog(name, fullName string) *cobra.Command {
logCmd.Flags().BoolVarP(&o.logFollow, "follow", "f", false, "Follow logs")

// Add a defined annotation in order to appear in the help menu
logCmd.Annotations = map[string]string{"command": "component"}
logCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
completion.RegisterCommandHandler(logCmd, completion.ComponentNameCompletionHandler)
// Adding `--context` flag
Expand Down
12 changes: 6 additions & 6 deletions pkg/odo/cli/component/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ func NewCmdPush(name, fullName string) *cobra.Command {
po := NewPushOptions()

var pushCmd = &cobra.Command{
Use: fmt.Sprintf("%s [component name]", name),
Short: "Push source code to a component",
Long: `Push source code to a component.`,
Example: fmt.Sprintf(pushCmdExample, fullName),
Args: cobra.MaximumNArgs(1),
Use: fmt.Sprintf("%s [component name]", name),
Short: "Push source code to a component",
Long: `Push source code to a component.`,
Example: fmt.Sprintf(pushCmdExample, fullName),
Args: cobra.MaximumNArgs(1),
Annotations: map[string]string{"command": "component"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(po, cmd, args)
},
Expand All @@ -126,7 +127,6 @@ func NewCmdPush(name, fullName string) *cobra.Command {
pushCmd.Flags().BoolVarP(&po.forceBuild, "force-build", "f", false, "Use force-build flag to force building the component")

// Add a defined annotation in order to appear in the help menu
pushCmd.Annotations = map[string]string{"command": "component"}
pushCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
completion.RegisterCommandHandler(pushCmd, completion.ComponentNameCompletionHandler)
completion.RegisterCommandFlagHandler(pushCmd, "context", completion.FileCompletionHandler)
Expand Down
12 changes: 6 additions & 6 deletions pkg/odo/cli/component/unlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ func NewCmdUnlink(name, fullName string) *cobra.Command {
o := NewUnlinkOptions()

unlinkCmd := &cobra.Command{
Use: fmt.Sprintf("%s <service> --component [component] OR %s <component> --component [component]", name, name),
Short: "Unlink component to a service or component",
Long: unlinkLongDesc,
Example: fmt.Sprintf(unlinkExample, fullName),
Args: cobra.ExactArgs(1),
Use: fmt.Sprintf("%s <service> --component [component] OR %s <component> --component [component]", name, name),
Short: "Unlink component to a service or component",
Long: unlinkLongDesc,
Example: fmt.Sprintf(unlinkExample, fullName),
Args: cobra.ExactArgs(1),
Annotations: map[string]string{"command": "component"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(o, cmd, args)
},
Expand All @@ -87,7 +88,6 @@ func NewCmdUnlink(name, fullName string) *cobra.Command {
unlinkCmd.PersistentFlags().BoolVarP(&o.wait, "wait", "w", false, "If enabled the link will return only when the component is fully running after the link is deleted")

// Add a defined annotation in order to appear in the help menu
unlinkCmd.Annotations = map[string]string{"command": "component"}
unlinkCmd.SetUsageTemplate(util.CmdUsageTemplate)
//Adding `--project` flag
projectCmd.AddProjectFlag(unlinkCmd)
Expand Down
12 changes: 6 additions & 6 deletions pkg/odo/cli/component/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,12 @@ func NewCmdUpdate(name, fullName string) *cobra.Command {
uo := NewUpdateOptions()

var updateCmd = &cobra.Command{
Use: name,
Args: cobra.MaximumNArgs(1),
Short: "Update the source code path of a component",
Long: "Update the source code path of a component",
Example: fmt.Sprintf(updateCmdExample, fullName),
Use: name,
Short: "Update the source code path of a component",
Long: "Update the source code path of a component",
Example: fmt.Sprintf(updateCmdExample, fullName),
Args: cobra.MaximumNArgs(1),
Annotations: map[string]string{"command": "component"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(uo, cmd, args)
},
Expand All @@ -167,7 +168,6 @@ func NewCmdUpdate(name, fullName string) *cobra.Command {
updateCmd.Flags().StringVarP(&uo.local, "local", "l", "", "Use local directory as a source for component.")
updateCmd.Flags().StringVarP(&uo.ref, "ref", "r", "", "Use a specific ref e.g. commit, branch or tag of the git repository")
// Add a defined annotation in order to appear in the help menu
updateCmd.Annotations = map[string]string{"command": "component"}
updateCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)

//Adding `--application` flag
Expand Down
12 changes: 6 additions & 6 deletions pkg/odo/cli/component/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ func NewCmdWatch(name, fullName string) *cobra.Command {
wo := NewWatchOptions()

var watchCmd = &cobra.Command{
Use: fmt.Sprintf("%s [component name]", name),
Short: "Watch for changes, update component on change",
Long: watchLongDesc,
Example: fmt.Sprintf(watchExample, fullName),
Args: cobra.MaximumNArgs(1),
Use: fmt.Sprintf("%s [component name]", name),
Short: "Watch for changes, update component on change",
Long: watchLongDesc,
Example: fmt.Sprintf(watchExample, fullName),
Args: cobra.MaximumNArgs(1),
Annotations: map[string]string{"command": "component"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(wo, cmd, args)
},
Expand All @@ -162,7 +163,6 @@ func NewCmdWatch(name, fullName string) *cobra.Command {
watchCmd.Flags().IntVar(&wo.delay, "delay", 1, "Time in seconds between a detection of code change and push.delay=0 means changes will be pushed as soon as they are detected which can cause performance issues")

// Add a defined annotation in order to appear in the help menu
watchCmd.Annotations = map[string]string{"command": "component"}
watchCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
// Adding context flag
genericclioptions.AddContextFlag(watchCmd, &wo.componentContext)
Expand Down
11 changes: 6 additions & 5 deletions pkg/odo/cli/project/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ func NewCmdProjectCreate(name, fullName string) *cobra.Command {
o := NewProjectCreateOptions()

projectCreateCmd := &cobra.Command{
Use: name,
Short: createShortDesc,
Long: createLongDesc,
Example: fmt.Sprintf(createExample, fullName),
Args: cobra.ExactArgs(1),
Use: name,
Short: createShortDesc,
Long: createLongDesc,
Example: fmt.Sprintf(createExample, fullName),
Args: cobra.ExactArgs(1),
Annotations: map[string]string{"machineoutput": "json"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(o, cmd, args)
},
Expand Down
11 changes: 6 additions & 5 deletions pkg/odo/cli/project/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ func NewCmdProjectDelete(name, fullName string) *cobra.Command {
o := NewProjectDeleteOptions()

projectDeleteCmd := &cobra.Command{
Use: name,
Short: deleteShortDesc,
Long: deleteLongDesc,
Example: fmt.Sprintf(deleteExample, fullName),
Args: cobra.ExactArgs(1),
Use: name,
Short: deleteShortDesc,
Long: deleteLongDesc,
Example: fmt.Sprintf(deleteExample, fullName),
Args: cobra.ExactArgs(1),
Annotations: map[string]string{"machineoutput": "json"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(o, cmd, args)
},
Expand Down
11 changes: 6 additions & 5 deletions pkg/odo/cli/project/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ func (plo *ProjectListOptions) Run() (err error) {
func NewCmdProjectList(name, fullName string) *cobra.Command {
o := NewProjectListOptions()
projectListCmd := &cobra.Command{
Use: name,
Short: listLongDesc,
Long: listLongDesc,
Example: fmt.Sprintf(listExample, fullName),
Args: cobra.ExactArgs(0),
Use: name,
Short: listLongDesc,
Long: listLongDesc,
Example: fmt.Sprintf(listExample, fullName),
Args: cobra.ExactArgs(0),
Annotations: map[string]string{"machineoutput": "json"},
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(o, cmd, args)
},
Expand Down
Loading

0 comments on commit cbf1b4e

Please sign in to comment.