Pi Dashboard TUI viewer — Go + Bubble Tea. Reads pi agent state files, cross-machine SSH pull, Enter=tmux attach, d=Hunk diff, Tab=Tuxedo tasks
This commit is contained in:
56
config.go
Normal file
56
config.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// Config holds the dashboard configuration
|
||||
type Config struct {
|
||||
PollInterval int `yaml:"poll_interval"` // in seconds
|
||||
Local struct {
|
||||
Path string `yaml:"path"`
|
||||
} `yaml:"local"`
|
||||
Remote []RemoteConfig `yaml:"remote"`
|
||||
}
|
||||
|
||||
// RemoteConfig holds SSH connection info for a remote machine
|
||||
type RemoteConfig struct {
|
||||
Host string `yaml:"host"`
|
||||
User string `yaml:"user"`
|
||||
Path string `yaml:"path"`
|
||||
Port int `yaml:"port"`
|
||||
}
|
||||
|
||||
func defaultConfig() Config {
|
||||
home, _ := os.UserHomeDir()
|
||||
return Config{
|
||||
PollInterval: 2,
|
||||
Local: struct {
|
||||
Path string `yaml:"path"`
|
||||
}{
|
||||
Path: filepath.Join(home, ".pi", "agent", "dashboard"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func loadConfig(path string) (Config, error) {
|
||||
cfg := defaultConfig()
|
||||
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return cfg, nil // use defaults
|
||||
}
|
||||
return cfg, fmt.Errorf("reading config: %w", err)
|
||||
}
|
||||
|
||||
if err := yaml.Unmarshal(data, &cfg); err != nil {
|
||||
return cfg, fmt.Errorf("parsing config: %w", err)
|
||||
}
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
Reference in New Issue
Block a user