Files
whatshooked/cmd/cli/main.go
Hein 271a0603b8
Some checks failed
CI / Test (1.22) (push) Failing after -30m33s
CI / Test (1.23) (push) Failing after -30m32s
CI / Lint (push) Failing after -30m39s
CI / Build (push) Failing after -30m35s
feat(auth): enhance login flow with notifications and path normalization
- add success notification on successful login
- show error notification with detailed message on login failure
- normalize API paths to prevent double slashes and trailing slashes
- redirect to login page only if not on login request or page
2026-03-05 01:03:50 +02:00

62 lines
1.4 KiB
Go

package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var (
cfgFile string
serverURL string
cliConfig *CLIConfig
)
func main() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
var rootCmd = &cobra.Command{
Use: "whatshook-cli",
Short: "WhatsHooked CLI - Manage WhatsApp webhooks",
Long: `A command-line interface for managing WhatsHooked server, hooks, and WhatsApp accounts.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if shouldSkipConfigLoad(cmd) {
return
}
var err error
cliConfig, err = LoadCLIConfig(cfgFile, serverURL)
if err != nil {
fmt.Fprintf(os.Stderr, "Error loading config: %v\n", err)
os.Exit(1)
}
},
}
func init() {
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default: $HOME/.whatshooked/cli.json)")
rootCmd.PersistentFlags().StringVar(&serverURL, "server", "", "server URL (default: http://localhost:8825)")
// Add all command groups
rootCmd.AddCommand(healthCmd)
rootCmd.AddCommand(hooksCmd)
rootCmd.AddCommand(accountsCmd)
rootCmd.AddCommand(sendCmd)
rootCmd.AddCommand(usersCmd)
rootCmd.AddCommand(passwordHashCmd)
}
func shouldSkipConfigLoad(cmd *cobra.Command) bool {
for c := cmd; c != nil; c = c.Parent() {
if c.Annotations != nil && c.Annotations["skip-config-load"] == "true" {
return true
}
}
return false
}