feat: add host actions, lifecycle hooks and operational tools
This commit is contained in:
1 parent
8d4915543e
commit
e5bde9c61f
32 files changed
+2083
-64
No files matched your search
@@ -95,6 +95,7 @@ func runMenu(cfg *config.Config) error {
|
||||
huh.NewOption("Resolver & cache", "resolver"),
|
||||
huh.NewOption("Shortcuts & command alias", "shortcuts"),
|
||||
huh.NewOption("Custom commands — mtr, ping, scripts", "commands"),
|
||||
huh.NewOption("History & activity logging", "operations"),
|
||||
huh.NewOption("Completion", "completion"),
|
||||
huh.NewOption("Save and exit", "save"),
|
||||
).
|
||||
@@ -125,6 +126,8 @@ func runMenu(cfg *config.Config) error {
|
||||
err = editShortcuts(cfg)
|
||||
case "commands":
|
||||
err = editCommands(cfg)
|
||||
case "operations":
|
||||
err = editOperations(cfg)
|
||||
case "completion":
|
||||
err = editCompletion(cfg)
|
||||
case "save":
|
||||
@@ -382,6 +385,9 @@ func save(cfg config.Config) error {
|
||||
if err := cfg.ValidateHosts(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cfg.ValidateOperations(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cfg.ValidateCommands(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -552,9 +558,19 @@ func save(cfg config.Config) error {
|
||||
for _, arg := range command.Args {
|
||||
fmt.Fprintf(&b, " - %q\n", arg)
|
||||
}
|
||||
fmt.Fprintf(&b, " confirm: %t\n timeout: %q\n post_run: %q\n", command.Confirm, command.Timeout, command.PostRun)
|
||||
if command.Match != (config.SSHMatch{}) {
|
||||
b.WriteString(" match:\n")
|
||||
for _, pair := range [][2]string{{"tag", command.Match.Tag}, {"instance", command.Match.Instance}, {"kind", command.Match.Kind}, {"name", command.Match.Name}} {
|
||||
if pair[1] != "" {
|
||||
fmt.Fprintf(&b, " %s: %q\n", pair[0], pair[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(&b, "\ntui:\n history_limit: %d\nactivity:\n enabled: %t\n retention_days: %d\n max_entries: %d\n", cfg.TUI.HistoryLimit, cfg.Activity.Enabled, cfg.Activity.RetentionDays, cfg.Activity.MaxEntries)
|
||||
if cfg.Shell.Alias != "" {
|
||||
fmt.Fprintf(&b, "\nshell:\n alias: %q\n", cfg.Shell.Alias)
|
||||
}
|
||||
@@ -568,12 +584,12 @@ func save(cfg config.Config) error {
|
||||
}
|
||||
|
||||
func sshOptionsEmpty(o config.SSHOptions) bool {
|
||||
return o.ProxyJump == "" && o.HostKeyChecking == "" && o.Target == "" && o.AddressFamily == "" && len(o.ExtraArgs) == 0 && len(o.Options) == 0 && len(o.Forwards) == 0 && o.PreConnect == ""
|
||||
return o.ProxyJump == "" && o.HostKeyChecking == "" && o.Target == "" && o.AddressFamily == "" && len(o.ExtraArgs) == 0 && len(o.Options) == 0 && len(o.Forwards) == 0 && o.PreConnect == "" && o.PostDisconnect == ""
|
||||
}
|
||||
|
||||
// writeSSHOptions keeps settings the wizard does not ask for when it rewrites the config.
|
||||
func writeSSHOptions(b *strings.Builder, indent string, o config.SSHOptions) {
|
||||
for _, field := range [][2]string{{"proxy_jump", o.ProxyJump}, {"host_key_checking", o.HostKeyChecking}, {"target", o.Target}, {"address_family", o.AddressFamily}, {"pre_connect", o.PreConnect}} {
|
||||
for _, field := range [][2]string{{"proxy_jump", o.ProxyJump}, {"host_key_checking", o.HostKeyChecking}, {"target", o.Target}, {"address_family", o.AddressFamily}, {"pre_connect", o.PreConnect}, {"post_disconnect", o.PostDisconnect}} {
|
||||
if field[1] != "" {
|
||||
fmt.Fprintf(b, "%s%s: %q\n", indent, field[0], field[1])
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user