Skip to content

Commit

Permalink
Add --ignore-case option (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
mniak authored Oct 7, 2021
1 parent d5981e7 commit def5073
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
34 changes: 21 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
on: [push, pull_request]
name: Test
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test:
strategy:
matrix:
go-version: [1.13.x, 1.14.x]
os: [ubuntu-latest, macos-latest, windows-latest]
go-version: [1.14.x, 1.16.x]
os: [macos-latest, ubuntu-latest, windows-latest]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install Go
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2

- name: Build
run: go build -v ./...

- name: Test
run: go test ./...
run: go test -v ./... -coverprofile=coverage.txt -covermode=atomic

- name: Upload coverage to Codecov
run: bash <(curl -s https://codecov.io/bash)
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.16.x'
8 changes: 6 additions & 2 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ var generateConfigMapCmd = &cobra.Command{
stripPrefix, err := cmd.Flags().GetBool("strip-prefix")
handleError(err)

ignoreCase, err := cmd.Flags().GetBool("ignore-case")
handleError(err)

configMap, err := lib.GenerateConfigMap(lib.GenerateConfigMapParams{
Name: name,
FromEnvironment: fromEnv,
Prefix: prefix,
StripPrefix: stripPrefix,
IgnoreCase: ignoreCase,
})
handleError(err)

Expand All @@ -45,7 +49,7 @@ func init() {
generateCmd.AddCommand(generateConfigMapCmd)

generateConfigMapCmd.Flags().Bool("env", false, "Load variables from environment")
generateConfigMapCmd.Flags().Bool("strip-prefix", false, "Strip the variable name prefix")

generateConfigMapCmd.Flags().String("prefix", "", "Filter the variables by this prefix")
generateConfigMapCmd.Flags().Bool("strip-prefix", false, "Strip the variable name prefix")
generateConfigMapCmd.Flags().BoolP("ignore-case", "i", false, "Ignore case distinctions when filtering variable names")
}
5 changes: 5 additions & 0 deletions lib/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type GenerateConfigMapParams struct {
FromEnvironment bool
Prefix string
StripPrefix bool
IgnoreCase bool
}

func (p GenerateConfigMapParams) Validate() error {
Expand Down Expand Up @@ -45,6 +46,10 @@ func (p GenerateConfigMapParams) getVariables() (map[string]string, error) {
}

func (p GenerateConfigMapParams) isValidKey(key string) bool {
if p.IgnoreCase {
key = strings.ToLower(key)
p.Prefix = strings.ToLower(p.Prefix)
}
return strings.HasPrefix(key, p.Prefix)
}

Expand Down

0 comments on commit def5073

Please sign in to comment.