Skip to content

Commit

Permalink
Merge df0eb32 into 6ed1287
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy authored Dec 15, 2022
2 parents 6ed1287 + df0eb32 commit e96f123
Show file tree
Hide file tree
Showing 27 changed files with 176 additions and 44 deletions.
108 changes: 108 additions & 0 deletions cmd/odo/help_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package main

import (
"bytes"
"context"
"strings"
"testing"

"github.com/redhat-developer/odo/pkg/config"
envcontext "github.com/redhat-developer/odo/pkg/config/context"
"github.com/redhat-developer/odo/pkg/odo/cli"
"k8s.io/klog"
)

var (
intro = `Usage:
odo [flags]
odo [command]
Examples:
Initializing your component by taking your pick from multiple languages or frameworks:
odo init
After creating your initial component, start development with:
odo dev
Want to deploy after development? See it live with:
odo deploy`

mainCommands = `Main Commands:
build-images Build images
deploy Deploy components
dev Deploy component to development cluster
init Init bootstraps a new project
logs Show logs of all containers of the component
registry List all components from the Devfile registry
`

managementCommands = `Management Commands:
add Add resources to devfile (binding)
create Perform create operation (namespace)
delete Delete resources (component, namespace)
describe Describe resource (binding, component)
list List all components in the current namespace (binding, component, namespace, services)
remove Remove resources from devfile (binding)
set Perform set operation (namespace)
`

openshiftCommands = `OpenShift Commands:
login Login to cluster
logout Logout of the cluster`

utilityCommands = `Utility Commands:
analyze Detect devfile to use based on files present in current directory
completion Add odo completion support to your development environment
preference Modifies preference settings (add, remove, set, unset, view)
version Print the client version information
`
)

func TestOdoHelp(t *testing.T) {
ctx := context.Background()
envConfig, err := config.GetConfiguration()
if err != nil {
t.Fatal(err)
}
ctx = envcontext.WithEnvConfig(ctx, *envConfig)
klog.InitFlags(nil)

root := cli.NewCmdOdo(ctx, cli.OdoRecommendedName, cli.OdoRecommendedName)

var stdoutB, stderrB bytes.Buffer
root.SetOut(&stdoutB)
root.SetErr(&stderrB)

root.SetArgs([]string{"help"})

err = root.ExecuteContext(ctx)
if err != nil {
t.Fatal(err)
}

stdout := stdoutB.String()
stderr := stderrB.String()

if stderr != "" {
t.Fatal("stderr should be empty")
}

if !strings.Contains(stdout, intro) {
t.Fatalf("stdout should contain \n%s\nbut is\n%s\n", intro, stdout)
}
if !strings.Contains(stdout, mainCommands) {
t.Fatalf("stdout should contain \n%s\nbut is\n%s\n", mainCommands, stdout)
}
if !strings.Contains(stdout, managementCommands) {
t.Fatalf("stdout should contain \n%s\nbut is\n%s\n", managementCommands, stdout)
}
if !strings.Contains(stdout, openshiftCommands) {
t.Fatalf("stdout should contain \n%s\nbut is\n%s\n", openshiftCommands, stdout)
}
if !strings.Contains(stdout, utilityCommands) {
t.Fatalf("stdout should contain \n%s\nbut is\n%s\n", utilityCommands, stdout)
}
}
2 changes: 1 addition & 1 deletion pkg/odo/cli/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewCmdAdd(name, fullName string) *cobra.Command {

bindingCmd := binding.NewCmdBinding(binding.BindingRecommendedCommandName, util.GetFullName(fullName, binding.BindingRecommendedCommandName))
createCmd.AddCommand(bindingCmd)
createCmd.Annotations = map[string]string{"command": "management"}
util.SetCommandGroup(createCmd, util.ManagementGroup)
createCmd.SetUsageTemplate(util.CmdUsageTemplate)

return createCmd
Expand Down
3 changes: 2 additions & 1 deletion pkg/odo/cli/alizer/alizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
odocontext "github.com/redhat-developer/odo/pkg/odo/context"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
"github.com/redhat-developer/odo/pkg/odo/util"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -74,8 +75,8 @@ func NewCmdAlizer(name, fullName string) *cobra.Command {
},
}
clientset.Add(alizerCmd, clientset.ALIZER, clientset.FILESYSTEM)
util.SetCommandGroup(alizerCmd, util.UtilityGroup)
commonflags.UseOutputFlag(alizerCmd)
alizerCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
alizerCmd.Annotations["command"] = "utility"
return alizerCmd
}
4 changes: 2 additions & 2 deletions pkg/odo/cli/build_images/build_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
odocontext "github.com/redhat-developer/odo/pkg/odo/context"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
"github.com/redhat-developer/odo/pkg/odo/util"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
)

Expand Down Expand Up @@ -79,8 +80,7 @@ func NewCmdBuildImages(name, fullName string) *cobra.Command {
},
}

// Add a defined annotation in order to appear in the help menu
buildImagesCmd.Annotations = map[string]string{"command": "main"}
util.SetCommandGroup(buildImagesCmd, util.MainGroup)
buildImagesCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
buildImagesCmd.Flags().BoolVar(&o.pushFlag, "push", false, "If true, build and push the images")
clientset.Add(buildImagesCmd, clientset.FILESYSTEM)
Expand Down
2 changes: 1 addition & 1 deletion pkg/odo/cli/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ func NewCmdCompletion(name, fullName string) *cobra.Command {
}

completionCmd.SetUsageTemplate(util.CmdUsageTemplate)
completionCmd.Annotations = map[string]string{"command": "utility"}
util.SetCommandGroup(completionCmd, util.UtilityGroup)
return completionCmd
}
3 changes: 2 additions & 1 deletion pkg/odo/cli/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/spf13/cobra"

"github.com/redhat-developer/odo/pkg/odo/cli/create/namespace"
"github.com/redhat-developer/odo/pkg/odo/util"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
)

Expand All @@ -23,12 +24,12 @@ func NewCmdCreate(name, fullName string) *cobra.Command {
Example: fmt.Sprintf("%s\n",
namespaceCreateCmd.Example,
),
Annotations: map[string]string{"command": "management"},
}

createCmd.AddCommand(namespaceCreateCmd)

// Add a defined annotation in order to appear in the help menu
util.SetCommandGroup(createCmd, util.ManagementGroup)
createCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)

return createCmd
Expand Down
5 changes: 3 additions & 2 deletions pkg/odo/cli/create/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/redhat-developer/odo/pkg/odo/cmdline"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
"github.com/redhat-developer/odo/pkg/odo/util"
scontext "github.com/redhat-developer/odo/pkg/segment/context"
)

Expand Down Expand Up @@ -128,13 +129,13 @@ func NewCmdNamespaceCreate(name, fullName string) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
return genericclioptions.GenericRun(o, cmd, args)
},
Annotations: map[string]string{"command": "main"},
Aliases: []string{"project"},
Aliases: []string{"project"},
}

namespaceCreateCmd.Flags().BoolVarP(&o.waitFlag, "wait", "w", false, "Wait until the namespace is ready")

clientset.Add(namespaceCreateCmd, clientset.KUBERNETES, clientset.PROJECT)
util.SetCommandGroup(namespaceCreateCmd, util.MainGroup)

return namespaceCreateCmd
}
6 changes: 3 additions & 3 deletions pkg/odo/cli/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ const RecommendedCommandName = "delete"
// NewCmdDelete implements the delete odo command
func NewCmdDelete(name, fullName string) *cobra.Command {
var deleteCmd = &cobra.Command{
Use: name,
Short: "Delete resources",
Annotations: map[string]string{"command": "management"},
Use: name,
Short: "Delete resources",
}

componentCmd := component.NewCmdComponent(component.ComponentRecommendedCommandName,
Expand All @@ -26,6 +25,7 @@ func NewCmdDelete(name, fullName string) *cobra.Command {
util.GetFullName(fullName, namespace.RecommendedCommandName))
deleteCmd.AddCommand(namespaceDeleteCmd)

util.SetCommandGroup(deleteCmd, util.ManagementGroup)
deleteCmd.SetUsageTemplate(util.CmdUsageTemplate)

return deleteCmd
Expand Down
5 changes: 3 additions & 2 deletions pkg/odo/cli/delete/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/redhat-developer/odo/pkg/odo/cmdline"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
"github.com/redhat-developer/odo/pkg/odo/util"
scontext "github.com/redhat-developer/odo/pkg/segment/context"
)

Expand Down Expand Up @@ -123,8 +124,7 @@ func NewCmdNamespaceDelete(name, fullName string) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
return genericclioptions.GenericRun(do, cmd, args)
},
Annotations: map[string]string{"command": "main"},
Aliases: []string{"project"},
Aliases: []string{"project"},
}

namespaceDeleteCmd.Flags().BoolVarP(&do.forceFlag, "force", "f", false, "Delete namespace without prompting")
Expand All @@ -134,5 +134,6 @@ func NewCmdNamespaceDelete(name, fullName string) *cobra.Command {
"Wait until the namespace no longer exists")

clientset.Add(namespaceDeleteCmd, clientset.KUBERNETES, clientset.PROJECT)
util.SetCommandGroup(namespaceDeleteCmd, util.MainGroup)
return namespaceDeleteCmd
}
3 changes: 2 additions & 1 deletion pkg/odo/cli/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
odocontext "github.com/redhat-developer/odo/pkg/odo/context"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
"github.com/redhat-developer/odo/pkg/odo/util"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
scontext "github.com/redhat-developer/odo/pkg/segment/context"
"github.com/redhat-developer/odo/pkg/version"
Expand Down Expand Up @@ -106,7 +107,7 @@ func NewCmdDeploy(name, fullName string) *cobra.Command {
clientset.Add(deployCmd, clientset.INIT, clientset.DEPLOY, clientset.FILESYSTEM)

// Add a defined annotation in order to appear in the help menu
deployCmd.Annotations["command"] = "main"
util.SetCommandGroup(deployCmd, util.MainGroup)
deployCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
commonflags.UseVariablesFlags(deployCmd)
return deployCmd
Expand Down
2 changes: 1 addition & 1 deletion pkg/odo/cli/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func NewCmdDescribe(name, fullName string) *cobra.Command {
componentCmd := NewCmdComponent(ComponentRecommendedCommandName, util.GetFullName(fullName, ComponentRecommendedCommandName))
bindingCmd := NewCmdBinding(BindingRecommendedCommandName, util.GetFullName(fullName, BindingRecommendedCommandName))
describeCmd.AddCommand(componentCmd, bindingCmd)
describeCmd.Annotations = map[string]string{"command": "management"}
util.SetCommandGroup(describeCmd, util.ManagementGroup)
describeCmd.SetUsageTemplate(util.CmdUsageTemplate)

return describeCmd
Expand Down
2 changes: 1 addition & 1 deletion pkg/odo/cli/dev/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ It forwards endpoints with any exposure values ('public', 'internal' or 'none')
clientset.WATCH,
)
// Add a defined annotation in order to appear in the help menu
devCmd.Annotations["command"] = "main"
odoutil.SetCommandGroup(devCmd, odoutil.MainGroup)
devCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
commonflags.UseVariablesFlags(devCmd)
commonflags.UseRunOnFlag(devCmd)
Expand Down
3 changes: 2 additions & 1 deletion pkg/odo/cli/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
odocontext "github.com/redhat-developer/odo/pkg/odo/context"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
"github.com/redhat-developer/odo/pkg/odo/util"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
scontext "github.com/redhat-developer/odo/pkg/segment/context"
"github.com/redhat-developer/odo/pkg/version"
Expand Down Expand Up @@ -271,7 +272,7 @@ func NewCmdInit(name, fullName string) *cobra.Command {

commonflags.UseOutputFlag(initCmd)
// Add a defined annotation in order to appear in the help menu
initCmd.Annotations["command"] = "main"
util.SetCommandGroup(initCmd, util.MainGroup)
initCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
return initCmd
}
13 changes: 7 additions & 6 deletions pkg/odo/cli/list/component/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/redhat-developer/odo/pkg/odo/cli/feature"
"github.com/redhat-developer/odo/pkg/odo/cli/ui"
"github.com/redhat-developer/odo/pkg/odo/commonflags"
"github.com/redhat-developer/odo/pkg/odo/util"

"github.com/redhat-developer/odo/pkg/component"

Expand Down Expand Up @@ -141,12 +142,11 @@ func NewCmdComponentList(ctx context.Context, name, fullName string) *cobra.Comm
o := NewListOptions()

var listCmd = &cobra.Command{
Use: name,
Short: "List all components in the current namespace",
Long: "List all components in the current namespace.",
Example: fmt.Sprintf(listExample, fullName),
Args: genericclioptions.NoArgsAndSilenceJSON,
Annotations: map[string]string{"command": "management"},
Use: name,
Short: "List all components in the current namespace",
Long: "List all components in the current namespace.",
Example: fmt.Sprintf(listExample, fullName),
Args: genericclioptions.NoArgsAndSilenceJSON,
RunE: func(cmd *cobra.Command, args []string) error {
return genericclioptions.GenericRun(o, cmd, args)
},
Expand All @@ -158,6 +158,7 @@ func NewCmdComponentList(ctx context.Context, name, fullName string) *cobra.Comm
}
listCmd.Flags().StringVar(&o.namespaceFlag, "namespace", "", "Namespace for odo to scan for components")

util.SetCommandGroup(listCmd, util.ManagementGroup)
commonflags.UseOutputFlag(listCmd)
commonflags.UseRunOnFlag(listCmd)

Expand Down
13 changes: 7 additions & 6 deletions pkg/odo/cli/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
odocontext "github.com/redhat-developer/odo/pkg/odo/context"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
"github.com/redhat-developer/odo/pkg/odo/util"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"

dfutil "github.com/devfile/library/pkg/util"
Expand Down Expand Up @@ -161,12 +162,11 @@ func NewCmdList(ctx context.Context, name, fullName string) *cobra.Command {
o := NewListOptions()

var listCmd = &cobra.Command{
Use: name,
Short: "List all components in the current namespace",
Long: "List all components in the current namespace.",
Example: fmt.Sprintf(listExample, fullName),
Args: genericclioptions.NoArgsAndSilenceJSON,
Annotations: map[string]string{"command": "management"},
Use: name,
Short: "List all components in the current namespace",
Long: "List all components in the current namespace.",
Example: fmt.Sprintf(listExample, fullName),
Args: genericclioptions.NoArgsAndSilenceJSON,
RunE: func(cmd *cobra.Command, args []string) error {
return genericclioptions.GenericRun(o, cmd, args)
},
Expand All @@ -182,6 +182,7 @@ func NewCmdList(ctx context.Context, name, fullName string) *cobra.Command {
servicesCmd := services.NewCmdServicesList(services.RecommendedCommandName, odoutil.GetFullName(fullName, services.RecommendedCommandName))
listCmd.AddCommand(namespaceCmd, bindingCmd, componentCmd, servicesCmd)

util.SetCommandGroup(listCmd, util.ManagementGroup)
listCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
listCmd.Flags().StringVar(&o.namespaceFlag, "namespace", "", "Namespace for odo to scan for components")

Expand Down
4 changes: 2 additions & 2 deletions pkg/odo/cli/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/redhat-developer/odo/pkg/odo/cmdline"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
"github.com/redhat-developer/odo/pkg/odo/util"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/templates"
Expand Down Expand Up @@ -105,8 +106,7 @@ func NewCmdLogin(name, fullName string) *cobra.Command {
},
}

// Add a defined annotation in order to appear in the help menu
loginCmd.Annotations = map[string]string{"command": "openshift"}
util.SetCommandGroup(loginCmd, util.OpenshiftGroup)
loginCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
loginCmd.Flags().StringVarP(&o.userNameFlag, "username", "u", "", "username, will prompt if not provided")
loginCmd.Flags().StringVarP(&o.passwordFlag, "password", "p", "", "password, will prompt if not provided")
Expand Down
Loading

0 comments on commit e96f123

Please sign in to comment.