feature: Added '--specignore' option to pass file containing specs to be ignored for fission spec commands (#2239)

- New flag `--specignore` has been added for command fission spec [list | validate | apply | destroy]
- This flag is optional.
- The default spec ignore file name is `.specignore`, if the flag is not used
- The spec ignore file existence will be checked in the `--specdir` path
- If spec ignore file is passed to the flag, with a name other than .specignore and if it does not exist in the `--specdir` path then an error will be returned.
- `--specdir` will be the root path against which the patterns will be evaluated
- The behaviour of the spec ignore file will be similar to .gitignore (only for yml and yaml files). For reference: http://git-scm.com/docs/gitignore
This commit is contained in:
Pradeep Lakshmi Narasimha
2021-10-29 13:26:42 +05:30
committed by GitHub
parent 8fb311b739
commit a5fb5b9901
19 changed files with 103 additions and 24 deletions
+29 -1
View File
@@ -25,7 +25,7 @@ import (
"strconv"
"strings"
"github.com/fission/fission/pkg/controller/client/rest"
ignore "github.com/sabhiram/go-gitignore"
"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
@@ -38,6 +38,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
"github.com/fission/fission/pkg/controller/client"
"github.com/fission/fission/pkg/controller/client/rest"
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
"github.com/fission/fission/pkg/fission-cli/console"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
@@ -317,6 +318,33 @@ func GetSpecDir(input cli.Input) string {
return specDir
}
func GetSpecIgnore(input cli.Input) string {
specIgnoreFile := input.String(flagkey.SpecIgnore)
if len(specIgnoreFile) == 0 {
specIgnoreFile = SPEC_IGNORE_FILE
}
return specIgnoreFile
}
// GetSpecIgnoreParser reads the specignore file and returns the ignore.IgnoreParser
// if the specignore file does not exist it returns empty ignore.IgnoreParser
func GetSpecIgnoreParser(specDir, specIgnore string) (ignore.IgnoreParser, error) {
specIgnorePath := filepath.Join(specDir, specIgnore)
// check for existence of spec ignore file
if _, err := os.Stat(specIgnorePath); errors.Is(err, os.ErrNotExist) {
// return error if it's custom spec ignore file
if specIgnore != SPEC_IGNORE_FILE {
return nil, errors.Errorf("Spec ignore file '%s' doesn't exist. "+
"Please check the file path: '%s'", specIgnore, specIgnorePath)
}
return ignore.CompileIgnoreLines(), nil
}
return ignore.CompileIgnoreFile(specIgnorePath)
}
func GetValidationFlag(input cli.Input) bool {
validationFlag := input.String(flagkey.SpecValidate)
// if flag has not been set, we return true to turn on validation by default