Skip to content

Commit

Permalink
Move command names to code constants
Browse files Browse the repository at this point in the history
Signed-off-by: Cornelius Weig <cornelius.weig@tngtech.com>
  • Loading branch information
Cornelius Weig committed Mar 14, 2019
1 parent 8f77212 commit 9fafaab
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 37 deletions.
5 changes: 3 additions & 2 deletions cmd/skaffold/app/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/flags"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -36,11 +37,11 @@ var (
// NewCmdBuild describes the CLI command to build artifacts.
func NewCmdBuild(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "build",
Use: constants.CommandBuild,
Short: "Builds the artifacts",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
opts.Command = "build"
opts.Command = constants.CommandBuild
return runBuild(out)
},
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/skaffold/app/cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"io"
"os"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -219,7 +220,7 @@ _complete skaffold 2>/dev/null
)

var completionCmd = &cobra.Command{
Use: "completion SHELL",
Use: constants.CommandCompletion + " SHELL",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return fmt.Errorf("requires 1 arg, found %d", len(args))
Expand Down
3 changes: 2 additions & 1 deletion cmd/skaffold/app/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import (
"io"

"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/cmd/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/spf13/cobra"
)

func NewCmdConfig(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "config",
Use: constants.CommandConfig,
Short: "A set of commands for interacting with the Skaffold config.",
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/skaffold/app/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ import (
"context"
"io"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

// NewCmdDelete describes the CLI command to delete deployed resources.
func NewCmdDelete(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "delete",
Use: constants.CommandDelete,
Short: "Delete the deployed resources",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
opts.Command = "delete"
opts.Command = constants.CommandDelete
return delete(out)
},
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/skaffold/app/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ package cmd
import (
"io"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/spf13/cobra"
)

// NewCmdDeploy describes the CLI command to deploy artifacts.
func NewCmdDeploy(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "deploy",
Use: constants.CommandDeploy,
Short: "Deploys the artifacts",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
// Same actions as `skaffold run`, but with pre-built images.
opts.Command = "deploy"
opts.Command = constants.CommandDeploy
return run(out)
},
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/skaffold/app/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/pkg/errors"
"github.com/rivo/tview"
Expand All @@ -33,11 +34,11 @@ import (
// NewCmdDev describes the CLI command to run a pipeline in development mode.
func NewCmdDev(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "dev",
Use: constants.CommandDev,
Short: "Runs a pipeline file in development mode",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
opts.Command = "dev"
opts.Command = constants.CommandDev
return dev(out, opts.ExperimentalGUI)
},
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/skaffold/app/cmd/diagnose.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/version"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/watch"

"github.com/pkg/errors"
"github.com/spf13/cobra"
yaml "gopkg.in/yaml.v2"
Expand All @@ -38,7 +38,7 @@ import (
// NewCmdDiagnose describes the CLI command to diagnose skaffold.
func NewCmdDiagnose(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "diagnose",
Use: constants.CommandDiagnose,
Short: "Run a diagnostic on Skaffold",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
3 changes: 2 additions & 1 deletion cmd/skaffold/app/cmd/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io/ioutil"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/pkg/errors"
Expand All @@ -30,7 +31,7 @@ import (

func NewCmdFix(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "fix",
Use: constants.CommandFix,
Short: "Converts old Skaffold config to newest schema version",
RunE: func(cmd *cobra.Command, args []string) error {
return runFix(out, opts.ConfigurationFile, overwrite)
Expand Down
3 changes: 2 additions & 1 deletion cmd/skaffold/app/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package cmd
import (
"io"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/initializer"
"github.com/spf13/cobra"
)
Expand All @@ -34,7 +35,7 @@ var (
// NewCmdInit describes the CLI command to generate a Skaffold configuration.
func NewCmdInit(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "init",
Use: constants.CommandInit,
Short: "Automatically generate Skaffold configuration for deploying an application",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
5 changes: 3 additions & 2 deletions cmd/skaffold/app/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ import (
"io"

"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/tips"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

// NewCmdRun describes the CLI command to run a pipeline.
func NewCmdRun(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "run",
Use: constants.CommandRun,
Short: "Runs a pipeline file",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
opts.Command = "run"
opts.Command = constants.CommandRun
err := run(out)
if err == nil {
tips.PrintForRun(out, opts)
Expand Down
3 changes: 2 additions & 1 deletion cmd/skaffold/app/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"io"

"github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/flags"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/version"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -29,7 +30,7 @@ var versionFlag = flags.NewTemplateFlag("{{.Version}}\n", version.Info{})

func NewCmdVersion(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "version",
Use: constants.CommandVersion,
Short: "Print the version information",
RunE: func(cmd *cobra.Command, args []string) error {
return RunVersion(out, cmd)
Expand Down
18 changes: 10 additions & 8 deletions integration/skaffold/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"os/exec"
"strings"
"testing"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
)

// RunBuilder is used to build a command line to run `skaffold`.
Expand All @@ -38,42 +40,42 @@ type RunBuilder struct {

// Dev runs `skaffold dev` with the given arguments.
func Dev(args ...string) *RunBuilder {
return &RunBuilder{command: "dev", args: args}
return &RunBuilder{command: constants.CommandDev, args: args}
}

// Fix runs `skaffold fix` with the given arguments.
func Fix(args ...string) *RunBuilder {
return &RunBuilder{command: "fix", args: args}
return &RunBuilder{command: constants.CommandFix, args: args}
}

// Build runs `skaffold build` with the given arguments.
func Build(args ...string) *RunBuilder {
return &RunBuilder{command: "build", args: args}
return &RunBuilder{command: constants.CommandBuild, args: args}
}

// Deploy runs `skaffold deploy` with the given arguments.
func Deploy(args ...string) *RunBuilder {
return &RunBuilder{command: "deploy", args: args}
return &RunBuilder{command: constants.CommandDeploy, args: args}
}

// Run runs `skaffold run` with the given arguments.
func Run(args ...string) *RunBuilder {
return &RunBuilder{command: "run", args: args}
return &RunBuilder{command: constants.CommandRun, args: args}
}

// Delete runs `skaffold delete` with the given arguments.
func Delete(args ...string) *RunBuilder {
return &RunBuilder{command: "delete", args: args}
return &RunBuilder{command: constants.CommandDelete, args: args}
}

// Config runs `skaffold config` with the given arguments.
func Config(args ...string) *RunBuilder {
return &RunBuilder{command: "config", args: args}
return &RunBuilder{command: constants.CommandConfig, args: args}
}

// Init runs `skaffold init` with the given arguments.
func Init(args ...string) *RunBuilder {
return &RunBuilder{command: "init", args: args}
return &RunBuilder{command: constants.CommandInit, args: args}
}

// InDir sets the directory in which skaffold is running.
Expand Down
13 changes: 13 additions & 0 deletions pkg/skaffold/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ const (

DefaultSkaffoldDir = ".skaffold"
DefaultCacheFile = "cache"

CommandBuild = "build"
CommandConfig = "config"
CommandDelete = "delete"
CommandDeploy = "deploy"
CommandDev = "dev"
CommandFix = "fix"
CommandInit = "init"
CommandRun = "run"
CommandDiagnose = "diagnose"
CommandCompletion = "completion"
CommandVersion = "version"

// A regex matching valid repository names (https://github.com/docker/distribution/blob/master/reference/reference.go)
RepositoryComponentRegex string = `^[a-z\d]+(?:(?:[_.]|__|-+)[a-z\d]+)*$`

Expand Down
3 changes: 2 additions & 1 deletion pkg/skaffold/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build/tag"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/deploy"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes"
Expand Down Expand Up @@ -100,7 +101,7 @@ func NewForConfig(opts *config.SkaffoldOptions, cfg *latest.SkaffoldPipeline) (*
return nil, errors.Wrap(err, "parsing test config")
}

forceDeploy := opts.Command == "dev" || opts.ForceDeploy
forceDeploy := opts.Command == constants.CommandDev || opts.ForceDeploy
deployer, err := getDeployer(&cfg.Deploy, kubeContext, opts.Namespace, forceDeploy, defaultRepo)
if err != nil {
return nil, errors.Wrap(err, "parsing deploy config")
Expand Down
22 changes: 11 additions & 11 deletions pkg/skaffold/schema/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func TestActivatedProfiles(t *testing.T) {
{
description: "Selected on the command line",
opts: &cfg.SkaffoldOptions{
Command: "dev",
Command: constants.CommandDev,
Profiles: []string{"activated", "also-activated"},
},
profiles: []latest.Profile{
Expand All @@ -374,12 +374,12 @@ func TestActivatedProfiles(t *testing.T) {
}, {
description: "Auto-activated by command",
opts: &cfg.SkaffoldOptions{
Command: "dev",
Command: constants.CommandDev,
},
profiles: []latest.Profile{
{Name: "run-profile", Activation: []latest.Activation{{Command: "run"}}},
{Name: "dev-profile", Activation: []latest.Activation{{Command: "dev"}}},
{Name: "non-run-profile", Activation: []latest.Activation{{Command: "!run"}}},
{Name: "run-profile", Activation: []latest.Activation{{Command: constants.CommandRun}}},
{Name: "dev-profile", Activation: []latest.Activation{{Command: constants.CommandDev}}},
{Name: "non-run-profile", Activation: []latest.Activation{{Command: "!" + constants.CommandRun}}},
},
expected: []string{"dev-profile", "non-run-profile"},
}, {
Expand Down Expand Up @@ -410,36 +410,36 @@ func TestActivatedProfiles(t *testing.T) {
}, {
description: "AND between activation criteria",
opts: &cfg.SkaffoldOptions{
Command: "dev",
Command: constants.CommandDev,
},
profiles: []latest.Profile{
{
Name: "activated", Activation: []latest.Activation{{
Env: "KEY=VALUE",
KubeContext: "prod-context",
Command: "dev",
Command: constants.CommandDev,
}},
},
{
Name: "not-activated", Activation: []latest.Activation{{
Env: "KEY=VALUE",
KubeContext: "prod-context",
Command: "build",
Command: constants.CommandBuild,
}},
},
},
expected: []string{"activated"},
}, {
description: "OR between activations",
opts: &cfg.SkaffoldOptions{
Command: "dev",
Command: constants.CommandDev,
},
profiles: []latest.Profile{
{
Name: "activated", Activation: []latest.Activation{{
Command: "run",
Command: constants.CommandRun,
}, {
Command: "dev",
Command: constants.CommandDev,
}},
},
},
Expand Down

0 comments on commit 9fafaab

Please sign in to comment.