Skip to content

fix: let CLI options take precedence over user settings#19

Merged
visciang merged 1 commit into
athonet-open:mainfrom
meox:fix/cli-opts-precedence
Jun 6, 2026
Merged

fix: let CLI options take precedence over user settings#19
visciang merged 1 commit into
athonet-open:mainfrom
meox:fix/cli-opts-precedence

Conversation

@meox

@meox meox commented Jun 6, 2026

Copy link
Copy Markdown

Problem

Options set in ~/.config/pix/settings.exs silently override values passed explicitly on the command line.

Each command handler merges the user settings on top of the parsed CLI options:

cli_opts = Keyword.merge(cli_opts, user_settings.command.shell.cli_opts)

Keyword.merge(a, b) gives precedence to the second argument, so the settings file wins over the CLI.

Reproduction

With a settings default:

%{command: %{shell: %{cli_opts: [ssh: "default=~/.ssh/id_ed25519_work"]}}}

running:

pix shell --ssh="default=~/.ssh/vm_key" dev_tools remote_load.sh my_service:latest 192.168.64.9

still mounts id_ed25519_work and discards the explicit --ssh value:

>>> mounting SSH key "/home/meox/.ssh/id_ed25519_work" as /root/.ssh/id_ed25519_work into shell container
root@192.168.64.9: Permission denied (publickey).

Fix

Swap the Keyword.merge argument order so user settings act as defaults and explicit CLI options take precedence:

cli_opts = Keyword.merge(user_settings.command.shell.cli_opts, cli_opts)

Applied consistently across all command handlers that perform this merge: shell, run, ls, graph, upgrade.

Notes

  • Options not provided on the CLI still fall back to the settings value, so existing settings.exs defaults keep working.
  • For multi-value (:keep) options such as ssh/secret/arg, an explicit CLI value now replaces the settings default for that key (CLI wins) rather than being clobbered by it.

Verification

  • mix compile --warnings-as-errors passes (pix app)
  • mix format --check-formatted passes

The command handlers merged user settings cli_opts on top of the
parsed CLI options via Keyword.merge(cli_opts, settings_opts). Since
Keyword.merge gives precedence to the second argument, any option set
in ~/.config/pix/settings.exs silently overrode the value passed
explicitly on the command line.

For example, with a settings default of
  shell: %{cli_opts: [ssh: "default=~/.ssh/id_ed25519_hpe"]}
running 'pix shell --ssh="default=~/.ssh/athonet" ...' would still
mount id_ed25519_hpe, discarding the CLI value.

Swap the merge order so settings act as defaults and explicit CLI
options win. Applies to shell, run, ls, graph and upgrade commands.
@visciang visciang merged commit d1b2c45 into athonet-open:main Jun 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants