Skip to content

Commit

Permalink
Merge pull request #2022 from tejal29/use_flagset
Browse files Browse the repository at this point in the history
Add Annotations to command and flags per phase annotation.
  • Loading branch information
balopat authored May 22, 2019
2 parents 6b7a28e + 72f2511 commit ab46e0d
Show file tree
Hide file tree
Showing 11 changed files with 374 additions and 93 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 @@ -45,14 +45,15 @@ var (

// NewCmdBuild describes the CLI command to build artifacts.
func NewCmdBuild(out io.Writer) *cobra.Command {
cmdUse := "build"
return commands.
New(out).
WithDescription("build", "Builds the artifacts").
WithDescription(cmdUse, "Builds the artifacts").
WithFlags(func(f *pflag.FlagSet) {
AddRunDevFlags(f)
f.StringSliceVarP(&opts.TargetImages, "build-image", "b", nil, "Choose which artifacts to build. Artifacts with image names that contain the expression will be built only. Default is to build sources for all artifacts")
f.BoolVarP(&quietFlag, "quiet", "q", false, "Suppress the build output and print image built on success. See --output to format output.")
f.VarP(buildFormatFlag, "output", "o", "Used in conjuction with --quiet flag. "+buildFormatFlag.Usage())
AddFlags(f, cmdUse)
}).
NoArgs(cancelWithCtrlC(context.Background(), doBuild))
}
Expand Down
35 changes: 1 addition & 34 deletions cmd/skaffold/app/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func NewSkaffoldCommand(out, err io.Writer) *cobra.Command {
}
}

SetUpFlags()
rootCmd.SetOutput(out)
rootCmd.AddCommand(NewCmdCompletion(out))
rootCmd.AddCommand(NewCmdVersion(out))
Expand Down Expand Up @@ -155,40 +156,6 @@ func FlagToEnvVarName(f *pflag.Flag) string {
return fmt.Sprintf("SKAFFOLD_%s", strings.Replace(strings.ToUpper(f.Name), "-", "_", -1))
}

func AddRunCommonFlags(f *pflag.FlagSet) {
f.BoolVar(&opts.EnableRPC, "enable-rpc", false, "Enable gRPC for exposing Skaffold events (true by default for `skaffold dev`)")
f.IntVar(&opts.RPCPort, "rpc-port", constants.DefaultRPCPort, "tcp port to expose event API")
f.IntVar(&opts.RPCHTTPPort, "rpc-http-port", constants.DefaultRPCHTTPPort, "tcp port to expose event REST API over HTTP")
f.StringVarP(&opts.ConfigurationFile, "filename", "f", "skaffold.yaml", "Filename or URL to the pipeline file")
f.BoolVar(&opts.Notification, "toot", false, "Emit a terminal beep after the deploy is complete")
f.StringSliceVarP(&opts.Profiles, "profile", "p", nil, "Activate profiles by name")
f.StringVarP(&opts.Namespace, "namespace", "n", "", "Run deployments in the specified namespace")
f.StringVarP(&opts.DefaultRepo, "default-repo", "d", "", "Default repository value (overrides global config)")
f.BoolVar(&opts.NoPrune, "no-prune", false, "Skip removing images and containers built by Skaffold")
f.BoolVar(&opts.NoPruneChildren, "no-prune-children", false, "Skip removing layers reused by Skaffold")
f.StringSliceVar(&opts.InsecureRegistries, "insecure-registry", nil, "Target registries for built images which are not secure")
}

func AddRunDeployFlags(f *pflag.FlagSet) {
f.BoolVar(&opts.Tail, "tail", false, "Stream logs from deployed objects")
f.BoolVar(&opts.Force, "force", false, "Recreate kubernetes resources if necessary for deployment (default: false, warning: might cause downtime!)")
f.StringSliceVarP(&opts.CustomLabels, "label", "l", nil, "Add custom labels to deployed objects. Set multiple times for multiple labels.")
}

func AddRunDevFlags(f *pflag.FlagSet) {
AddRunCommonFlags(f)
f.BoolVar(&opts.SkipTests, "skip-tests", false, "Whether to skip the tests after building")
f.BoolVar(&opts.CacheArtifacts, "cache-artifacts", false, "Set to true to enable caching of artifacts.")
f.StringVarP(&opts.CacheFile, "cache-file", "", "", "Specify the location of the cache file (default $HOME/.skaffold/cache)")
}

func AddDevDebugFlags(f *pflag.FlagSet) {
f.BoolVar(&opts.TailDev, "tail", true, "Stream logs from deployed objects")
f.BoolVar(&opts.Cleanup, "cleanup", true, "Delete deployments after dev mode is interrupted")
f.BoolVar(&opts.PortForward, "port-forward", false, "Port-forward exposed container ports within pods")
f.StringSliceVarP(&opts.CustomLabels, "label", "l", nil, "Add custom labels to deployed objects. Set multiple times for multiple labels")
}

func SetUpLogs(out io.Writer, level string) error {
logrus.SetOutput(out)
lvl, err := logrus.ParseLevel(v)
Expand Down
6 changes: 3 additions & 3 deletions cmd/skaffold/app/cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import (

// NewCmdDebug describes the CLI command to run a pipeline in debug mode.
func NewCmdDebug(out io.Writer) *cobra.Command {
cmdUse := "debug"
return commands.
New(out).
WithLongDescription("debug", "Runs a pipeline file in debug mode", "Similar to `dev`, but configures the pipeline for debugging.").
WithLongDescription(cmdUse, "Runs a pipeline file in debug mode", "Similar to `dev`, but configures the pipeline for debugging.").
WithFlags(func(f *pflag.FlagSet) {
AddRunDevFlags(f)
AddDevDebugFlags(f)
AddFlags(f, cmdUse)
}).
NoArgs(cancelWithCtrlC(context.Background(), doDebug))
}
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 @@ -29,11 +29,12 @@ import (

// NewCmdDelete describes the CLI command to delete deployed resources.
func NewCmdDelete(out io.Writer) *cobra.Command {
cmdUse := "delete"
return commands.
New(out).
WithDescription("delete", "Delete the deployed resources").
WithDescription(cmdUse, "Delete the deployed resources").
WithFlags(func(f *pflag.FlagSet) {
AddRunCommonFlags(f)
AddFlags(f, cmdUse)
}).
NoArgs(cancelWithCtrlC(context.Background(), doDelete))
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/skaffold/app/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ var (

// NewCmdDeploy describes the CLI command to deploy artifacts.
func NewCmdDeploy(out io.Writer) *cobra.Command {
cmdUse := "deploy"
return commands.
New(out).
WithDescription("deploy", "Deploys the artifacts").
WithDescription(cmdUse, "Deploys the artifacts").
WithFlags(func(f *pflag.FlagSet) {
f.VarP(&preBuiltImages, "images", "i", "A list of pre-built images to deploy")
f.VarP(&buildOutputFile, "build-artifacts", "a", `Filepath containing build output.
E.g. build.out created by running skaffold build --quiet {{json .}} > build.out`)
AddRunDevFlags(f)
AddRunDeployFlags(f)
AddFlags(f, cmdUse)
}).
NoArgs(cancelWithCtrlC(context.Background(), doDeploy))
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/skaffold/app/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ import (

// NewCmdDev describes the CLI command to run a pipeline in development mode.
func NewCmdDev(out io.Writer) *cobra.Command {
cmdUse := "dev"
return commands.
New(out).
WithDescription("dev", "Runs a pipeline file in development mode").
WithDescription(cmdUse, "Runs a pipeline file in development mode").
WithFlags(func(f *pflag.FlagSet) {
f.StringVar(&opts.Trigger, "trigger", "polling", "How are changes detected? (polling, manual or notify)")
f.StringSliceVarP(&opts.TargetImages, "watch-image", "w", nil, "Choose which artifacts to watch. Artifacts with image names that contain the expression will be watched only. Default is to watch sources for all artifacts")
f.IntVarP(&opts.WatchPollInterval, "watch-poll-interval", "i", 1000, "Interval (in ms) between two checks for file changes")
AddRunDevFlags(f)
AddDevDebugFlags(f)
AddFlags(f, cmdUse)
}).
NoArgs(cancelWithCtrlC(context.Background(), doDev))
}
Expand Down
Loading

0 comments on commit ab46e0d

Please sign in to comment.