Replace flag text with const (#1391)
This commit is contained in:
@@ -34,10 +34,10 @@ import (
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
|
||||
pkgutil "github.com/fission/fission/pkg/fission-cli/cmd/package/util"
|
||||
spectypes "github.com/fission/fission/pkg/fission-cli/cmd/spec/types"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
@@ -56,27 +56,27 @@ type ApplySubCommand struct {
|
||||
// Apply is *not* transactional -- if the user hits Ctrl-C, or their laptop dies
|
||||
// etc, while doing an apply, they will get a partially applied deployment. However,
|
||||
// they can retry their apply command once they're back online.
|
||||
func Apply(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Apply(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := ApplySubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *ApplySubCommand) do(flags cli.Input) error {
|
||||
return opts.run(flags)
|
||||
func (opts *ApplySubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *ApplySubCommand) run(flags cli.Input) error {
|
||||
specDir := util.GetSpecDir(flags)
|
||||
func (opts *ApplySubCommand) run(input cli.Input) error {
|
||||
specDir := util.GetSpecDir(input)
|
||||
|
||||
deleteResources := flags.Bool("delete")
|
||||
watchResources := flags.Bool("watch")
|
||||
waitForBuild := flags.Bool("wait")
|
||||
deleteResources := input.Bool(flagkey.SpecDelete)
|
||||
watchResources := input.Bool(flagkey.SpecWatch)
|
||||
waitForBuild := input.Bool(flagkey.SpecWait)
|
||||
|
||||
var watcher *fsnotify.Watcher
|
||||
var pbw *packageBuildWatcher
|
||||
@@ -123,7 +123,7 @@ func (opts *ApplySubCommand) run(flags cli.Input) error {
|
||||
}
|
||||
|
||||
// validate
|
||||
err = fr.Validate(flags)
|
||||
err = fr.Validate(input)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error validating specs")
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(Init),
|
||||
}
|
||||
wrapper.SetFlags(initCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDirFlag, flag.SpecNameFlag, flag.SpecDeployIDFlag},
|
||||
Optional: []flag.Flag{flag.SpecDir, flag.SpecName, flag.SpecDeployID},
|
||||
})
|
||||
|
||||
validateCmd := &cobra.Command{
|
||||
@@ -39,7 +39,7 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(Validate),
|
||||
}
|
||||
wrapper.SetFlags(validateCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDirFlag},
|
||||
Optional: []flag.Flag{flag.SpecDir},
|
||||
})
|
||||
|
||||
applyCmd := &cobra.Command{
|
||||
@@ -48,7 +48,7 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(Apply),
|
||||
}
|
||||
wrapper.SetFlags(applyCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDirFlag, flag.SpecDeployIDFlag, flag.SpecWaitFlag},
|
||||
Optional: []flag.Flag{flag.SpecDir, flag.SpecDeployID, flag.SpecWait},
|
||||
})
|
||||
|
||||
destroyCmd := &cobra.Command{
|
||||
@@ -57,7 +57,7 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(Destroy),
|
||||
}
|
||||
wrapper.SetFlags(destroyCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDirFlag},
|
||||
Optional: []flag.Flag{flag.SpecDir},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
|
||||
@@ -29,24 +29,24 @@ type DestroySubCommand struct {
|
||||
}
|
||||
|
||||
// Destroy destroys everything in the spec.
|
||||
func Destroy(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Destroy(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := &DestroySubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *DestroySubCommand) do(flags cli.Input) error {
|
||||
return opts.run(flags)
|
||||
func (opts *DestroySubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *DestroySubCommand) run(flags cli.Input) error {
|
||||
func (opts *DestroySubCommand) run(input cli.Input) error {
|
||||
// get specdir
|
||||
specDir := util.GetSpecDir(flags)
|
||||
specDir := util.GetSpecDir(input)
|
||||
|
||||
// read everything
|
||||
fr, err := ReadSpecs(specDir)
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
"github.com/fission/fission/pkg/controller/client"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
spectypes "github.com/fission/fission/pkg/fission-cli/cmd/spec/types"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
@@ -37,30 +38,30 @@ type InitSubCommand struct {
|
||||
deployConfig *spectypes.DeploymentConfig
|
||||
}
|
||||
|
||||
func Init(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Init(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := InitSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *InitSubCommand) do(flags cli.Input) error {
|
||||
err := opts.complete(flags)
|
||||
func (opts *InitSubCommand) do(input cli.Input) error {
|
||||
err := opts.complete(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return opts.run(flags)
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *InitSubCommand) complete(flags cli.Input) error {
|
||||
func (opts *InitSubCommand) complete(input cli.Input) error {
|
||||
// Figure out spec directory
|
||||
specDir := util.GetSpecDir(flags)
|
||||
specDir := util.GetSpecDir(input)
|
||||
|
||||
name := flags.String("name")
|
||||
name := input.String(flagkey.SpecName)
|
||||
if len(name) == 0 {
|
||||
// come up with a name using the current dir
|
||||
dir, err := filepath.Abs(".")
|
||||
@@ -71,7 +72,7 @@ func (opts *InitSubCommand) complete(flags cli.Input) error {
|
||||
name = util.KubifyName(basename)
|
||||
}
|
||||
|
||||
deployID := flags.String("deployid")
|
||||
deployID := input.String(flagkey.SpecDeployID)
|
||||
if len(deployID) == 0 {
|
||||
deployID = uuid.NewV4().String()
|
||||
}
|
||||
@@ -101,8 +102,8 @@ func (opts *InitSubCommand) complete(flags cli.Input) error {
|
||||
|
||||
// run just initializes an empty spec directory and adds some
|
||||
// sample YAMLs in there that might be useful.
|
||||
func (opts *InitSubCommand) run(flags cli.Input) error {
|
||||
specDir := util.GetSpecDir(flags)
|
||||
func (opts *InitSubCommand) run(input cli.Input) error {
|
||||
specDir := util.GetSpecDir(input)
|
||||
|
||||
// Add a bit of documentation to the spec dir here
|
||||
err := ioutil.WriteFile(filepath.Join(specDir, "README"), []byte(SPEC_README), 0644)
|
||||
|
||||
@@ -246,7 +246,7 @@ func (fr *FissionResources) validateFunctionReference(functions map[string]bool,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fr *FissionResources) Validate(flags cli.Input) error {
|
||||
func (fr *FissionResources) Validate(input cli.Input) error {
|
||||
result := utils.MultiErrorWithFormat()
|
||||
|
||||
// check references: both dangling refs + garbage
|
||||
@@ -348,7 +348,7 @@ func (fr *FissionResources) Validate(flags cli.Input) error {
|
||||
packages[MapKey(pkgMeta)] = true
|
||||
}
|
||||
|
||||
client, err := util.GetServer(flags)
|
||||
client, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -38,32 +38,32 @@ type ValidateSubCommand struct {
|
||||
|
||||
// Validate parses a set of specs and checks for references to
|
||||
// resources that don't exist.
|
||||
func Validate(flags cli.Input) error {
|
||||
c, err := util.GetServer(flags)
|
||||
func Validate(input cli.Input) error {
|
||||
c, err := util.GetServer(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts := &ValidateSubCommand{
|
||||
client: c,
|
||||
}
|
||||
return opts.do(flags)
|
||||
return opts.do(input)
|
||||
}
|
||||
|
||||
func (opts *ValidateSubCommand) do(flags cli.Input) error {
|
||||
return opts.run(flags)
|
||||
func (opts *ValidateSubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *ValidateSubCommand) run(flags cli.Input) error {
|
||||
func (opts *ValidateSubCommand) run(input cli.Input) error {
|
||||
|
||||
// this will error on parse errors and on duplicates
|
||||
specDir := util.GetSpecDir(flags)
|
||||
specDir := util.GetSpecDir(input)
|
||||
fr, err := ReadSpecs(specDir)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error reading specs")
|
||||
}
|
||||
|
||||
// this does the rest of the checks, like dangling refs
|
||||
err = fr.Validate(flags)
|
||||
err = fr.Validate(input)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error validating specs")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user