aac139368f
Moves all packages from internal/ to pkg/ so they can be imported by external modules (needed for claude-pm integration). - internal/app/ → pkg/app/ - internal/docker/ → pkg/docker/ - internal/config/ → pkg/config/ - internal/utils/ → pkg/utils/ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
111 lines
3.4 KiB
Go
111 lines
3.4 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/oxker/oxker/pkg/config"
|
|
)
|
|
|
|
// CLIArgs represents parsed command-line arguments
|
|
type CLIArgs struct {
|
|
DockerIntervalMs int
|
|
RawLogs bool
|
|
ColorLogs bool
|
|
ShowTimestamp bool
|
|
ShowSelf bool
|
|
DebugMode bool
|
|
ConfigFile string
|
|
Host string
|
|
NoStdErr bool
|
|
SaveDir string
|
|
Timezone string
|
|
UseCLI bool
|
|
}
|
|
|
|
// ParseCLIArgs parses command-line arguments
|
|
func ParseCLIArgs() (*CLIArgs, error) {
|
|
args := &CLIArgs{}
|
|
|
|
// Define flags
|
|
flag.IntVar(&args.DockerIntervalMs, "d", 1000, "Minimum update interval for docker information in milliseconds")
|
|
flag.BoolVar(&args.RawLogs, "r", false, "Show raw logs (no ANSI formatting)")
|
|
flag.BoolVar(&args.ColorLogs, "c", false, "Attempt to color the logs")
|
|
flag.BoolVar(&args.ShowTimestamp, "t", false, "Remove timestamps from each log entry")
|
|
flag.BoolVar(&args.ShowSelf, "s", false, "Display the oxker container")
|
|
flag.BoolVar(&args.DebugMode, "g", false, "No TUI, debugging mode")
|
|
flag.StringVar(&args.ConfigFile, "config-file", "", "Location of config file (TOML/JSON/JSONC)")
|
|
flag.StringVar(&args.Host, "host", "", "Connect to Docker with a custom hostname")
|
|
flag.BoolVar(&args.NoStdErr, "no-stderr", false, "Do not include stderr output in logs")
|
|
flag.StringVar(&args.SaveDir, "save-dir", "", "Save exported logs into a custom directory")
|
|
flag.StringVar(&args.Timezone, "timezone", "", "Display Docker logs timestamps in a given timezone")
|
|
flag.BoolVar(&args.UseCLI, "use-cli", false, "Use Docker CLI when exec-ing into a container")
|
|
|
|
flag.Parse()
|
|
|
|
// Validate docker interval
|
|
if args.DockerIntervalMs < 1 {
|
|
return nil, fmt.Errorf("docker interval must be greater than 0")
|
|
}
|
|
|
|
// Handle conflicting log options
|
|
if args.RawLogs && args.ColorLogs {
|
|
args.RawLogs = false
|
|
}
|
|
|
|
return args, nil
|
|
}
|
|
|
|
// LoadConfig loads configuration from file or returns defaults
|
|
func LoadConfig(cliArgs *CLIArgs) (*config.Config, error) {
|
|
cfg := config.NewConfig()
|
|
|
|
// If config file specified, try to load it
|
|
if cliArgs.ConfigFile != "" {
|
|
path := cliArgs.ConfigFile
|
|
// Check if absolute or relative path
|
|
if !filepath.IsAbs(path) {
|
|
// Try relative to current directory
|
|
fullPath := filepath.Join(".", path)
|
|
if err := config.LoadConfigPath(fullPath, cfg); err != nil {
|
|
// Try relative to config directory
|
|
home, _ := os.UserHomeDir()
|
|
fullPath = filepath.Join(home, ".config", "oxker", path)
|
|
if err := config.LoadConfigPath(fullPath, cfg); err != nil {
|
|
return nil, fmt.Errorf("failed to load config file: %w", err)
|
|
}
|
|
}
|
|
} else {
|
|
if err := config.LoadConfigPath(path, cfg); err != nil {
|
|
return nil, fmt.Errorf("failed to load config file: %w", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Override with CLI args
|
|
if cliArgs.DockerIntervalMs > 0 {
|
|
cfg.DockerIntervalMs = cliArgs.DockerIntervalMs
|
|
}
|
|
cfg.RawLogs = cliArgs.RawLogs
|
|
cfg.ColorLogs = cliArgs.ColorLogs
|
|
cfg.ShowTimestamp = !cliArgs.ShowTimestamp
|
|
cfg.UseCLI = cliArgs.UseCLI
|
|
cfg.GUI = !cliArgs.DebugMode
|
|
if cliArgs.Host != "" {
|
|
cfg.Host = cliArgs.Host
|
|
}
|
|
cfg.DirConfig = cliArgs.ConfigFile
|
|
|
|
return cfg, nil
|
|
}
|
|
|
|
// ShowDebugInfo displays information in debug mode (no TUI)
|
|
func ShowDebugInfo(containers interface{}) {
|
|
// Debug mode - display basic information without TUI
|
|
fmt.Println("Oxker Debug Mode - Container Information")
|
|
fmt.Println("=========================================")
|
|
// TODO: Implement debug mode display
|
|
}
|