| 24 | ) |
| 25 | |
| 26 | func GetCommand() *cobra.Command { |
| 27 | cmd := &cobra.Command{ |
| 28 | Use: "get NAME", |
| 29 | Args: cobra.ExactArgs(1), |
| 30 | Short: "Get a secret from a keystore.", |
| 31 | Long: "Retrieves a named secret from the local OS keychain. The secret value is masked in output.", |
| 32 | RunE: func(cmd *cobra.Command, args []string) error { |
| 33 | id, err := store.ParseID(args[0]) |
| 34 | if err != nil { |
| 35 | return err |
| 36 | } |
| 37 | kc, err := StoreFrom(cmd.Context()) |
| 38 | if err != nil { |
| 39 | return err |
| 40 | } |
| 41 | s, err := kc.Get(cmd.Context(), id) |
| 42 | if err != nil { |
| 43 | return err |
| 44 | } |
| 45 | _, ok := s.(*pass.PassValue) |
| 46 | if !ok { |
| 47 | return errors.New("unknown secret type") |
| 48 | } |
| 49 | cmd.Printf("ID: %s\nValue: %s\n", id.String(), "**********") |
| 50 | return nil |
| 51 | }, |
| 52 | } |
| 53 | return cmd |
| 54 | } |