Skip to content

Commit

Permalink
fix: make options optional (#218)
Browse files Browse the repository at this point in the history
Signed-off-by: Akshay Patidar <[email protected]>
  • Loading branch information
akshaypatidar1999 authored Mar 20, 2024
1 parent 6dadccd commit bb1493a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
version: v1.51.1
version: v1.54
args: -E gofmt -E gci
11 changes: 3 additions & 8 deletions internal/command/commands/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (c *Component) Run(args []string) int {
serviceName := flagSet.String("service", "", "name of the service in which the component is deployed")
envName := flagSet.String("env", "", "name of the environment in which the service is deployed")
operation := flagSet.String("operation", "", "name of the operation to performed on the component")
options := flagSet.String("options", "", "options of the operation in JSON format")
options := flagSet.String("options", "{}", "options of the operation in JSON format")
filePath := flagSet.String("file", "", "file to provide options for component operations")

err := flagSet.Parse(args)
Expand All @@ -40,19 +40,14 @@ func (c *Component) Run(args []string) int {
}
emptyParameters := emptyParameters(map[string]string{"--name": *name, "--service": *serviceName, "--env": *envName, "--operation": *operation})
if len(emptyParameters) == 0 {
isOptionsPresent := len(*options) > 0
isOptionsPresent := *options != "{}"
isFilePresent := len(*filePath) > 0

if isOptionsPresent && isFilePresent {
c.Logger.Error("You can provide either --options or --file but not both")
return 1
}

if !isOptionsPresent && !isFilePresent {
c.Logger.Error("You should provide either --options or --file")
return 1
}

var optionsData map[string]interface{}

if isFilePresent {
Expand All @@ -62,7 +57,7 @@ func (c *Component) Run(args []string) int {
return 1
}
optionsData = parsedConfig.(map[string]interface{})
} else if isOptionsPresent {
} else {
err = json.Unmarshal([]byte(*options), &optionsData)
if err != nil {
c.Logger.Error("Unable to parse JSON data " + err.Error())
Expand Down

0 comments on commit bb1493a

Please sign in to comment.