diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 65c41af2..6d01404b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ on: name: Test jobs: - test: + test-unit: strategy: matrix: platform: [ubuntu-latest, macos-latest] @@ -20,39 +20,36 @@ jobs: if: runner.os == 'macOS' run: brew install bash - name: Setup go - uses: actions/setup-go@v1 + uses: actions/setup-go@v2 with: - go-version: 1.17.x + go-version: 1.18.x - name: Checkout code uses: actions/checkout@v2 - name: Test unit env: LETS_CONFIG_DIR: .. run: go test ./... -v + + test-bats: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install Lets + uses: lets-cli/lets-action@v1.1 + with: + version: latest - name: Test bats - env: - NO_COLOR: 1 - run: | - git clone git://github.com/bats-core/bats-core - git clone git://github.com/bats-core/bats-support.git bats-core/bats-support - git clone git://github.com/bats-core/bats-assert.git bats-core/bats-assert - cd bats-core - ./install.sh ../ - cd ../ - PATH=${PATH}:$(pwd) - go build -o lets *.go - BATS_UTILS_PATH=./bats-core ./bin/bats tests + run: lets test-bats lint: runs-on: ubuntu-latest steps: - - name: Setup go - uses: actions/setup-go@v1 - with: - go-version: 1.17.x - - name: Checkout code + - name: Checkout uses: actions/checkout@v2 - - name: Lint - run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./bin v1.37.0 - ./bin/golangci-lint run -v -c .golangci.yaml + - name: Install Lets + uses: lets-cli/lets-action@v1.1 + with: + version: latest + - name: Run lint + run: lets lint diff --git a/.golangci.yaml b/.golangci.yaml index 3a125ead..70c53372 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,9 +1,12 @@ run: tests: false + go: 1.18 linters: enable-all: true disable: + - typecheck + - containedctx - gochecknoglobals - goimports - funlen @@ -19,6 +22,7 @@ linters: - cyclop - gocyclo - gocognit + - tagliatelle linters-settings: gomnd: @@ -27,9 +31,14 @@ linters-settings: checks: case,condition,return lll: line-length: 120 + varnamelen: + min-name-length: 2 issues: exclude-rules: - path: _test\.go linters: - - gomnd \ No newline at end of file + - gomnd + - path: set\.go + linters: + - typecheck \ No newline at end of file diff --git a/build.yaml b/build.yaml index 67b3314d..561b3084 100644 --- a/build.yaml +++ b/build.yaml @@ -8,4 +8,4 @@ commands: build-lint-image: description: Build lets lint docker image - cmd: docker build -t lets-lint -f docker/Dockerfile.lint . + cmd: docker build -t lets-lint -f docker/lint.Dockerfile . diff --git a/checksum/checksum.go b/checksum/checksum.go index 13f93298..31354ddf 100644 --- a/checksum/checksum.go +++ b/checksum/checksum.go @@ -27,7 +27,7 @@ var checksumCache = make(map[string][]byte) // // return sorted list of files read by glob patterns. func readFilesFromPatterns(workDir string, patterns []string) ([]string, error) { - filesSet := set.NewStringSet() + filesSet := set.NewSet[string]() for _, pattern := range patterns { absPatternPath := pattern @@ -40,7 +40,7 @@ func readFilesFromPatterns(workDir string, patterns []string) ([]string, error) return []string{}, fmt.Errorf("can not read file to calculate checksum: %w", err) } - filesSet.AddMany(matches) + filesSet.Add(matches...) } // sort files list files := filesSet.ToList() diff --git a/cmd/subcommand.go b/cmd/subcommand.go index dd715a06..86fc784c 100644 --- a/cmd/subcommand.go +++ b/cmd/subcommand.go @@ -52,13 +52,11 @@ func newCmdGeneric(command config.Command, conf *config.Config, out io.Writer) * 1, ) - commandToRun := command if command.Ref != "" { - refCmd := command - commandToRun = conf.Commands[refCmd.Ref].FromRef(refCmd, conf) + command = conf.Commands[command.Ref].FromRef(command) } - return runner.NewRunner(&commandToRun, conf, out).Execute(cmd.Context()) + return runner.NewRunner(&command, conf, out).Execute(cmd.Context()) }, // we use docopt to parse flags on our own, so any flag is valid flag here FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}, diff --git a/config/config/command.go b/config/config/command.go index 4d163ecb..620e0d20 100644 --- a/config/config/command.go +++ b/config/config/command.go @@ -4,8 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "os" - "strings" "github.com/lets-cli/lets/checksum" ) @@ -59,7 +57,7 @@ type Command struct { // ref is basically a command name to use with predefined args, env Ref string // can be specified only with ref - RefArgs string + RefArgs []string } // NewCommand creates new command struct. @@ -78,20 +76,13 @@ func (cmd Command) WithArgs(args []string) Command { return newCmd } -func (cmd Command) FromRef(refCommand Command, cfg *Config) Command { +func (cmd Command) FromRef(refCommand Command) Command { newCmd := cmd - // we have to expand env here on our own, since this args not came from users tty, and not expanded before lets - refArgsRaw := os.Expand(refCommand.RefArgs, func(key string) string { - return cfg.Env[key] - }) - - refArgs := strings.Split(refArgsRaw, " ") - if len(newCmd.Args) == 0 { - newCmd.Args = append([]string{cmd.Name}, refArgs...) + newCmd.Args = append([]string{cmd.Name}, refCommand.RefArgs...) } else { - newCmd.Args = append(newCmd.Args, refArgs...) + newCmd.Args = append(newCmd.Args, refCommand.RefArgs...) } newCmd.CommandArgs = newCmd.Args[1:] diff --git a/config/config/config.go b/config/config/config.go index 211e1481..812f9f54 100644 --- a/config/config/config.go +++ b/config/config/config.go @@ -14,11 +14,11 @@ var ( ) var ( - ValidConfigDirectives = set.NewStringSetWithValues( - []string{COMMANDS, SHELL, ENV, EvalEnv, MIXINS, VERSION, BEFORE}, + ValidConfigDirectives = set.NewSet( + COMMANDS, SHELL, ENV, EvalEnv, MIXINS, VERSION, BEFORE, ) - ValidMixinConfigDirectives = set.NewStringSetWithValues( - []string{COMMANDS, ENV, EvalEnv, BEFORE}, + ValidMixinConfigDirectives = set.NewSet( + COMMANDS, ENV, EvalEnv, BEFORE, ) ) diff --git a/config/parser/args.go b/config/parser/args.go index 388507f6..52bf7d5a 100644 --- a/config/parser/args.go +++ b/config/parser/args.go @@ -1,21 +1,52 @@ package parser import ( + "fmt" + "os" + + "github.com/kballard/go-shellquote" "github.com/lets-cli/lets/config/config" ) func parseArgs(rawArgs interface{}, newCmd *config.Command) error { - args, ok := rawArgs.(string) - if !ok { + switch args := rawArgs.(type) { + case string: + argsList, err := shellquote.Split(args) + if err != nil { + return parseError( + "can not parse into args list", + newCmd.Name, + ARGS, + err.Error(), + ) + } + + newCmd.RefArgs = argsList + case []string: + newCmd.RefArgs = args + case []interface{}: + for _, arg := range args { + newCmd.RefArgs = append(newCmd.RefArgs, fmt.Sprintf("%s", arg)) + } + default: return parseError( - "must be a string", + "must be a string or a list of string", newCmd.Name, ARGS, "", ) } - newCmd.RefArgs = args - return nil } + +func postprocessRefArgs(cfg *config.Config) { + for _, cmd := range cfg.Commands { + for idx, arg := range cmd.RefArgs { + // we have to expand env here on our own, since this args not came from users tty, and not expanded before lets + cmd.RefArgs[idx] = os.Expand(arg, func(key string) string { + return cfg.Env[key] + }) + } + } +} diff --git a/config/parser/command.go b/config/parser/command.go index ba4954b1..b0fc8a5f 100644 --- a/config/parser/command.go +++ b/config/parser/command.go @@ -24,7 +24,7 @@ var ( ARGS = "args" ) -var directives = set.NewStringSetWithValues([]string{ +var directives = set.NewSet[string]( CMD, DESCRIPTION, WORKDIR, @@ -38,7 +38,7 @@ var directives = set.NewStringSetWithValues([]string{ AFTER, REF, ARGS, -}) +) // parseCommand parses and validates unmarshaled yaml. func parseCommand(newCmd *config.Command, rawCommand map[string]interface{}, cfg *config.Config) error { diff --git a/config/parser/parser.go b/config/parser/parser.go index a6b929cc..a30e31eb 100644 --- a/config/parser/parser.go +++ b/config/parser/parser.go @@ -50,26 +50,6 @@ func newConfigParseError(msg string, name string, field string) error { } func parseConfigGeneral(rawKeyValue map[string]interface{}, cfg *config.Config) error { - if cmds, ok := rawKeyValue[config.COMMANDS]; ok { - cmdsMap, ok := cmds.(map[string]interface{}) - if !ok { - return newConfigParseError( - "must be a mapping", - config.COMMANDS, - "", - ) - } - - commands, err := parseCommands(cmdsMap, cfg) - if err != nil { - return err - } - - for _, c := range commands { - cfg.Commands[c.Name] = c - } - } - rawEnv := make(map[string]interface{}) if env, ok := rawKeyValue[ENV]; ok { @@ -123,6 +103,26 @@ func parseConfigGeneral(rawKeyValue map[string]interface{}, cfg *config.Config) } } + if cmds, ok := rawKeyValue[config.COMMANDS]; ok { + cmdsMap, ok := cmds.(map[string]interface{}) + if !ok { + return newConfigParseError( + "must be a mapping", + config.COMMANDS, + "", + ) + } + + commands, err := parseCommands(cmdsMap, cfg) + if err != nil { + return err + } + + for _, c := range commands { + cfg.Commands[c.Name] = c + } + } + return nil } @@ -176,6 +176,8 @@ func parseConfig(rawKeyValue map[string]interface{}, cfg *config.Config) error { } } + postprocessRefArgs(cfg) + return nil } diff --git a/docker/Dockerfile b/docker/Dockerfile index 587f8813..7a85ae1c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.17.5-buster +FROM golang:1.18-buster ENV GOPROXY https://proxy.golang.org WORKDIR /app @@ -6,9 +6,9 @@ WORKDIR /app RUN apt-get update && apt-get install git gcc RUN cd /tmp && \ - git clone git://github.com/bats-core/bats-core && \ - git clone git://github.com/bats-core/bats-support.git /bats/bats-support && \ - git clone git://github.com/bats-core/bats-assert.git /bats/bats-assert && \ + git clone https://github.com/bats-core/bats-core && \ + git clone https://github.com/bats-core/bats-support.git /bats/bats-support && \ + git clone https://github.com/bats-core/bats-assert.git /bats/bats-assert && \ cd bats-core && \ ./install.sh /usr && \ echo Bats installed diff --git a/docker/Dockerfile.lint b/docker/lint.Dockerfile similarity index 52% rename from docker/Dockerfile.lint rename to docker/lint.Dockerfile index 75923f8f..814cabbb 100644 --- a/docker/Dockerfile.lint +++ b/docker/lint.Dockerfile @@ -1,3 +1,3 @@ -FROM golangci/golangci-lint:v1.37-alpine +FROM golangci/golangci-lint:v1.45-alpine RUN mkdir -p /.cache && chmod -R 777 /.cache diff --git a/docs/docs/changelog.md b/docs/docs/changelog.md index 63316e81..06abf8d1 100644 --- a/docs/docs/changelog.md +++ b/docs/docs/changelog.md @@ -5,8 +5,12 @@ title: Changelog ## [Unreleased] +## [0.0.45] + * `[Fixed]` **`Breaking change`** Fix duplicate files for checksum. This will change checksum output if the same file has been read multiple times. +* `[Fixed]` Fix parsing for ref args when declared as string. +* `[Added]` ref `args` can be a list of string ## [0.0.44](https://github.com/lets-cli/lets/releases/tag/v0.0.44) diff --git a/docs/docs/config.md b/docs/docs/config.md index 36ce48b1..8292507c 100644 --- a/docs/docs/config.md +++ b/docs/docs/config.md @@ -700,19 +700,23 @@ Now: ```yaml commands: - ls: - cmd: [ls] + hello: + cmd: echo Hello $@ - ls-table: - ref: ls - args: -l + hello-world: + ref: hello + args: World + + hello-by-name: + ref: hello + args: [Dear, Friend] ``` ### `args` `key: args` -`type: string` +`type: string or list of string` **`Experimental feature`** diff --git a/env/env.go b/env/env.go index d2a07e56..154054a9 100644 --- a/env/env.go +++ b/env/env.go @@ -5,12 +5,6 @@ import ( "strconv" ) -// GetConfigPathFromEnv return config file name and config dir -// LETS_CONFIG_DIR convenient to use in tests or when you want to run lets in another dir. -func GetConfigPathFromEnv() (string, string) { - return os.Getenv("LETS_CONFIG"), os.Getenv("LETS_CONFIG_DIR") -} - // IsDebug checks LETS_DEBUG env. If set to true or 1 - we in debug mode. func IsDebug() bool { debug, err := strconv.ParseBool(os.Getenv("LETS_DEBUG")) diff --git a/go.mod b/go.mod index e8867853..1b8572d6 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/lets-cli/lets -go 1.17 +go 1.18 require ( github.com/codeclysm/extract v2.2.0+incompatible @@ -16,8 +16,9 @@ require ( github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/juju/errors v0.0.0-20200330140219-3fe23663418f // indirect github.com/juju/testing v0.0.0-20201216035041-2be42bba85f3 // indirect + github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect + golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect gopkg.in/yaml.v2 v2.3.0 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b diff --git a/go.sum b/go.sum index 517394c9..bb019556 100644 --- a/go.sum +++ b/go.sum @@ -77,6 +77,8 @@ github.com/juju/version v0.0.0-20180108022336-b64dbd566305/go.mod h1:kE8gK5X0CIm github.com/juju/version v0.0.0-20191219164919-81c1be00b9a6/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U= github.com/julienschmidt/httprouter v1.1.1-0.20151013225520-77a895ad01eb/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -171,8 +173,9 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs= +golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/runner/run.go b/runner/run.go index 29f3b970..01afe174 100644 --- a/runner/run.go +++ b/runner/run.go @@ -69,16 +69,10 @@ func NewRunner(cmd *config.Command, cfg *config.Config, out io.Writer) *Runner { } func NewChildRunner(cmd *config.Command, parentRunner *Runner) *Runner { - cfg := parentRunner.cfg - if cmd.Ref != "" { - newCmd := cfg.Commands[cmd.Ref].FromRef(*cmd, cfg) - cmd = &newCmd - } - return &Runner{ cmd: cmd, parentCmd: parentRunner.cmd, - cfg: cfg, + cfg: parentRunner.cfg, out: parentRunner.out, } } @@ -337,6 +331,11 @@ func (r *Runner) runDepends(ctx context.Context) error { if len(dep.Env) != 0 { dependCmd = dependCmd.WithEnv(dep.Env) } + + if dependCmd.Ref != "" { + dependCmd = r.cfg.Commands[dependCmd.Ref].FromRef(dependCmd) + } + err := NewChildRunner(&dependCmd, r).Execute(ctx) if err != nil { // must return error to root diff --git a/set/set.go b/set/set.go index 9e596779..8a8871c8 100644 --- a/set/set.go +++ b/set/set.go @@ -1,49 +1,35 @@ package set -type StringSet struct { - entryMap map[string]struct{} -} - -func (s *StringSet) Add(value string) { - s.entryMap[value] = struct{}{} -} +type Set[T comparable] map[T]struct{} -func (s *StringSet) AddMany(values []string) { +func (s Set[T]) Add(values ...T) { for _, value := range values { - s.entryMap[value] = struct{}{} + s[value] = struct{}{} } } -func (s *StringSet) ToList() []string { - values := make([]string, 0, len(s.entryMap)) - for k := range s.entryMap { +func (s Set[T]) ToList() []T { + values := make([]T, 0, len(s)) + for k := range s { values = append(values, k) } return values } -func (s *StringSet) Remove(value string) { - delete(s.entryMap, value) +func (s Set[T]) Remove(value T) { + delete(s, value) } -func (s *StringSet) Contains(value string) bool { - _, c := s.entryMap[value] +func (s Set[T]) Contains(value T) bool { + _, c := s[value] return c } -func NewStringSet() *StringSet { - return &StringSet{ - entryMap: make(map[string]struct{}), - } -} - -func NewStringSetWithValues(values []string) *StringSet { - set := &StringSet{ - entryMap: make(map[string]struct{}), - } - set.AddMany(values) +func NewSet[T comparable](values ...T) Set[T] { + set := make(Set[T]) + set.Add(values...) return set } diff --git a/set/set_test.go b/set/set_test.go index f060b23f..737221ac 100644 --- a/set/set_test.go +++ b/set/set_test.go @@ -6,9 +6,9 @@ import ( "testing" ) -func TestStringSet(t *testing.T) { +func TestSet(t *testing.T) { t.Run("add string to set", func(t *testing.T) { - set := NewStringSet() + set := NewSet[string]() set.Add("a") set.Add("b") @@ -22,9 +22,9 @@ func TestStringSet(t *testing.T) { } }) t.Run("add many strings at once to set", func(t *testing.T) { - set := NewStringSet() + set := NewSet[string]() - set.AddMany([]string{"a", "b", "c"}) + set.Add("a", "b", "c") set.Add("c") values := set.ToList() @@ -35,11 +35,9 @@ func TestStringSet(t *testing.T) { }) t.Run("remove string from set", func(t *testing.T) { - set := NewStringSet() + set := NewSet[string]() - set.Add("a") - set.Add("b") - set.Add("c") + set.Add("a", "b", "c") set.Remove("c") values := set.ToList() @@ -50,14 +48,28 @@ func TestStringSet(t *testing.T) { }) t.Run("remove string from set", func(t *testing.T) { - set := NewStringSet() + set := NewSet[string]() - set.Add("a") - set.Add("b") - set.Add("c") + set.Add("a", "b", "c") if !set.Contains("c") { t.Errorf("set must contain element which was added, got: %s", set.ToList()) } }) } + +func TestIntSet(t *testing.T) { + t.Run("add int to set", func(t *testing.T) { + set := NewSet[int]() + + set.Add(1) + set.Add(2) + set.Add(2) + + values := set.ToList() + sort.Ints(values) + if !reflect.DeepEqual(values, []int{1, 2}) { + t.Errorf("set must contain only unique elements, got: %v", values) + } + }) +} diff --git a/test/config.go b/test/config.go deleted file mode 100644 index f0b252e1..00000000 --- a/test/config.go +++ /dev/null @@ -1,51 +0,0 @@ -package test - -import ( - "log" - "os" - - "gopkg.in/yaml.v3" -) - -type SerializableTestConfig struct { - Shell string - Commands map[string]map[string]string -} - -// NewTestConfig creates config, write it to temp dir, set LETS_CONFIG_DIR with LETS_CONFIG and return cleanup func. -func NewTestConfig(configRaw *SerializableTestConfig) func() { - tempDir := os.TempDir() - testConfigFile := CreateTempFile(tempDir, "lets_*.yaml") - - err := yaml.NewEncoder(testConfigFile).Encode(configRaw) - if err != nil { - log.Fatalf("can not create test config: %s", err) - } - - err = os.Setenv("LETS_CONFIG_DIR", tempDir) - if err != nil { - log.Fatalf("can not set LETS_CONFIG_DIR during test: %s", err) - } - - err = os.Setenv("LETS_CONFIG", testConfigFile.Name()) - if err != nil { - log.Fatalf("can not set LETS_CONFIG during test: %s", err) - } - - return func() { - err := os.Unsetenv("LETS_CONFIG_DIR") - if err != nil { - log.Fatalf("can not unset LETS_CONFIG_DIR after test: %s", err) - } - - err = os.Unsetenv("LETS_CONFIG") - if err != nil { - log.Fatalf("can not unset LETS_CONFIG after test: %s", err) - } - - err = os.Remove(testConfigFile.Name()) - if err != nil { - log.Fatalf("can not remove temp config file %s after test: %s", testConfigFile.Name(), err) - } - } -} diff --git a/tests/command_ref.bats b/tests/command_ref.bats index 08992e8a..b4831f82 100644 --- a/tests/command_ref.bats +++ b/tests/command_ref.bats @@ -10,3 +10,9 @@ setup() { assert_success assert_line --index 0 "Hello World" } + +@test "command ref: run existing command with args as list from ref" { + run lets hello-list + assert_success + assert_line --index 0 "Hello Fellow friend" +} diff --git a/tests/command_ref/lets.yaml b/tests/command_ref/lets.yaml index 4b2f1db8..29167cd8 100644 --- a/tests/command_ref/lets.yaml +++ b/tests/command_ref/lets.yaml @@ -7,3 +7,7 @@ commands: hello-world: ref: hello args: World + + hello-list: + ref: hello + args: [Fellow, friend] diff --git a/util/dir.go b/util/dir.go index 1f779708..af4cf0de 100644 --- a/util/dir.go +++ b/util/dir.go @@ -6,7 +6,7 @@ import ( ) func SafeCreateDir(dirPath string) error { - if err := os.Mkdir(dirPath, 0755); err != nil { + if err := os.Mkdir(dirPath, 0o755); err != nil { if os.IsExist(err) { // its ok if we already have a dir, just return return nil diff --git a/workdir/workdir.go b/workdir/workdir.go index c2b79f75..33288ff3 100644 --- a/workdir/workdir.go +++ b/workdir/workdir.go @@ -42,14 +42,15 @@ func GetDotLetsDir(workDir string) (string, error) { // InitLetsFile creates lets.yaml int the current dir. func InitLetsFile(workDir string, version string) error { - f := filepath.Join(workDir, "lets.yaml") + configfile := filepath.Join(workDir, "lets.yaml") - if _, err := os.Stat(f); err == nil { + if _, err := os.Stat(configfile); err == nil { return fmt.Errorf("lets.yaml already exists in %s", workDir) } output := fmt.Sprintf(defaultLetsYaml, version) - if err := os.WriteFile(f, []byte(output), 0644); err != nil { + //#nosec G306 + if err := os.WriteFile(configfile, []byte(output), 0o644); err != nil { return err }