diff --git a/internal/cli/cli.go b/internal/cli/cli.go index a40c9b3..23e5372 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -27,6 +27,7 @@ type Instance struct { func NewCLIInstance() *Instance { fs := afero.NewOsFs() stateDir := secret.DetermineStateDir("") + return &Instance{ fs: fs, stateDir: stateDir, @@ -70,6 +71,7 @@ func getStdinScanner() *bufio.Scanner { if stdinScanner == nil { stdinScanner = bufio.NewScanner(os.Stdin) } + return stdinScanner } @@ -87,7 +89,9 @@ func readLineFromStdin(prompt string) (string, error) { if err := scanner.Err(); err != nil { return "", fmt.Errorf("failed to read from stdin: %w", err) } + return "", fmt.Errorf("failed to read from stdin: EOF") } + return strings.TrimSpace(scanner.Text()), nil } diff --git a/internal/cli/crypto.go b/internal/cli/crypto.go index 6a9332e..9130042 100644 --- a/internal/cli/crypto.go +++ b/internal/cli/crypto.go @@ -23,12 +23,14 @@ func newEncryptCmd() *cobra.Command { cli := NewCLIInstance() cli.cmd = cmd + return cli.Encrypt(args[0], inputFile, outputFile) }, } cmd.Flags().StringP("input", "i", "", "Input file (default: stdin)") cmd.Flags().StringP("output", "o", "", "Output file (default: stdout)") + return cmd } @@ -44,12 +46,14 @@ func newDecryptCmd() *cobra.Command { cli := NewCLIInstance() cli.cmd = cmd + return cli.Decrypt(args[0], inputFile, outputFile) }, } cmd.Flags().StringP("input", "i", "", "Input file (default: stdin)") cmd.Flags().StringP("output", "o", "", "Output file (default: stdout)") + return cmd } diff --git a/internal/cli/generate.go b/internal/cli/generate.go index 84b20d8..0e5ffa3 100644 --- a/internal/cli/generate.go +++ b/internal/cli/generate.go @@ -50,6 +50,7 @@ func newGenerateSecretCmd() *cobra.Command { force, _ := cmd.Flags().GetBool("force") cli := NewCLIInstance() + return cli.GenerateSecret(cmd, args[0], length, secretType, force) }, } @@ -134,6 +135,7 @@ func (cli *Instance) GenerateSecret( } cmd.Printf("Generated and stored %d-character %s secret: %s\n", length, secretType, secretName) + return nil } diff --git a/internal/cli/root.go b/internal/cli/root.go index 6f2bdf5..c3e3921 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -42,5 +42,6 @@ func newRootCmd() *cobra.Command { cmd.AddCommand(newVersionCmd()) secret.Debug("newRootCmd completed") + return cmd } diff --git a/internal/cli/secrets.go b/internal/cli/secrets.go index 85e9c4b..d3ece2d 100644 --- a/internal/cli/secrets.go +++ b/internal/cli/secrets.go @@ -26,11 +26,13 @@ func newAddCmd() *cobra.Command { cli := NewCLIInstance() cli.cmd = cmd // Set the command for stdin access secret.Debug("Created CLI instance, calling AddSecret") + return cli.AddSecret(args[0], force) }, } cmd.Flags().BoolP("force", "f", false, "Overwrite existing secret") + return cmd } @@ -42,11 +44,13 @@ func newGetCmd() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { version, _ := cmd.Flags().GetString("version") cli := NewCLIInstance() + return cli.GetSecretWithVersion(cmd, args[0], version) }, } cmd.Flags().StringP("version", "v", "", "Get a specific version (default: current)") + return cmd } @@ -66,11 +70,13 @@ func newListCmd() *cobra.Command { } cli := NewCLIInstance() + return cli.ListSecrets(cmd, jsonOutput, filter) }, } cmd.Flags().Bool("json", false, "Output in JSON format") + return cmd } @@ -85,6 +91,7 @@ func newImportCmd() *cobra.Command { force, _ := cmd.Flags().GetBool("force") cli := NewCLIInstance() + return cli.ImportSecret(cmd, args[0], sourceFile, force) }, } @@ -92,6 +99,7 @@ func newImportCmd() *cobra.Command { cmd.Flags().StringP("source", "s", "", "Source file to import from (required)") cmd.Flags().BoolP("force", "f", false, "Overwrite existing secret") _ = cmd.MarkFlagRequired("source") + return cmd } @@ -131,6 +139,7 @@ func (cli *Instance) AddSecret(secretName string, force bool) error { } secret.Debug("vault.AddSecret completed successfully") + return nil } @@ -246,6 +255,7 @@ func (cli *Instance) ListSecrets(cmd *cobra.Command, jsonOutput bool, filter str cmd.Println("No secrets found in current vault.") cmd.Println("Run 'secret add ' to create one.") } + return nil } @@ -297,5 +307,6 @@ func (cli *Instance) ImportSecret(cmd *cobra.Command, secretName, sourceFile str } cmd.Printf("Successfully imported secret '%s' from file '%s'\n", secretName, sourceFile) + return nil } diff --git a/internal/cli/unlockers.go b/internal/cli/unlockers.go index b7ef811..6dd8925 100644 --- a/internal/cli/unlockers.go +++ b/internal/cli/unlockers.go @@ -41,11 +41,13 @@ func newUnlockersListCmd() *cobra.Command { cli := NewCLIInstance() cli.cmd = cmd + return cli.UnlockersList(jsonOutput) }, } cmd.Flags().Bool("json", false, "Output in JSON format") + return cmd } @@ -62,6 +64,7 @@ func newUnlockersAddCmd() *cobra.Command { } cmd.Flags().String("keyid", "", "GPG key ID for PGP unlockers") + return cmd } @@ -169,6 +172,7 @@ func (cli *Instance) UnlockersList(jsonOutput bool) error { case "pgp": unlocker = secret.NewPGPUnlocker(cli.fs, unlockerDir, diskMetadata) } + break } } @@ -208,6 +212,7 @@ func (cli *Instance) UnlockersList(jsonOutput bool) error { if len(unlockers) == 0 { cli.cmd.Println("No unlockers found in current vault.") cli.cmd.Println("Run 'secret unlockers add passphrase' to create one.") + return nil } @@ -263,6 +268,7 @@ func (cli *Instance) UnlockersAdd(unlockerType string, cmd *cobra.Command) error } cmd.Printf("Created passphrase unlocker: %s\n", passphraseUnlocker.GetID()) + return nil case "keychain": @@ -275,6 +281,7 @@ func (cli *Instance) UnlockersAdd(unlockerType string, cmd *cobra.Command) error if keyName, err := keychainUnlocker.GetKeychainItemName(); err == nil { cmd.Printf("Keychain Item Name: %s\n", keyName) } + return nil case "pgp": @@ -295,6 +302,7 @@ func (cli *Instance) UnlockersAdd(unlockerType string, cmd *cobra.Command) error cmd.Printf("Created PGP unlocker: %s\n", pgpUnlocker.GetID()) cmd.Printf("GPG Key ID: %s\n", gpgKeyID) + return nil default: diff --git a/internal/cli/vault.go b/internal/cli/vault.go index 287b07a..25a85c4 100644 --- a/internal/cli/vault.go +++ b/internal/cli/vault.go @@ -38,11 +38,13 @@ func newVaultListCmd() *cobra.Command { jsonOutput, _ := cmd.Flags().GetBool("json") cli := NewCLIInstance() + return cli.ListVaults(cmd, jsonOutput) }, } cmd.Flags().Bool("json", false, "Output in JSON format") + return cmd } @@ -83,6 +85,7 @@ func newVaultImportCmd() *cobra.Command { } cli := NewCLIInstance() + return cli.VaultImport(cmd, vaultName) }, } @@ -147,6 +150,7 @@ func (cli *Instance) CreateVault(cmd *cobra.Command, name string) error { } cmd.Printf("Created vault '%s'\n", vlt.GetName()) + return nil } @@ -157,6 +161,7 @@ func (cli *Instance) SelectVault(cmd *cobra.Command, name string) error { } cmd.Printf("Selected vault '%s' as current\n", name) + return nil } diff --git a/internal/cli/version.go b/internal/cli/version.go index aab6cc8..82f8aa4 100644 --- a/internal/cli/version.go +++ b/internal/cli/version.go @@ -48,6 +48,7 @@ func VersionCommands(cli *Instance) *cobra.Command { } versionCmd.AddCommand(listCmd, promoteCmd) + return versionCmd } @@ -154,6 +155,7 @@ func (cli *Instance) ListVersions(cmd *cobra.Command, secretName string) error { } w.Flush() + return nil } diff --git a/internal/secret/crypto.go b/internal/secret/crypto.go index c3c010d..29813cc 100644 --- a/internal/secret/crypto.go +++ b/internal/secret/crypto.go @@ -40,6 +40,7 @@ func EncryptToRecipient(data []byte, recipient age.Recipient) ([]byte, error) { result := buf.Bytes() Debug("EncryptToRecipient completed successfully", "result_length", len(result)) + return result, nil } diff --git a/internal/secret/debug.go b/internal/secret/debug.go index 1d4c6b9..2aeb948 100644 --- a/internal/secret/debug.go +++ b/internal/secret/debug.go @@ -113,6 +113,7 @@ func (h *colorizedHandler) Handle(_ context.Context, record slog.Record) error { } first = false output += fmt.Sprintf("%s=%#v", attr.Key, attr.Value.Any()) + return true }) output += "}\033[0m" @@ -120,6 +121,7 @@ func (h *colorizedHandler) Handle(_ context.Context, record slog.Record) error { output += "\n" _, err := h.output.Write([]byte(output)) + return err }