Skip to content

Commit

Permalink
Remove devfile push cmd (#2598)
Browse files Browse the repository at this point in the history
* Remove push-devfile command, Add --devfile flag in experimental mode

* Check if --devfile has been explicitly set on cli

* Check presence of devfile to enable devfile feature in experimental mode

* Moving PushRecommendedCommandName to its original place
  • Loading branch information
kanchwala-yusuf authored Feb 19, 2020
1 parent 265c965 commit df98d82
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 67 deletions.
8 changes: 0 additions & 8 deletions pkg/odo/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/openshift/odo/pkg/odo/cli/version"
"github.com/openshift/odo/pkg/odo/util"
odoutil "github.com/openshift/odo/pkg/odo/util"
"github.com/openshift/odo/pkg/odo/util/experimental"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -175,13 +174,6 @@ func NewCmdOdo(name, fullName string) *cobra.Command {
debug.NewCmdDebug(debug.RecommendedCommandName, util.GetFullName(fullName, debug.RecommendedCommandName)),
)

// Expose commands in experimental mode, if experimental mode is enabled.
if experimental.IsExperimentalModeEnabled() {
rootCmd.AddCommand(
component.NewCmdPushDevfile(component.PushDevfileRecommendedCommandName, util.GetFullName(fullName, component.PushDevfileRecommendedCommandName)),
)
}

odoutil.VisitCommands(rootCmd, reconfigureCmdWithSubcmd)

return rootCmd
Expand Down
68 changes: 10 additions & 58 deletions pkg/odo/cli/component/devfile.go
Original file line number Diff line number Diff line change
@@ -1,55 +1,28 @@
package component

import (
"fmt"

"github.com/openshift/odo/pkg/devfile"
"github.com/openshift/odo/pkg/odo/cli/project"
"github.com/openshift/odo/pkg/odo/genericclioptions"
"github.com/spf13/cobra"
ktemplates "k8s.io/kubernetes/pkg/kubectl/util/templates"
)

// examples
var pushDevFileExample = ktemplates.Examples(`
Devfile support is an experimental feature which extends the support for the use of Che devfiles in odo
for performing various odo operations.
/*
Devfile support is an experimental feature which extends the support for the
use of Che devfiles in odo for performing various odo operations.
The devfile support progress can be tracked by:
https://github.com/openshift/odo/issues/2467
Please note that this feature is currently under development and the "push-devfile" command has been
temporarily exposed only for experimental purposes, and may/will be removed in future releases.
`)

const PushDevfileRecommendedCommandName = "push-devfile"
Please note that this feature is currently under development and the "--devfile"
flag is exposed only if the experimental mode in odo is enabled.
// PushDevfileOptions encapsulates odo component push-devfile options
type PushDevfileOptions struct {
devfilePath string
*genericclioptions.Context
}

// NewPushDevfileOptions returns new instance of PushDevfileOptions
func NewPushDevfileOptions() *PushDevfileOptions {
return &PushDevfileOptions{}
}

// Complete completes args
func (pdo *PushDevfileOptions) Complete(name string, cmd *cobra.Command, args []string) (err error) {
return nil
}

// Validate validates the parameters
func (pdo *PushDevfileOptions) Validate() (err error) {
return nil
}
The behaviour of this feature is subject to change as development for this
feature progresses.
*/

// Run has the logic to perform the required actions as part of command
func (pdo *PushDevfileOptions) Run() (err error) {
func (po *PushOptions) DevfilePush() (err error) {

// Parse devfile
devObj, err := devfile.Parse(pdo.devfilePath)
devObj, err := devfile.Parse(po.devfilePath)
if err != nil {
return err
}
Expand All @@ -62,24 +35,3 @@ func (pdo *PushDevfileOptions) Run() (err error) {

return nil
}

// NewCmdPushDevfile implements odo push-devfile command
func NewCmdPushDevfile(name, fullName string) *cobra.Command {
o := NewPushDevfileOptions()

var pushDevfileCmd = &cobra.Command{
Use: name,
Short: "Push component using devfile.",
Long: "Push component using devfile.",
Example: fmt.Sprintf(pushDevFileExample, fullName),
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
genericclioptions.GenericRun(o, cmd, args)
},
}

pushDevfileCmd.Flags().StringVar(&o.devfilePath, "devfile", "./devfile.yaml", "Path to a devfile.yaml")
project.AddProjectFlag(pushDevfileCmd)

return pushDevfileCmd
}
30 changes: 29 additions & 1 deletion pkg/odo/cli/component/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/openshift/odo/pkg/log"
"github.com/openshift/odo/pkg/odo/genericclioptions"
"github.com/openshift/odo/pkg/odo/util/completion"
"github.com/openshift/odo/pkg/odo/util/experimental"
"github.com/openshift/odo/pkg/util"
"github.com/pkg/errors"
"github.com/spf13/cobra"

Expand All @@ -32,6 +34,9 @@ const PushRecommendedCommandName = "push"
// PushOptions encapsulates options that push command uses
type PushOptions struct {
*CommonPushOptions

// devfile path
devfilePath string
}

// NewPushOptions returns new instance of PushOptions
Expand All @@ -44,6 +49,12 @@ func NewPushOptions() *PushOptions {

// Complete completes push args
func (po *PushOptions) Complete(name string, cmd *cobra.Command, args []string) (err error) {

// if experimental mode is enabled and devfile is present
if experimental.IsExperimentalModeEnabled() && util.CheckPathExists(po.devfilePath) {
return nil
}

conf, err := config.NewLocalConfigInfo(po.componentContext)
if err != nil {
return errors.Wrap(err, "unable to retrieve configuration information")
Expand Down Expand Up @@ -75,6 +86,11 @@ func (po *PushOptions) Complete(name string, cmd *cobra.Command, args []string)
// Validate validates the push parameters
func (po *PushOptions) Validate() (err error) {

// if experimental flag is set and devfile is present
if experimental.IsExperimentalModeEnabled() && util.CheckPathExists(po.devfilePath) {
return nil
}

log.Info("Validation")

// First off, we check to see if the component exists. This is ran each time we do `odo push`
Expand Down Expand Up @@ -102,7 +118,14 @@ func (po *PushOptions) Validate() (err error) {

// Run has the logic to perform the required actions as part of command
func (po *PushOptions) Run() (err error) {
return po.Push()
// if experimental mode is enabled, use devfile push
if experimental.IsExperimentalModeEnabled() && util.CheckPathExists(po.devfilePath) {
// devfile push
return po.DevfilePush()
} else {
// Legacy odo push
return po.Push()
}
}

// NewCmdPush implements the push odo command
Expand All @@ -127,6 +150,11 @@ func NewCmdPush(name, fullName string) *cobra.Command {
pushCmd.Flags().BoolVar(&po.pushSource, "source", false, "Use source flag to only push latest source on to cluster")
pushCmd.Flags().BoolVarP(&po.forceBuild, "force-build", "f", false, "Use force-build flag to force building the component")

// enable devfile flag if experimental mode is enabled
if experimental.IsExperimentalModeEnabled() {
pushCmd.Flags().StringVar(&po.devfilePath, "devfile", "./devfile.yaml", "Path to a devfile.yaml")
}

pushCmd.SetUsageTemplate(odoutil.CmdUsageTemplate)
completion.RegisterCommandHandler(pushCmd, completion.ComponentNameCompletionHandler)
completion.RegisterCommandFlagHandler(pushCmd, "context", completion.FileCompletionHandler)
Expand Down

0 comments on commit df98d82

Please sign in to comment.