Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(root): fix flags logic at the root.go file
  • Loading branch information
danvergara committed Oct 21, 2025
commit 943a12e0e707c4ac70cc929d7fd77138453e071c
54 changes: 26 additions & 28 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,20 @@ func NewRootCmd() *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
var opts command.Options
var err error
var kb command.TUIKeyBindings
// Default keybindings.
var kb = command.TUIKeyBindings{
RunQuery: tcell.KeyCtrlSpace,
Structure: tcell.KeyCtrlS,
Indexes: tcell.KeyCtrlI,
Constraints: tcell.KeyCtrlT,
ClearEditor: tcell.KeyCtrlD,
Navigation: command.TUINavigationBindgins{
Up: tcell.KeyCtrlK,
Down: tcell.KeyCtrlJ,
Left: tcell.KeyCtrlH,
Right: tcell.KeyCtrlL,
},
}

if cfg {
opts, err = config.Init(cfgName)
Expand Down Expand Up @@ -100,33 +113,6 @@ func NewRootCmd() *cobra.Command {
SSHKeyPassphrase: sshKeyPassphrase,
}

// Default keybindings.
kb = command.TUIKeyBindings{
RunQuery: tcell.KeyCtrlSpace,
Structure: tcell.KeyCtrlS,
Indexes: tcell.KeyCtrlI,
Constraints: tcell.KeyCtrlT,
ClearEditor: tcell.KeyCtrlD,
Navigation: command.TUINavigationBindgins{
Up: tcell.KeyCtrlK,
Down: tcell.KeyCtrlJ,
Left: tcell.KeyCtrlH,
Right: tcell.KeyCtrlL,
},
}

// If the --keybindings flag is set, fill the keybindings with the ones fonud in the config file.
// This is safe to do even if they're missing in the config files, because the config package has default values for it.
if keybindings {
kb, err = config.SetupKeybindings()
if err != nil {
return err
}
}

// Set the keybindings values, either the default ones or the found in the config file.
opts.UpdateKeybindings(kb)

if form.IsEmpty(opts) {
opts, err = form.Run()
if err != nil {
Expand All @@ -135,6 +121,18 @@ func NewRootCmd() *cobra.Command {
}
}

// If the --keybindings flag is set, fill the keybindings with the ones fonud in the config file.
// This is safe to do even if they're missing in the config files, because the config package has default values for it.
if keybindings {
kb, err = config.SetupKeybindings()
if err != nil {
return err
}
}

// Set the keybindings values, either the default ones or the found in the config file.
opts.UpdateKeybindings(kb)

if err := connection.ValidateOpts(opts); err != nil {
return err
}
Expand Down