This repository was archived by the owner on Feb 16, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,4 +23,5 @@ func NewEnvCommand(io ui.IO, newClient newClientFunc) *EnvCommand {
2323func (cmd * EnvCommand ) Register (r command.Registerer ) {
2424 clause := r .Command ("env" , "Manage environment variables." ).Hidden () // The command is hidden, because it's still in beta.
2525 NewEnvReadCommand (cmd .io , cmd .newClient ).Register (clause )
26+ NewEnvListCommand (cmd .io ).Register (clause )
2627}
Original file line number Diff line number Diff line change 1+ package secrethub
2+
3+ import (
4+ "fmt"
5+
6+ "github.com/secrethub/secrethub-cli/internals/cli/ui"
7+ "github.com/secrethub/secrethub-cli/internals/secrethub/command"
8+ )
9+
10+ // EnvListCommand is a command to list all environment variable keys set in the process of `secrethub run`.
11+ type EnvListCommand struct {
12+ io ui.IO
13+ environment * environment
14+ }
15+
16+ // NewEnvListCommand creates a new EnvListCommand.
17+ func NewEnvListCommand (io ui.IO ) * EnvListCommand {
18+ return & EnvListCommand {
19+ io : io ,
20+ environment : newEnvironment (io ),
21+ }
22+ }
23+
24+ // Register adds a CommandClause and it's args and flags to a Registerer.
25+ func (cmd * EnvListCommand ) Register (r command.Registerer ) {
26+ clause := r .Command ("ls" , "Read the value of a single environment variable." )
27+ clause .Alias ("list" )
28+
29+ cmd .environment .register (clause )
30+
31+ command .BindAction (clause , cmd .Run )
32+ }
33+
34+ // Run handles the command with the options as specified in the command.
35+ func (cmd * EnvListCommand ) Run () error {
36+ env , err := cmd .environment .env ()
37+ if err != nil {
38+ return err
39+ }
40+
41+ for key , value := range env {
42+ // For now only environment variables in which a secret is loaded are printed.
43+ // TODO: Make this behavior configurable.
44+ if value .containsSecret () {
45+ fmt .Fprintln (cmd .io .Stdout (), key )
46+ }
47+ }
48+
49+ return nil
50+ }
You can’t perform that action at this time.
0 commit comments