Skip to content

refactor: switch from Viper to go-flagsfiller - #108

Open
haseemajaz wants to merge 5 commits into
itzg:mainfrom
haseemajaz:refactor/flagsfiller
Open

haseemajaz wants to merge 5 commits into
itzg:mainfrom
haseemajaz:refactor/flagsfiller

Conversation

@haseemajaz

Copy link
Copy Markdown

Closes #107.

Switches rcon-cli from Viper to go-flagsfiller, and loads the config file directly with YAML instead of through Viper.

  • Same flags: --host, --port, --password, --abort-on-ctrl-c, --config.
  • Same env vars: RCON_HOST, RCON_PORT, RCON_PASSWORD, RCON_ABORT_ON_CTRL_C.
  • Same config file search order: --config path, then rcon-cli/config.yaml in the user config directory, then .rcon-cli.yaml in $HOME, /data, /server.
  • Same precedence: flags beat env, env beats config file, config file beats defaults.
  • Cobra stays; only the Viper parts are removed, so go.mod drops Viper and its indirect dependencies.

Behaviour change to note: the config file is now YAML-only. Viper also accepted json, toml and others, but YAML is the only format the README documents, so the loader reads .yaml/.yml.

How tested:

  • go test ./...: all packages pass (cmd, rcon).
  • go vet ./...: clean. gofmt -l .: clean.
  • New tests for config file loading and for flag/env/file/default precedence, including omitted keys keeping their values and a bool read from the file.
  • Manual: rcon-cli --help output compared with main (same flags, same defaults, env vars now shown); a config.yaml with host/port/password is honoured, and a flag overrides it.
  • go-flagsfiller v1.19.0, gopkg.in/yaml.v3 v3.0.1. No viper reference remains anywhere in the repo.

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.

Switch to flagsfiller

1 participant