1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(newGetCmd())
}
func newGetCmd() *cobra.Command {
return &cobra.Command{
Use: "get KEY",
Short: "Print a secret value",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
key := normalizeKeyInput(args[0])
project := resolveProject()
// Priority 1: active session
if sv := trySession(); sv != nil {
val, ok := sv[key]
if !ok {
return fmt.Errorf("key %q not found in project %q", key, project)
}
fmt.Print(val)
return nil
}
// Priority 2: full vault
v, _, _, err := openVault()
if err != nil {
return err
}
val, ok := v.Get(project, key)
if !ok {
return fmt.Errorf("key %q not found in project %q", key, project)
}
fmt.Print(val)
return nil
},
}
}
|