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:
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
Copyright 2021 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 util
|
||||
|
||||
// fission-cli options
|
||||
const (
|
||||
SPEC_IGNORE_FILE = ".specignore"
|
||||
)
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user