-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from lets-cli/fix-ref-args
Fix ref args
- Loading branch information
Showing
25 changed files
with
188 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected] | ||
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/[email protected] | ||
with: | ||
version: latest | ||
- name: Run lint | ||
run: lets lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.