@@ -20,6 +20,7 @@ type RemoveOptions struct {
20
20
21
21
SecretName string
22
22
OrgName string
23
+ EnvName string
23
24
}
24
25
25
26
func NewCmdRemove (f * cmdutil.Factory , runF func (* RemoveOptions ) error ) * cobra.Command {
@@ -31,12 +32,16 @@ func NewCmdRemove(f *cmdutil.Factory, runF func(*RemoveOptions) error) *cobra.Co
31
32
32
33
cmd := & cobra.Command {
33
34
Use : "remove <secret-name>" ,
34
- Short : "Remove an organization or repository secret" ,
35
+ Short : "Remove an organization, environment, or repository secret" ,
35
36
Args : cobra .ExactArgs (1 ),
36
37
RunE : func (cmd * cobra.Command , args []string ) error {
37
38
// support `-R, --repo` override
38
39
opts .BaseRepo = f .BaseRepo
39
40
41
+ if err := cmdutil .MutuallyExclusive ("specify only one of `--org` or `--env`" , opts .OrgName != "" , opts .EnvName != "" ); err != nil {
42
+ return err
43
+ }
44
+
40
45
opts .SecretName = args [0 ]
41
46
42
47
if runF != nil {
@@ -46,7 +51,8 @@ func NewCmdRemove(f *cmdutil.Factory, runF func(*RemoveOptions) error) *cobra.Co
46
51
return removeRun (opts )
47
52
},
48
53
}
49
- cmd .Flags ().StringVarP (& opts .OrgName , "org" , "o" , "" , "List secrets for an organization" )
54
+ cmd .Flags ().StringVarP (& opts .OrgName , "org" , "o" , "" , "Remove a secret for an organization" )
55
+ cmd .Flags ().StringVarP (& opts .EnvName , "env" , "e" , "" , "Remove a secret for an environment" )
50
56
51
57
return cmd
52
58
}
@@ -59,6 +65,7 @@ func removeRun(opts *RemoveOptions) error {
59
65
client := api .NewClientFromHTTP (c )
60
66
61
67
orgName := opts .OrgName
68
+ envName := opts .EnvName
62
69
63
70
var baseRepo ghrepo.Interface
64
71
if orgName == "" {
@@ -69,10 +76,12 @@ func removeRun(opts *RemoveOptions) error {
69
76
}
70
77
71
78
var path string
72
- if orgName == "" {
73
- path = fmt .Sprintf ("repos/%s/actions/secrets/%s" , ghrepo .FullName (baseRepo ), opts .SecretName )
74
- } else {
79
+ if orgName != "" {
75
80
path = fmt .Sprintf ("orgs/%s/actions/secrets/%s" , orgName , opts .SecretName )
81
+ } else if envName != "" {
82
+ path = fmt .Sprintf ("repos/%s/environments/%s/secrets/%s" , ghrepo .FullName (baseRepo ), envName , opts .SecretName )
83
+ } else {
84
+ path = fmt .Sprintf ("repos/%s/actions/secrets/%s" , ghrepo .FullName (baseRepo ), opts .SecretName )
76
85
}
77
86
78
87
cfg , err := opts .Config ()
@@ -96,7 +105,11 @@ func removeRun(opts *RemoveOptions) error {
96
105
target = ghrepo .FullName (baseRepo )
97
106
}
98
107
cs := opts .IO .ColorScheme ()
99
- fmt .Fprintf (opts .IO .Out , "%s Removed secret %s from %s\n " , cs .SuccessIconWithColor (cs .Red ), opts .SecretName , target )
108
+ if envName != "" {
109
+ fmt .Fprintf (opts .IO .Out , "%s Removed secret %s from %s environment on %s\n " , cs .SuccessIconWithColor (cs .Red ), opts .SecretName , envName , target )
110
+ } else {
111
+ fmt .Fprintf (opts .IO .Out , "%s Removed secret %s from %s\n " , cs .SuccessIconWithColor (cs .Red ), opts .SecretName , target )
112
+ }
100
113
}
101
114
102
115
return nil
0 commit comments