Skip to content

Commit 2c8a009

Browse files
author
Josh Newman
committed
feat(get): add copy to clipboard flag
1 parent 46e80b3 commit 2c8a009

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

cmd/get.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"strings"
88

9+
"github.com/atotto/clipboard"
910
"github.com/aws/aws-sdk-go-v2/service/ssm"
1011
"github.com/spf13/cobra"
1112
)
@@ -26,6 +27,7 @@ var getCmd = &cobra.Command{
2627
func runGetCmd(cmd *cobra.Command, args []string) {
2728
path := fmt.Sprintf("/%s", stripSlash(args[0]))
2829
decrypt, _ := cmd.Flags().GetBool("decrypt")
30+
copy, _ := cmd.Flags().GetBool("copy")
2931

3032
client := ssm.NewFromConfig(awsConfig)
3133

@@ -43,11 +45,19 @@ func runGetCmd(cmd *cobra.Command, args []string) {
4345
val = strings.TrimSuffix(val, "\n")
4446
}
4547

46-
fmt.Println(val)
48+
if copy {
49+
if err := clipboard.WriteAll(val); err != nil {
50+
panic(err)
51+
}
52+
fmt.Println("Value copied to clipboard!")
53+
} else {
54+
fmt.Println(val)
55+
}
4756
}
4857

4958
func init() {
5059
getCmd.Flags().BoolP("decrypt", "d", true, "decrypt \"SecureString\" value")
60+
getCmd.Flags().BoolP("copy", "c", false, "copy to clipboard")
5161

5262
rootCmd.AddCommand(getCmd)
5363
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.16
44

55
require (
66
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
7+
github.com/atotto/clipboard v0.1.4
78
github.com/aws/aws-sdk-go-v2 v1.2.1
89
github.com/aws/aws-sdk-go-v2/config v1.1.2
910
github.com/aws/aws-sdk-go-v2/service/ssm v1.1.2

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj
2222
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
2323
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ=
2424
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
25+
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
26+
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
2527
github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
2628
github.com/aws/aws-sdk-go-v2 v1.2.1 h1:055XAi+MtmhyYX161p+jWRibkCb9YpI2ymXZiW1dwVY=
2729
github.com/aws/aws-sdk-go-v2 v1.2.1/go.mod h1:hTQc/9pYq5bfFACIUY9tc/2SYWd9Vnmw+testmuQeRY=

0 commit comments

Comments
 (0)