feat: complete Rust-to-Go rewrite with Bubbletea v2
Rewrites oxker from Rust/ratatui to Go/Bubbletea, migrated to the Bubbletea v2 API (charm.land/bubbletea/v2). Removes all original Rust source files and legacy Go modules (internal/ui, internal/input, bubbles). Key changes: - View() returns tea.View with declarative AltScreen and MouseMode - KeyMsg → KeyPressMsg, MouseMsg → MouseClickMsg/WheelMsg/MotionMsg/ReleaseMsg - execWriteKey rewritten for v2 key fields (Code/Mod/Text) - Mouse toggle via View field instead of imperative commands - Filter/search text input uses msg.Text for v2 space key compat Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/oxker/oxker/internal/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
|
||||
}
|
||||
Reference in New Issue
Block a user