6119
My
mysis / files
mysis / internal / features / flags.go
2.7 KB
1package features 2 3import ( 4 "flag" 5 "os" 6 7 "github.com/xonecas/mysis/internal/config" 8) 9 10// Flags holds parsed command-line flags. 11type Flags struct { 12 ShowHelp bool 13 ShowVersion bool 14 ConfigPath string 15 Debug bool 16 ProviderName string 17 SessionName string 18 ListSessions bool 19 DeleteSession string 20 Autoplay string 21 SystemFile string 22 TUI bool 23} 24 25// ParseFlags parses command-line flags and returns the result. 26// This is display-agnostic - it only parses flags without printing or exiting. 27// The caller is responsible for handling ShowHelp and ShowVersion flags. 28func ParseFlags() *Flags { 29 var f Flags 30 31 flag.BoolVar(&f.ShowHelp, "help", false, "Show help and exit") 32 flag.BoolVar(&f.ShowHelp, "h", false, "Show help and exit (shorthand)") 33 flag.BoolVar(&f.ShowVersion, "version", false, "Show version and exit") 34 flag.BoolVar(&f.ShowVersion, "v", false, "Show version and exit (shorthand)") 35 flag.StringVar(&f.ConfigPath, "config", "", "Path to config file") 36 flag.StringVar(&f.ConfigPath, "c", "", "Path to config file (shorthand)") 37 flag.BoolVar(&f.Debug, "debug", false, "Enable debug logging") 38 flag.BoolVar(&f.Debug, "d", false, "Enable debug logging (shorthand)") 39 flag.StringVar(&f.ProviderName, "provider", "", "Provider name (overrides default from config)") 40 flag.StringVar(&f.ProviderName, "p", "", "Provider name (shorthand)") 41 flag.StringVar(&f.SessionName, "session", "", "Session name (resume or create named session)") 42 flag.StringVar(&f.SessionName, "s", "", "Session name (shorthand)") 43 flag.BoolVar(&f.ListSessions, "list-sessions", false, "List recent sessions and exit") 44 flag.BoolVar(&f.ListSessions, "l", false, "List recent sessions and exit (shorthand)") 45 flag.StringVar(&f.DeleteSession, "delete-session", "", "Delete a session by name") 46 flag.StringVar(&f.DeleteSession, "D", "", "Delete a session by name (shorthand)") 47 flag.StringVar(&f.Autoplay, "autoplay", "", "Start autoplay immediately with given message") 48 flag.StringVar(&f.Autoplay, "a", "", "Start autoplay immediately (shorthand)") 49 flag.StringVar(&f.SystemFile, "file", "", "Load system prompt from markdown file") 50 flag.StringVar(&f.SystemFile, "f", "", "Load system prompt from markdown file (shorthand)") 51 flag.BoolVar(&f.TUI, "tui", false, "Use terminal UI mode instead of CLI") 52 flag.BoolVar(&f.TUI, "t", false, "Use terminal UI mode (shorthand)") 53 54 // Disable default help behavior - caller will handle it 55 flag.Usage = func() {} 56 57 flag.Parse() 58 59 // Resolve config path if not specified 60 if f.ConfigPath == "" { 61 if _, err := os.Stat("config.toml"); err == nil { 62 f.ConfigPath = "config.toml" 63 } else { 64 dataDir, err := config.DataDir() 65 if err == nil { 66 f.ConfigPath = dataDir + "/config.toml" 67 } 68 } 69 } 70 71 return &f 72}