Migrate from urfave/cli to cobra (#1385)
This commit is contained in:
@@ -37,7 +37,7 @@ import (
|
||||
|
||||
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/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
@@ -430,7 +430,7 @@ func localArchiveFromSpec(specDir string, aus *spectypes.ArchiveUploadSpec) (*fv
|
||||
absGlob := rootDir + "/" + relativeGlob
|
||||
f, err := filepath.Glob(absGlob)
|
||||
if err != nil {
|
||||
consolemsg.Info(fmt.Sprintf("Invalid glob in archive %v: %v", aus.Name, relativeGlob))
|
||||
console.Info(fmt.Sprintf("Invalid glob in archive %v: %v", aus.Name, relativeGlob))
|
||||
return nil, err
|
||||
}
|
||||
files = append(files, f...)
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
Copyright 2019 The Fission Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package spec
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
wrapper "github.com/fission/fission/pkg/fission-cli/cliwrapper/driver/cobra"
|
||||
"github.com/fission/fission/pkg/fission-cli/flag"
|
||||
)
|
||||
|
||||
func Commands() *cobra.Command {
|
||||
initCmd := &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "Create an initial declarative application specification",
|
||||
RunE: wrapper.Wrapper(Init),
|
||||
}
|
||||
wrapper.SetFlags(initCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDirFlag, flag.SpecNameFlag, flag.SpecDeployIDFlag},
|
||||
})
|
||||
|
||||
validateCmd := &cobra.Command{
|
||||
Use: "validate",
|
||||
Short: "Validate declarative application specification",
|
||||
RunE: wrapper.Wrapper(Validate),
|
||||
}
|
||||
wrapper.SetFlags(validateCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDirFlag},
|
||||
})
|
||||
|
||||
applyCmd := &cobra.Command{
|
||||
Use: "apply",
|
||||
Short: "Create, update, or delete resources from application specification",
|
||||
RunE: wrapper.Wrapper(Apply),
|
||||
}
|
||||
wrapper.SetFlags(applyCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDirFlag, flag.SpecDeployIDFlag, flag.SpecWaitFlag},
|
||||
})
|
||||
|
||||
destroyCmd := &cobra.Command{
|
||||
Use: "destroy",
|
||||
Short: "Delete an environment",
|
||||
RunE: wrapper.Wrapper(Destroy),
|
||||
}
|
||||
wrapper.SetFlags(destroyCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.SpecDirFlag},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
Use: "spec",
|
||||
Aliases: []string{"specs"},
|
||||
Short: "Manage a declarative application specification",
|
||||
}
|
||||
|
||||
command.AddCommand(initCmd, validateCmd, applyCmd, destroyCmd)
|
||||
|
||||
return command
|
||||
}
|
||||
@@ -32,10 +32,11 @@ import (
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd/spec/types"
|
||||
"github.com/fission/fission/pkg/fission-cli/consolemsg"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
"github.com/fission/fission/pkg/generator/encoder"
|
||||
v1generator "github.com/fission/fission/pkg/generator/v1"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
)
|
||||
|
||||
var specDefaultEncoder = encoder.DefaultYAMLEncoder()
|
||||
@@ -246,7 +247,7 @@ func (fr *FissionResources) validateFunctionReference(functions map[string]bool,
|
||||
}
|
||||
|
||||
func (fr *FissionResources) Validate(flags cli.Input) error {
|
||||
result := &multierror.Error{}
|
||||
result := utils.MultiErrorWithFormat()
|
||||
|
||||
// check references: both dangling refs + garbage
|
||||
// packages -> archives
|
||||
@@ -357,7 +358,7 @@ func (fr *FissionResources) Validate(flags cli.Input) error {
|
||||
Namespace: cm.Namespace,
|
||||
})
|
||||
if k8serrors.IsNotFound(err) {
|
||||
consolemsg.Warn(fmt.Sprintf("Configmap %s is referred in the spec but not present in the cluster", cm.Name))
|
||||
console.Warn(fmt.Sprintf("Configmap %s is referred in the spec but not present in the cluster", cm.Name))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,7 +368,7 @@ func (fr *FissionResources) Validate(flags cli.Input) error {
|
||||
Namespace: s.Namespace,
|
||||
})
|
||||
if k8serrors.IsNotFound(err) {
|
||||
consolemsg.Warn(fmt.Sprintf("Secret %s is referred in the spec but not present in the cluster", s.Name))
|
||||
console.Warn(fmt.Sprintf("Secret %s is referred in the spec but not present in the cluster", s.Name))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -395,7 +396,7 @@ func (fr *FissionResources) Validate(flags cli.Input) error {
|
||||
}
|
||||
|
||||
if len(t.Spec.Host) > 0 {
|
||||
consolemsg.Warn(fmt.Sprintf("Host in HTTPTrigger spec.Host is now marked as deprecated, see 'help' for details"))
|
||||
console.Warn(fmt.Sprintf("Host in HTTPTrigger spec.Host is now marked as deprecated, see 'help' for details"))
|
||||
}
|
||||
|
||||
result = multierror.Append(result, t.Validate())
|
||||
@@ -430,25 +431,25 @@ func (fr *FissionResources) Validate(flags cli.Input) error {
|
||||
for _, e := range fr.Environments {
|
||||
environments[fmt.Sprintf("%s:%s", e.Metadata.Name, e.Metadata.Namespace)] = struct{}{}
|
||||
if ((e.Spec.Runtime.Container != nil) && (e.Spec.Runtime.PodSpec != nil)) || ((e.Spec.Builder.Container != nil) && (e.Spec.Builder.PodSpec != nil)) {
|
||||
consolemsg.Warn("You have provided both - container spec and pod spec and while merging the pod spec will take precedence.")
|
||||
console.Warn("You have provided both - container spec and pod spec and while merging the pod spec will take precedence.")
|
||||
}
|
||||
// Unlike CLI can change the environment version silently,
|
||||
// we have to warn the user to modify spec file when this takes place.
|
||||
if e.Spec.Version < 3 && e.Spec.Poolsize != 0 {
|
||||
consolemsg.Warn("Poolsize can only be configured when environment version equals to 3, default poolsize 3 will be used for creating environment pool.")
|
||||
console.Warn("Poolsize can only be configured when environment version equals to 3, default poolsize 3 will be used for creating environment pool.")
|
||||
}
|
||||
}
|
||||
|
||||
for _, f := range fr.Functions {
|
||||
if _, ok := environments[fmt.Sprintf("%s:%s", f.Spec.Environment.Name, f.Spec.Environment.Namespace)]; !ok {
|
||||
consolemsg.Warn(fmt.Sprintf("Environment %s is referenced in function %s but not declared in specs", f.Spec.Environment.Name, f.Metadata.Name))
|
||||
console.Warn(fmt.Sprintf("Environment %s is referenced in function %s but not declared in specs", f.Spec.Environment.Name, f.Metadata.Name))
|
||||
}
|
||||
strategy := f.Spec.InvokeStrategy.ExecutionStrategy
|
||||
if strategy.ExecutorType == fv1.ExecutorTypeNewdeploy && strategy.SpecializationTimeout < fv1.DefaultSpecializationTimeOut {
|
||||
consolemsg.Warn(fmt.Sprintf("SpecializationTimeout in function spec.InvokeStrategy.ExecutionStrategy should be a value equal to or greater than %v", fv1.DefaultSpecializationTimeOut))
|
||||
console.Warn(fmt.Sprintf("SpecializationTimeout in function spec.InvokeStrategy.ExecutionStrategy should be a value equal to or greater than %v", fv1.DefaultSpecializationTimeOut))
|
||||
}
|
||||
if f.Spec.FunctionTimeout <= 0 {
|
||||
consolemsg.Warn(fmt.Sprintf("FunctionTimeout in function spec should be a field which should have a value greater than 0"))
|
||||
console.Warn(fmt.Sprintf("FunctionTimeout in function spec should be a field which should have a value greater than 0"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -577,7 +578,7 @@ func (fr *FissionResources) ParseYaml(b []byte, loc *Location) error {
|
||||
default:
|
||||
// no need to error out just because there's some extra files around;
|
||||
// also good for compatibility.
|
||||
consolemsg.Warn(fmt.Sprintf("Ignoring unknown type %v in %v", tm.Kind, loc))
|
||||
console.Warn(fmt.Sprintf("Ignoring unknown type %v in %v", tm.Kind, loc))
|
||||
}
|
||||
|
||||
// add to source map, check for duplicates
|
||||
|
||||
Reference in New Issue
Block a user