Skip to content

Commit 7ef2839

Browse files
author
Josh Newman
committed
feat(put): add optional value flag for direct input escaping values starting with --
1 parent 2c8a009 commit 7ef2839

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Flags:
130130
-h, --help help for put
131131
-o, --overwrite overwrite param if exists.
132132
-t, --type string type of parameter. (default "SecureString")
133+
-v, --value string value to store.
133134

134135
Global Flags:
135136
--config string config file (default is $HOME/.easy-params.yaml)

cmd/put.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ var putCmd = &cobra.Command{
2020
Args: func(cmd *cobra.Command, args []string) error {
2121
context, _ := cmd.Flags().GetString("context")
2222

23-
if context == "" && len(args) < 2 {
24-
return errors.New("requires a path and a value")
23+
if context == "" && len(args) < 1 {
24+
return errors.New("requires a path")
2525
}
2626

2727
return nil
@@ -98,9 +98,24 @@ func runPutCmdContext(cmd *cobra.Command, args []string, ctx string) {
9898

9999
func runPutCmd(cmd *cobra.Command, args []string) {
100100
path := args[0]
101-
value := args[1]
102101
overwrite, _ := cmd.Flags().GetBool("overwrite")
103102
valueType, _ := cmd.Flags().GetString("type")
103+
valueFlag, _ := cmd.Flags().GetString("value")
104+
105+
value := ""
106+
if len(args) > 1 {
107+
value = args[1]
108+
}
109+
110+
if value == "" {
111+
// try to use the flag
112+
if valueFlag == "" {
113+
fmt.Println(text.FgRed.Sprint("Value argument or flag is required."))
114+
os.Exit(1)
115+
}
116+
117+
value = valueFlag
118+
}
104119

105120
client := ssm.NewFromConfig(awsConfig)
106121

@@ -127,6 +142,7 @@ func init() {
127142
putCmd.Flags().BoolP("overwrite", "o", false, "overwrite param if exists.")
128143
putCmd.Flags().StringP("type", "t", "SecureString", "type of parameter.")
129144
putCmd.Flags().StringP("context", "c", "", "context mode for setting many values.")
145+
putCmd.Flags().StringP("value", "v", "", "value to store.")
130146

131147
rootCmd.AddCommand(putCmd)
132148
}

0 commit comments

Comments
 (0)