-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
386 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
"github.com/charmbracelet/lipgloss" | ||
"github.com/charmbracelet/lipgloss/table" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewDynamicVariablesCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
GroupID: "configuration", | ||
Use: "dynamic_variables", | ||
Short: "manage dynamic variables", | ||
Long: `manage dynamic variables`, | ||
} | ||
|
||
cmd.DisableFlagsInUseLine = true | ||
cmd.SilenceUsage = true | ||
|
||
cmd.AddCommand( | ||
NewDynamicVariablesAddCommand(), | ||
NewDynamicVariablesListCommand(), | ||
NewDynamicVariablesRemoveCommand(), | ||
) | ||
|
||
return cmd | ||
} | ||
|
||
// Define DynamicVariables as a list of key-value pairs (map[string]string) | ||
type DynamicVariables []map[string]string | ||
|
||
func GetMockDynamicVars() DynamicVariables { | ||
// Initialize DynamicVariables with some key-value pairs | ||
vars := DynamicVariables{ | ||
{"key": "environment", "value": "production"}, | ||
{"key": "version", "value": "1.0.0"}, | ||
{"key": "region", "value": "us-west-1"}, | ||
} | ||
return vars | ||
} | ||
|
||
func NewDynamicVariablesListCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Short: "list dynamic variables", | ||
Long: `list dynamic variables`, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
dynamicVars := GetMockDynamicVars() | ||
|
||
var rows [][]string | ||
headers := []string{"Key", "Value", "Status"} | ||
|
||
for _, dynamicVar := range dynamicVars { | ||
row := []string{dynamicVar["key"], dynamicVar["value"], "Enabled"} | ||
rows = append(rows, row) | ||
} | ||
|
||
printDynamicVariables := func(headers []string, rows [][]string) { | ||
if len(rows) == 0 { | ||
return | ||
} | ||
dynamicVariablesOutput := table.New(). | ||
BorderHeader(false). | ||
Border(lipgloss.HiddenBorder()). | ||
StyleFunc(func(row, col int) lipgloss.Style { | ||
switch { | ||
case row == 0: | ||
return HeaderStyle | ||
default: | ||
return lipgloss.NewStyle() | ||
} | ||
}). | ||
Headers(headers...). | ||
Rows(rows...) | ||
fmt.Println(dynamicVariablesOutput) | ||
} | ||
|
||
printDynamicVariables(headers, rows) | ||
return nil | ||
}, | ||
} | ||
|
||
cmd.DisableFlagsInUseLine = true | ||
cmd.SilenceUsage = true | ||
|
||
return cmd | ||
} | ||
|
||
type dynamicVariableAddFlags struct { | ||
key string | ||
value string | ||
} | ||
|
||
|
||
func (f dynamicVariableAddFlags) successString() string { | ||
var sb strings.Builder | ||
_, _ = fmt.Fprintf(&sb, `dynamic variable added successfully as: "%s" (%s).`, f.key, f.value) | ||
_, _ = fmt.Fprintln(&sb) | ||
return sb.String() | ||
} | ||
|
||
func NewDynamicVariablesAddCommand() *cobra.Command { | ||
f := dynamicVariableAddFlags{} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "add", | ||
Short: "add a dynamic variable", | ||
Long: `add a dynamic variable`, | ||
Example: ` add --key some_key --value s0m3v@lu3@5@`, | ||
PreRunE: func(cmd *cobra.Command, _ []string) error { | ||
cmd.MarkFlagsRequiredTogether("key", "value") | ||
|
||
return nil | ||
}, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
if cmd.Flags().NFlag() == 0 { | ||
return errors.New(cmd.UsageString()) | ||
} | ||
|
||
fmt.Println(f.successString()) | ||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVarP(&f.key, "key", "k", "", "key of the dynamic variable") | ||
cmd.Flags().StringVarP(&f.value, "value", "v", "", "value of the dynamic variable") | ||
|
||
cmd.DisableFlagsInUseLine = true | ||
cmd.SilenceUsage = true | ||
|
||
return cmd | ||
} | ||
|
||
func NewDynamicVariablesRemoveCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "remove", | ||
Short: "remove a dynamic variable", | ||
Long: `remove a dynamic variable`, | ||
Example: ` remove --key some_key`, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
dynamicVariableKey, _ := cmd.Flags().GetString("key") | ||
|
||
fmt.Printf(`"%s" dynamic variable removed successfully.`, dynamicVariableKey) | ||
fmt.Println() | ||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().StringP("key", "k", "", "name of the dynamic variable") | ||
_ = cmd.MarkFlagRequired("key") | ||
|
||
cmd.DisableFlagsInUseLine = true | ||
cmd.SilenceUsage = true | ||
|
||
return cmd | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## mdai dynamic variables list | ||
|
||
list telemetry dynamic variables | ||
|
||
### Synopsis | ||
|
||
list telemetry dynamic variables | ||
|
||
``` | ||
mdai dynamic variables list | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for list | ||
--pipeline | ||
--service | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--kubeconfig sts Path to a kubeconfig | ||
--kubecontext string Kubernetes context to use | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [mdai dynamic_variables](mdai_dynamic_variables.md) - telemetry dynamic variables | ||
|
||
###### Auto generated by spf13/cobra on 23-Aug-2024 |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
## mdai dynamic_variables | ||
|
||
Manage dynamic variables | ||
|
||
### Synopsis | ||
|
||
Manage dynamic variables | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for filter | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--kubeconfig string Path to a kubeconfig | ||
--kubecontext string Kubernetes context to use | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [mdai](mdai.md) - MyDecisive.ai CLI | ||
* [mdai dynamic_variables add](mdai_dynamic_variables_add.md) - add dynamic variables | ||
* [mdai dynamic_variables list](mdai_dynamic_variables_list.md) - list dynamic variables | ||
* [mdai dynamic_variables remove](mdai_dynamic_variables_remove.md) - remove a dynamic variables | ||
|
||
###### Auto generated by spf13/cobra on 23-Aug-2024 |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## mdai dynamic variables add | ||
|
||
add dynamic variables | ||
|
||
``` | ||
mdai dynamic_variables add | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
add --key some_key --description some_value | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-v, --value string value of the dynamic variables | ||
-h, --help help for add | ||
-k, --key string key of the dynamic variables | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--kubeconfig string Path to a kubeconfig | ||
--kubecontext string Kubernetes context to use | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [mdai dynamic_variables](mdai_dynamic variables.md) - dynamic variables | ||
|
||
###### Auto generated by spf13/cobra on 23-Aug-2024 |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
## mdai filter remove | ||
|
||
remove a dynamic variable | ||
|
||
### Synopsis | ||
|
||
remove a dynamic variable | ||
|
||
``` | ||
mdai dynamic_variable remove | ||
``` | ||
|
||
### Examples | ||
|
||
``` | ||
remove --key some_key | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for remove | ||
-k, --key string key of the dynamic variable | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--kubeconfig string Path to a kubeconfig | ||
--kubecontext string Kubernetes context to use | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [mdai dynamic_variable](mdai_dynamic_variable.md) - dynamic variables | ||
|
||
###### Auto generated by spf13/cobra on 23-Aug-2024 |
Oops, something went wrong.