fix: add --help/-h flag support to CLI and all subcommands

Fixes #562: picoclaw --help and -h now print help and exit 0 instead of
showing 'Unknown command'. No-args also exits 0.

Fixes #574: every subcommand (agent, auth, cron, gateway, onboard, status,
skills) now responds to --help/-h with usage info.
This commit is contained in:
Rahul Bansal 2026-02-21 10:23:44 +05:30
parent cf6831aec8
commit 51b591edda
7 changed files with 65 additions and 4 deletions

View file

@ -29,6 +29,18 @@ func agentCmd() {
args := os.Args[2:] args := os.Args[2:]
for i := 0; i < len(args); i++ { for i := 0; i < len(args); i++ {
switch args[i] { switch args[i] {
case "--help", "-h":
fmt.Println("Interact with the agent directly")
fmt.Println()
fmt.Println("Usage: picoclaw agent [options]")
fmt.Println()
fmt.Println("Options:")
fmt.Println(" -m, --message <text> Send a single message (non-interactive)")
fmt.Println(" -s, --session <key> Session key (default: cli:default)")
fmt.Println(" --model <model> Override the default model")
fmt.Println(" -d, --debug Enable debug logging")
fmt.Println(" -h, --help Show this help message")
return
case "--debug", "-d": case "--debug", "-d":
logger.SetLevel(logger.DEBUG) logger.SetLevel(logger.DEBUG)
fmt.Println("🔍 Debug mode enabled") fmt.Println("🔍 Debug mode enabled")

View file

@ -26,6 +26,8 @@ func authCmd() {
} }
switch os.Args[2] { switch os.Args[2] {
case "--help", "-h":
authHelp()
case "login": case "login":
authLoginCmd() authLoginCmd()
case "logout": case "logout":

View file

@ -18,6 +18,11 @@ func cronCmd() {
return return
} }
if os.Args[2] == "--help" || os.Args[2] == "-h" {
cronHelp()
return
}
subcommand := os.Args[2] subcommand := os.Args[2]
// Load config to get workspace path // Load config to get workspace path

View file

@ -28,13 +28,22 @@ import (
) )
func gatewayCmd() { func gatewayCmd() {
// Check for --debug flag // Check for flags
args := os.Args[2:] args := os.Args[2:]
for _, arg := range args { for _, arg := range args {
if arg == "--debug" || arg == "-d" { switch arg {
case "--help", "-h":
fmt.Println("Start the picoclaw gateway server")
fmt.Println()
fmt.Println("Usage: picoclaw gateway [options]")
fmt.Println()
fmt.Println("Options:")
fmt.Println(" -d, --debug Enable debug logging")
fmt.Println(" -h, --help Show this help message")
return
case "--debug", "-d":
logger.SetLevel(logger.DEBUG) logger.SetLevel(logger.DEBUG)
fmt.Println("🔍 Debug mode enabled") fmt.Println("🔍 Debug mode enabled")
break
} }
} }

View file

@ -18,6 +18,19 @@ import (
var embeddedFiles embed.FS var embeddedFiles embed.FS
func onboard() { func onboard() {
for _, arg := range os.Args[2:] {
switch arg {
case "--help", "-h":
fmt.Println("Initialize picoclaw configuration and workspace")
fmt.Println()
fmt.Println("Usage: picoclaw onboard")
fmt.Println()
fmt.Println("Creates the default config file and workspace directory.")
fmt.Println("If a config already exists, prompts before overwriting.")
return
}
}
configPath := getConfigPath() configPath := getConfigPath()
if _, err := os.Stat(configPath); err == nil { if _, err := os.Stat(configPath); err == nil {

View file

@ -11,6 +11,19 @@ import (
) )
func statusCmd() { func statusCmd() {
for _, arg := range os.Args[2:] {
switch arg {
case "--help", "-h":
fmt.Println("Show picoclaw status and configuration")
fmt.Println()
fmt.Println("Usage: picoclaw status")
fmt.Println()
fmt.Println("Displays version, config path, workspace path, configured")
fmt.Println("providers, and authentication status.")
return
}
}
cfg, err := loadConfig() cfg, err := loadConfig()
if err != nil { if err != nil {
fmt.Printf("Error loading config: %v\n", err) fmt.Printf("Error loading config: %v\n", err)

View file

@ -95,7 +95,7 @@ func copyDirectory(src, dst string) error {
func main() { func main() {
if len(os.Args) < 2 { if len(os.Args) < 2 {
printHelp() printHelp()
os.Exit(1) os.Exit(0)
} }
command := os.Args[1] command := os.Args[1]
@ -125,6 +125,11 @@ func main() {
subcommand := os.Args[2] subcommand := os.Args[2]
if subcommand == "--help" || subcommand == "-h" {
skillsHelp()
return
}
cfg, err := loadConfig() cfg, err := loadConfig()
if err != nil { if err != nil {
fmt.Printf("Error loading config: %v\n", err) fmt.Printf("Error loading config: %v\n", err)
@ -168,6 +173,8 @@ func main() {
} }
case "version", "--version", "-v": case "version", "--version", "-v":
printVersion() printVersion()
case "--help", "-h":
printHelp()
default: default:
fmt.Printf("Unknown command: %s\n", command) fmt.Printf("Unknown command: %s\n", command)
printHelp() printHelp()