Add comprehensive e2e tests for all CLI commands with mocked API responses. Fix test infrastructure to handle global state (os.Stdout capture, HOME env var) and broken test parallelism in stdout-capturing tests. - Add testutil_test.go with runFreshCommand, setupE2E, mockAPIServer - Add e2e_full_test.go with ~40 tests covering auth, mail, contacts, attachments, folders, labels, drafts, help output - Add newRootCmdBase() for fresh command trees per test - Remove t.Parallel() from stdout-capturing and HOME-dependent tests - Fix SessionWithMockSession to use runFreshCommand (stdout capture) Co-Authored-By: Paperclip <noreply@paperclip.ing>
68 lines
1.5 KiB
Go
68 lines
1.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "pop",
|
|
Short: "ProtonMail CLI tool",
|
|
Long: `pop is a CLI tool for interacting with ProtonMail.
|
|
|
|
It provides commands for managing emails, contacts, and attachments
|
|
with full PGP encryption support.`,
|
|
}
|
|
|
|
func newRootCmdBase() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "pop",
|
|
Short: "ProtonMail CLI tool",
|
|
Long: `pop is a CLI tool for interacting with ProtonMail.
|
|
|
|
It provides commands for managing emails, contacts, and attachments
|
|
with full PGP encryption support.`,
|
|
}
|
|
cmd.AddCommand(loginCmd())
|
|
cmd.AddCommand(logoutCmd())
|
|
cmd.AddCommand(sessionCmd())
|
|
cmd.AddCommand(mailCmd())
|
|
cmd.AddCommand(mailDraftCmd())
|
|
cmd.AddCommand(contactCmd())
|
|
cmd.AddCommand(attachmentCmd())
|
|
cmd.AddCommand(folderCmd())
|
|
cmd.AddCommand(labelCmd())
|
|
return cmd
|
|
}
|
|
|
|
func NewRootCmd() *cobra.Command {
|
|
rootCmd.AddCommand(loginCmd())
|
|
rootCmd.AddCommand(logoutCmd())
|
|
rootCmd.AddCommand(sessionCmd())
|
|
rootCmd.AddCommand(mailCmd())
|
|
rootCmd.AddCommand(mailDraftCmd())
|
|
rootCmd.AddCommand(contactCmd())
|
|
rootCmd.AddCommand(attachmentCmd())
|
|
rootCmd.AddCommand(folderCmd())
|
|
rootCmd.AddCommand(labelCmd())
|
|
return rootCmd
|
|
}
|
|
|
|
func init() {
|
|
cobra.OnInitialize(initConfig)
|
|
}
|
|
|
|
func initConfig() {
|
|
// Initialize config loading
|
|
// Config is loaded from ~/.config/pop/
|
|
}
|
|
|
|
func Execute() {
|
|
if err := rootCmd.Execute(); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
}
|