├── .envrc ├── opt-env-conf-test ├── test_resources │ ├── docs │ │ ├── empty │ │ │ ├── env.txt │ │ │ ├── config.txt │ │ │ ├── opt-long.txt │ │ │ ├── show.txt │ │ │ ├── config-docs.txt │ │ │ ├── docs.txt │ │ │ ├── env-docs.txt │ │ │ ├── opt-docs.txt │ │ │ ├── opt-short.txt │ │ │ ├── nix-options.nix │ │ │ ├── version.txt │ │ │ ├── help.txt │ │ │ ├── reference.txt │ │ │ └── man.txt │ │ ├── hidden │ │ │ ├── env.txt │ │ │ ├── config.txt │ │ │ ├── opt-long.txt │ │ │ ├── config-docs.txt │ │ │ ├── env-docs.txt │ │ │ ├── opt-docs.txt │ │ │ ├── opt-short.txt │ │ │ ├── docs.txt │ │ │ ├── nix-options.nix │ │ │ ├── version.txt │ │ │ ├── help.txt │ │ │ ├── reference.txt │ │ │ ├── show.txt │ │ │ └── man.txt │ │ ├── verbose │ │ │ ├── env.txt │ │ │ ├── config.txt │ │ │ ├── config-docs.txt │ │ │ ├── env-docs.txt │ │ │ ├── nix-options.nix │ │ │ ├── version.txt │ │ │ ├── opt-short.txt │ │ │ ├── opt-long.txt │ │ │ ├── help.txt │ │ │ ├── opt-docs.txt │ │ │ ├── show.txt │ │ │ ├── docs.txt │ │ │ ├── man.txt │ │ │ └── reference.txt │ │ ├── many-args │ │ │ ├── config.txt │ │ │ ├── env.txt │ │ │ ├── env-docs.txt │ │ │ ├── config-docs.txt │ │ │ ├── nix-options.nix │ │ │ ├── version.txt │ │ │ ├── opt-long.txt │ │ │ ├── opt-short.txt │ │ │ ├── show.txt │ │ │ ├── help.txt │ │ │ ├── opt-docs.txt │ │ │ ├── docs.txt │ │ │ ├── man.txt │ │ │ └── reference.txt │ │ ├── optional │ │ │ ├── config.txt │ │ │ ├── env.txt │ │ │ ├── env-docs.txt │ │ │ ├── config-docs.txt │ │ │ ├── nix-options.nix │ │ │ ├── version.txt │ │ │ ├── opt-long.txt │ │ │ ├── opt-short.txt │ │ │ ├── help.txt │ │ │ ├── opt-docs.txt │ │ │ ├── show.txt │ │ │ ├── man.txt │ │ │ ├── docs.txt │ │ │ └── reference.txt │ │ ├── some-args │ │ │ ├── config.txt │ │ │ ├── env.txt │ │ │ ├── env-docs.txt │ │ │ ├── config-docs.txt │ │ │ ├── nix-options.nix │ │ │ ├── version.txt │ │ │ ├── opt-short.txt │ │ │ ├── opt-long.txt │ │ │ ├── help.txt │ │ │ ├── show.txt │ │ │ ├── man.txt │ │ │ ├── reference.txt │ │ │ ├── opt-docs.txt │ │ │ └── docs.txt │ │ ├── with-default │ │ │ ├── env.txt │ │ │ ├── config.txt │ │ │ ├── config-docs.txt │ │ │ ├── env-docs.txt │ │ │ ├── nix-options.nix │ │ │ ├── version.txt │ │ │ ├── opt-short.txt │ │ │ ├── opt-long.txt │ │ │ ├── help.txt │ │ │ ├── man.txt │ │ │ ├── show.txt │ │ │ ├── opt-docs.txt │ │ │ ├── reference.txt │ │ │ └── docs.txt │ │ ├── greet │ │ │ ├── version.txt │ │ │ ├── opt-short.txt │ │ │ ├── config.txt │ │ │ ├── nix-options.nix │ │ │ ├── env.txt │ │ │ ├── opt-long.txt │ │ │ ├── env-docs.txt │ │ │ ├── config-docs.txt │ │ │ ├── help.txt │ │ │ ├── opt-docs.txt │ │ │ └── man.txt │ │ ├── secret │ │ │ ├── version.txt │ │ │ ├── opt-short.txt │ │ │ ├── opt-long.txt │ │ │ ├── env.txt │ │ │ ├── nix-options.nix │ │ │ ├── config.txt │ │ │ ├── config-docs.txt │ │ │ ├── help.txt │ │ │ └── env-docs.txt │ │ ├── yes-no │ │ │ ├── version.txt │ │ │ ├── opt-short.txt │ │ │ ├── opt-long.txt │ │ │ ├── env.txt │ │ │ ├── config.txt │ │ │ ├── nix-options.nix │ │ │ ├── config-docs.txt │ │ │ ├── env-docs.txt │ │ │ ├── help.txt │ │ │ ├── opt-docs.txt │ │ │ ├── man.txt │ │ │ ├── reference.txt │ │ │ └── docs.txt │ │ ├── same-help │ │ │ ├── version.txt │ │ │ ├── opt-short.txt │ │ │ ├── opt-long.txt │ │ │ ├── env.txt │ │ │ ├── config.txt │ │ │ ├── nix-options.nix │ │ │ ├── config-docs.txt │ │ │ ├── help.txt │ │ │ ├── man.txt │ │ │ ├── env-docs.txt │ │ │ ├── opt-docs.txt │ │ │ └── reference.txt │ │ ├── sum-type │ │ │ ├── version.txt │ │ │ ├── env.txt │ │ │ ├── opt-long.txt │ │ │ ├── opt-short.txt │ │ │ ├── config.txt │ │ │ ├── nix-options.nix │ │ │ ├── config-docs.txt │ │ │ ├── env-docs.txt │ │ │ ├── help.txt │ │ │ ├── man.txt │ │ │ ├── opt-docs.txt │ │ │ └── reference.txt │ │ ├── big-config │ │ │ ├── version.txt │ │ │ ├── opt-long.txt │ │ │ ├── opt-short.txt │ │ │ ├── env.txt │ │ │ ├── config-docs.txt │ │ │ ├── config.txt │ │ │ ├── nix-options.nix │ │ │ ├── opt-docs.txt │ │ │ ├── help.txt │ │ │ ├── man.txt │ │ │ ├── env-docs.txt │ │ │ ├── reference.txt │ │ │ └── docs.txt │ │ ├── enable-disable │ │ │ ├── version.txt │ │ │ ├── env.txt │ │ │ ├── opt-short.txt │ │ │ ├── opt-long.txt │ │ │ ├── config.txt │ │ │ ├── nix-options.nix │ │ │ ├── config-docs.txt │ │ │ ├── env-docs.txt │ │ │ ├── opt-docs.txt │ │ │ ├── help.txt │ │ │ ├── man.txt │ │ │ ├── reference.txt │ │ │ └── docs.txt │ │ ├── sub-commands │ │ │ ├── version.txt │ │ │ ├── opt-short.txt │ │ │ ├── config.txt │ │ │ ├── nix-options.nix │ │ │ ├── env.txt │ │ │ ├── opt-long.txt │ │ │ ├── help.txt │ │ │ ├── man.txt │ │ │ ├── env-docs.txt │ │ │ ├── reference.txt │ │ │ └── config-docs.txt │ │ ├── sub-settings │ │ │ ├── version.txt │ │ │ ├── opt-short.txt │ │ │ ├── config.txt │ │ │ ├── opt-long.txt │ │ │ ├── env.txt │ │ │ ├── env-docs.txt │ │ │ ├── nix-options.nix │ │ │ ├── config-docs.txt │ │ │ ├── help.txt │ │ │ ├── opt-docs.txt │ │ │ ├── man.txt │ │ │ ├── reference.txt │ │ │ ├── docs.txt │ │ │ └── show.txt │ │ ├── three-commands │ │ │ ├── opt-short.txt │ │ │ ├── version.txt │ │ │ ├── env.txt │ │ │ ├── config.txt │ │ │ ├── nix-options.nix │ │ │ ├── opt-long.txt │ │ │ ├── help.txt │ │ │ ├── config-docs.txt │ │ │ ├── man.txt │ │ │ ├── env-docs.txt │ │ │ ├── reference.txt │ │ │ └── opt-docs.txt │ │ ├── yes-no-optional │ │ │ ├── version.txt │ │ │ ├── env.txt │ │ │ ├── opt-long.txt │ │ │ ├── opt-short.txt │ │ │ ├── config.txt │ │ │ ├── nix-options.nix │ │ │ ├── config-docs.txt │ │ │ ├── env-docs.txt │ │ │ ├── help.txt │ │ │ ├── opt-docs.txt │ │ │ ├── man.txt │ │ │ ├── reference.txt │ │ │ └── docs.txt │ │ └── enable-disable-optional │ │ │ ├── version.txt │ │ │ ├── env.txt │ │ │ ├── opt-long.txt │ │ │ ├── opt-short.txt │ │ │ ├── config.txt │ │ │ ├── nix-options.nix │ │ │ ├── config-docs.txt │ │ │ ├── env-docs.txt │ │ │ ├── opt-docs.txt │ │ │ ├── help.txt │ │ │ ├── man.txt │ │ │ ├── reference.txt │ │ │ └── docs.txt │ ├── error │ │ ├── typo-switch.txt │ │ ├── typo-option.txt │ │ ├── unrecognised-arg.txt │ │ ├── leftover-argument.txt │ │ ├── leftover-option.txt │ │ ├── leftover-switch.txt │ │ ├── unrecognised-switch.txt │ │ ├── unrecognised-option.txt │ │ ├── check-failed-checkEither.txt │ │ ├── some-none.txt │ │ ├── empty.txt │ │ ├── missing-option.txt │ │ ├── missing-argument.txt │ │ ├── unfolding-tombstone-option.txt │ │ ├── unfolding-tombstone-switch.txt │ │ ├── empty-choice.txt │ │ ├── missing-env.txt │ │ ├── missing-var.txt │ │ ├── check-failed-checkMaybe.txt │ │ ├── read-int-option.txt │ │ ├── read-int-argument.txt │ │ ├── required-command.txt │ │ ├── unreadable-var.txt │ │ ├── missing-options.txt │ │ ├── unrecognised-command.txt │ │ ├── missing-vars.txt │ │ ├── read-int-options.txt │ │ ├── unreadable-vars.txt │ │ ├── all-or-nothing.txt │ │ └── all-or-nothing-relevant.txt │ ├── help │ │ ├── sub-bar.txt │ │ ├── sub-foo.txt │ │ ├── read.txt │ │ ├── create.txt │ │ ├── sub.txt │ │ ├── toplevel-pure.txt │ │ ├── wrong-command.txt │ │ └── toplevel-pure-with-invalid-port.txt │ ├── lint │ │ ├── no-commands.txt │ │ ├── no-reader-for-argument.txt │ │ ├── no-metavar-for-argument.txt │ │ ├── no-dashed-for-option.txt │ │ ├── no-dashed-for-switch.txt │ │ ├── no-metavar-for-env.txt │ │ ├── many-conf.txt │ │ ├── many-env.txt │ │ ├── no-metavar-for-option.txt │ │ ├── no-reader-for-option.txt │ │ ├── some-conf.txt │ │ ├── some-env.txt │ │ ├── dash-in-short.txt │ │ ├── unknown-default-command.txt │ │ ├── no-option-or-switch-for-dashed.txt │ │ ├── dash-in-long.txt │ │ ├── unreadable-example.txt │ │ ├── only-default.txt │ │ ├── empty-setting.txt │ │ ├── config-without-load.txt │ │ ├── no-reader-for-env.txt │ │ └── null-setting.txt │ └── completion │ │ ├── bash-completion-script.bash │ │ ├── fish-completion-script.fish │ │ └── zsh-completion-script.zsh ├── test │ ├── Spec.hs │ └── OptEnvConf │ │ ├── EnvMapSpec.hs │ │ ├── TestUtils.hs │ │ ├── NonDetSpec.hs │ │ ├── ReaderSpec.hs │ │ └── ToplevelSpec.hs ├── LICENSE.md ├── src │ └── OptEnvConf │ │ ├── EnvMap │ │ └── Gen.hs │ │ └── Args │ │ └── Gen.hs ├── CHANGELOG.md ├── default.nix └── package.yaml ├── opt-env-conf-example ├── test │ └── Spec.hs ├── app │ └── Main.hs ├── default.nix ├── package.yaml ├── options.nix └── opt-env-conf-example.cabal ├── .gitignore ├── weeder.toml ├── .hlint.yaml ├── nix └── overlay.nix ├── opt-env-conf ├── src │ └── OptEnvConf │ │ ├── Terminal.hs │ │ ├── EnvMap.hs │ │ ├── Casing.hs │ │ └── Capability.hs ├── default.nix ├── package.yaml └── opt-env-conf.cabal ├── stack.yaml └── TODO.smos /.envrc: -------------------------------------------------------------------------------- 1 | use flake 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/empty/env.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/hidden/env.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/verbose/env.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/empty/config.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/empty/opt-long.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/empty/show.txt: -------------------------------------------------------------------------------- 1 | Pure _ -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/hidden/config.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/hidden/opt-long.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/many-args/config.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/many-args/env.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/optional/config.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/optional/env.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/some-args/config.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/some-args/env.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/verbose/config.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/with-default/env.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/with-default/config.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/empty/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd [] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/empty/docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsSingle Nothing -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/empty/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd [] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/empty/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd [] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/empty/opt-short.txt: -------------------------------------------------------------------------------- 1 | empty -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/hidden/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd [] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/hidden/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd [] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/hidden/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd [] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/hidden/opt-short.txt: -------------------------------------------------------------------------------- 1 | hidden -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/many-args/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr [] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/optional/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr [] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/some-args/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr [] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/verbose/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr [] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/verbose/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr [] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/hidden/docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsSingle Nothing -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/many-args/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr [] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/optional/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr [] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/some-args/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr [] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/with-default/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr [] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/with-default/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr [] -------------------------------------------------------------------------------- /opt-env-conf-example/test/Spec.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -F -pgmF sydtest-discover #-} 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test/Spec.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -F -pgmF sydtest-discover #-} 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/empty/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { } 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/empty/version.txt: -------------------------------------------------------------------------------- 1 | empty 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/greet/version.txt: -------------------------------------------------------------------------------- 1 | greet 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/hidden/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { } 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/hidden/version.txt: -------------------------------------------------------------------------------- 1 | hidden 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/optional/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { } 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/secret/version.txt: -------------------------------------------------------------------------------- 1 | secret 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/verbose/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { } 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no/version.txt: -------------------------------------------------------------------------------- 1 | yes-no 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/typo-switch.txt: -------------------------------------------------------------------------------- 1 | Unrecognised args: --baz 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/many-args/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { } 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/many-args/version.txt: -------------------------------------------------------------------------------- 1 | many-args 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/optional/version.txt: -------------------------------------------------------------------------------- 1 | optional 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/same-help/version.txt: -------------------------------------------------------------------------------- 1 | same-help 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/some-args/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { } 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/some-args/version.txt: -------------------------------------------------------------------------------- 1 | some-args 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sum-type/version.txt: -------------------------------------------------------------------------------- 1 | sum-type 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/verbose/version.txt: -------------------------------------------------------------------------------- 1 | verbose 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/with-default/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { } 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/typo-option.txt: -------------------------------------------------------------------------------- 1 | Unrecognised args: --baz arg 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/unrecognised-arg.txt: -------------------------------------------------------------------------------- 1 | Unrecognised args: arg 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/big-config/version.txt: -------------------------------------------------------------------------------- 1 | big-config 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/leftover-argument.txt: -------------------------------------------------------------------------------- 1 | Unrecognised args: foo bar 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/leftover-option.txt: -------------------------------------------------------------------------------- 1 | Unrecognised args: --key val 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/leftover-switch.txt: -------------------------------------------------------------------------------- 1 | Unrecognised args: --switch 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/unrecognised-switch.txt: -------------------------------------------------------------------------------- 1 | Unrecognised args: --foo 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | stack.yaml.lock 2 | .stack-work/ 3 | .direnv 4 | .pre-commit-config.yaml 5 | result 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable/version.txt: -------------------------------------------------------------------------------- 1 | enable-disable 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-commands/version.txt: -------------------------------------------------------------------------------- 1 | sub-commands 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-settings/version.txt: -------------------------------------------------------------------------------- 1 | sub-settings 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/three-commands/opt-short.txt: -------------------------------------------------------------------------------- 1 | three-commands [COMMAND] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/three-commands/version.txt: -------------------------------------------------------------------------------- 1 | three-commands 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/with-default/version.txt: -------------------------------------------------------------------------------- 1 | with-default 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/unrecognised-option.txt: -------------------------------------------------------------------------------- 1 | Unrecognised args: --foo bar 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/many-args/opt-long.txt: -------------------------------------------------------------------------------- 1 | ARGUMENT Argument 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/optional/opt-long.txt: -------------------------------------------------------------------------------- 1 | ARGUMENT Argument 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/verbose/opt-short.txt: -------------------------------------------------------------------------------- 1 | verbose [-v] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no-optional/version.txt: -------------------------------------------------------------------------------- 1 | yes-no-optional 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/check-failed-checkEither.txt: -------------------------------------------------------------------------------- 1 | Check failed: 2 | example error 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/many-args/opt-short.txt: -------------------------------------------------------------------------------- 1 | many-args [ARGUMENT] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/optional/opt-short.txt: -------------------------------------------------------------------------------- 1 | optional [ARGUMENT] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sum-type/env.txt: -------------------------------------------------------------------------------- 1 | sum-type SUM_TYPE example 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sum-type/opt-long.txt: -------------------------------------------------------------------------------- 1 | -a a 2 | -b b 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no/opt-short.txt: -------------------------------------------------------------------------------- 1 | yes-no [--[no-]example] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/some-none.txt: -------------------------------------------------------------------------------- 1 | Missing argument: METAVAR undocumented 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable-optional/version.txt: -------------------------------------------------------------------------------- 1 | enable-disable-optional 0.0.0 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/empty.txt: -------------------------------------------------------------------------------- 1 | Hit the 'empty' case of the Parser type, this should not happen. 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/missing-option.txt: -------------------------------------------------------------------------------- 1 | Missing option: --foo example option 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no/opt-long.txt: -------------------------------------------------------------------------------- 1 | --[no-]example Example of a yes/no switch 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/missing-argument.txt: -------------------------------------------------------------------------------- 1 | Missing argument: ARGUMENT example argument 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/unfolding-tombstone-option.txt: -------------------------------------------------------------------------------- 1 | Missing option: -b undocumented 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/unfolding-tombstone-switch.txt: -------------------------------------------------------------------------------- 1 | Missing option: -f undocumented 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/big-config/opt-long.txt: -------------------------------------------------------------------------------- 1 | --config-file Path to the configuration file 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sum-type/opt-short.txt: -------------------------------------------------------------------------------- 1 | sum-type [-a | -b] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no/env.txt: -------------------------------------------------------------------------------- 1 | EXAMPLE BOOL Example of a yes/no switch 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/empty-choice.txt: -------------------------------------------------------------------------------- 1 | Hit the 'empty' case of the Parser type, this should not happen. 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/some-args/opt-short.txt: -------------------------------------------------------------------------------- 1 | some-args ARGUMENT [ARGUMENT] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no-optional/env.txt: -------------------------------------------------------------------------------- 1 | EXAMPLE BOOL Example of a yes/no switch 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no-optional/opt-long.txt: -------------------------------------------------------------------------------- 1 | --[no-]example Example of a yes/no switch 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no-optional/opt-short.txt: -------------------------------------------------------------------------------- 1 | yes-no-optional [--[no-]example] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/missing-env.txt: -------------------------------------------------------------------------------- 1 | Missing env var: 2 | FOO METAVAR 3 | undocumented 4 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/missing-var.txt: -------------------------------------------------------------------------------- 1 | Missing env var: 2 | FOO METAVAR 3 | undocumented 4 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/big-config/opt-short.txt: -------------------------------------------------------------------------------- 1 | big-config [--config-file FILE_PATH] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/verbose/opt-long.txt: -------------------------------------------------------------------------------- 1 | -v Verbosity level. Use multiple to increase verbosity 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/big-config/env.txt: -------------------------------------------------------------------------------- 1 | CONFIG_FILE FILE_PATH Path to the configuration file 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable/env.txt: -------------------------------------------------------------------------------- 1 | EXAMPLE BOOL Example of an enable/disable switch 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable/opt-short.txt: -------------------------------------------------------------------------------- 1 | enable-disable [--(enable|disable)-example] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/some-args/opt-long.txt: -------------------------------------------------------------------------------- 1 | ARGUMENT Argument 2 | ARGUMENT Argument 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/check-failed-checkMaybe.txt: -------------------------------------------------------------------------------- 1 | Check failed: 2 | checkMapMaybe failed without a helpful error message 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable-optional/env.txt: -------------------------------------------------------------------------------- 1 | EXAMPLE BOOL Example of an enable/disable switch 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable/opt-long.txt: -------------------------------------------------------------------------------- 1 | --(enable|disable)-example Example of an enable/disable switch 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-commands/opt-short.txt: -------------------------------------------------------------------------------- 1 | sub-commands [--config-file FILE_PATH] COMMAND -------------------------------------------------------------------------------- /opt-env-conf-example/app/Main.hs: -------------------------------------------------------------------------------- 1 | module Main (main) where 2 | 3 | import OptEnvConf.Example (exampleMain) 4 | 5 | main :: IO () 6 | main = exampleMain 7 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sum-type/config.txt: -------------------------------------------------------------------------------- 1 | example 2 | sum-type: 3 | # or null 4 |  5 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/read-int-option.txt: -------------------------------------------------------------------------------- 1 | Failed to read option: 2 | --num integer option 3 | Un-Read-able value: "five" 4 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable-optional/opt-long.txt: -------------------------------------------------------------------------------- 1 | --(enable|disable)-example Example of an enable/disable switch 2 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable-optional/opt-short.txt: -------------------------------------------------------------------------------- 1 | enable-disable-optional [--(enable|disable)-example] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/read-int-argument.txt: -------------------------------------------------------------------------------- 1 | Failed to read argument: 2 | INT integer option 3 | Un-Read-able value: "five" 4 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/required-command.txt: -------------------------------------------------------------------------------- 1 | Missing command, available commands: 2 | one: first 3 | two: second 4 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no/config.txt: -------------------------------------------------------------------------------- 1 | Example of a yes/no switch 2 | example: 3 | # or null 4 |  5 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/unreadable-var.txt: -------------------------------------------------------------------------------- 1 | Failed to read env var: 2 | FOO METAVAR 3 | undocumented 4 | Un-Read-able value: "n" 5 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-settings/opt-short.txt: -------------------------------------------------------------------------------- 1 | sub-settings [--config-file FILE_PATH] --foo-bar-quux STR -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/missing-options.txt: -------------------------------------------------------------------------------- 1 | Missing option: --foo example option 1 2 | Missing option: --bar example option 2 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-commands/config.txt: -------------------------------------------------------------------------------- 1 | name 2 | example: john 3 | name: 4 | # or null 5 |  6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-settings/config.txt: -------------------------------------------------------------------------------- 1 | Example with sub-settings 2 | foo.bar.quux: 3 | # or null 4 |  5 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no-optional/config.txt: -------------------------------------------------------------------------------- 1 | Example of a yes/no switch 2 | example: 3 | # or null 4 |  5 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable/config.txt: -------------------------------------------------------------------------------- 1 | Example of an enable/disable switch 2 | example: 3 | # or null 4 |  5 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable-optional/config.txt: -------------------------------------------------------------------------------- 1 | Example of an enable/disable switch 2 | example: 3 | # or null 4 |  5 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/same-help/opt-short.txt: -------------------------------------------------------------------------------- 1 | same-help [--int INT | --string STR] [--[no-]other] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-settings/opt-long.txt: -------------------------------------------------------------------------------- 1 | --config-file Path to the configuration file 2 | --foo-bar-quux Example with sub-settings 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/with-default/opt-short.txt: -------------------------------------------------------------------------------- 1 | with-default [-f|--first | [-s|--second]] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/same-help/opt-long.txt: -------------------------------------------------------------------------------- 1 | --int int or string 2 | --string int or string 3 | --[no-]other int or string 4 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/three-commands/env.txt: -------------------------------------------------------------------------------- 1 | NUMBER INT number example: 5 2 | ENABLE BOOL enable extra 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/unrecognised-command.txt: -------------------------------------------------------------------------------- 1 | Unrecognised command: three 2 | available commands: 3 | one: first 4 | two: second 5 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/missing-vars.txt: -------------------------------------------------------------------------------- 1 | Missing env var: 2 | FOO METAVAR 3 | undocumented 4 | Missing env var: 5 | BAR METAVAR 6 | undocumented 7 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/with-default/opt-long.txt: -------------------------------------------------------------------------------- 1 | -f|--first first 2 | -s|--second second default: Second 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/same-help/env.txt: -------------------------------------------------------------------------------- 1 | INT INT int or string 2 | STRING STR int or string 3 | OTHER BOOL int or string 4 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-settings/env.txt: -------------------------------------------------------------------------------- 1 | CONFIG_FILE FILE_PATH Path to the configuration file 2 | FOO_BAR_QUUX STR Example with sub-settings 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/LICENSE.md: -------------------------------------------------------------------------------- 1 | # Sydtest License 2 | 3 | Copyright (c) 2024 Tom Sydney Kerckhove 4 | 5 | See the Sydtest License at https://github.com/NorfairKing/sydtest/blob/master/sydtest/LICENSE.md for the full license text. 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-commands/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { 3 | name = lib.mkOption { 4 | default = null; 5 | description = "name"; 6 | type = lib.types.nullOr lib.types.str; 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sum-type/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { 3 | sum-type = lib.mkOption { 4 | default = null; 5 | description = "example"; 6 | type = lib.types.nullOr lib.types.str; 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /weeder.toml: -------------------------------------------------------------------------------- 1 | unused-types = true 2 | type-class-roots = false 3 | roots = [ 4 | "^Main.main", 5 | # Generated 6 | "Paths_", 7 | ] 8 | root-instances = [ 9 | {class = 'IsString'}, 10 | {class = 'IsList'}, 11 | ] 12 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/help/sub-bar.txt: -------------------------------------------------------------------------------- 1 | Usage: example sub bar 2 | 3 | bar explanation 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/help/sub-foo.txt: -------------------------------------------------------------------------------- 1 | Usage: example sub foo 2 | 3 | foo explanation 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/help/read.txt: -------------------------------------------------------------------------------- 1 | Usage: example read 2 | 3 | read command explanation 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { 3 | example = lib.mkOption { 4 | default = null; 5 | description = "Example of a yes/no switch"; 6 | type = lib.types.nullOr lib.types.bool; 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no-optional/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { 3 | example = lib.mkOption { 4 | default = null; 5 | description = "Example of a yes/no switch"; 6 | type = lib.types.nullOr lib.types.bool; 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/read-int-options.txt: -------------------------------------------------------------------------------- 1 | Failed to read option: 2 | --foo integer option 1 3 | Un-Read-able value: "n" 4 | Failed to read option: 5 | --bar integer option 2 6 | Un-Read-able value: "m" 7 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { 3 | example = lib.mkOption { 4 | default = null; 5 | description = "Example of an enable/disable switch"; 6 | type = lib.types.nullOr lib.types.bool; 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-commands/env.txt: -------------------------------------------------------------------------------- 1 | CONFIG_FILE FILE_PATH Path to the configuration file 2 | NAME NAME name example: john 3 | -------------------------------------------------------------------------------- /opt-env-conf-test/src/OptEnvConf/EnvMap/Gen.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -Wno-orphans #-} 2 | 3 | module OptEnvConf.EnvMap.Gen where 4 | 5 | import Data.GenValidity 6 | import Data.GenValidity.Containers () 7 | import OptEnvConf.EnvMap 8 | 9 | instance GenValid EnvMap 10 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable-optional/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { 3 | example = lib.mkOption { 4 | default = null; 5 | description = "Example of an enable/disable switch"; 6 | type = lib.types.nullOr lib.types.bool; 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/unreadable-vars.txt: -------------------------------------------------------------------------------- 1 | Failed to read env var: 2 | FOO METAVAR 3 | undocumented 4 | Un-Read-able value: "n" 5 | Failed to read env var: 6 | BAR METAVAR 7 | undocumented 8 | Un-Read-able value: "m" 9 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/no-commands.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | commands was called with an empty list. 5 | Defined at: test/OptEnvConf/LintSpec.hs:121:6 in opt-env-conf-test:OptEnvConf.LintSpec 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/no-reader-for-argument.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | argument has no reader. 5 | Defined at: test/OptEnvConf/LintSpec.hs:41:7 in opt-env-conf-test:OptEnvConf.LintSpec 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/greet/opt-short.txt: -------------------------------------------------------------------------------- 1 | greet [--config-file FILE_PATH] [-g|--greeting GREETING] [SUBJECT] [-p|--polite] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/no-metavar-for-argument.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | argument has no metavar. 5 | Defined at: test/OptEnvConf/LintSpec.hs:49:7 in opt-env-conf-test:OptEnvConf.LintSpec 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/no-dashed-for-option.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | option has no long or short. 5 | Defined at: test/OptEnvConf/LintSpec.hs:67:7 in opt-env-conf-test:OptEnvConf.LintSpec 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/no-dashed-for-switch.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | switch has no long or short. 5 | Defined at: test/OptEnvConf/LintSpec.hs:98:7 in opt-env-conf-test:OptEnvConf.LintSpec 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/no-metavar-for-env.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | env or name has no metavar. 5 | Defined at: test/OptEnvConf/LintSpec.hs:112:7 in opt-env-conf-test:OptEnvConf.LintSpec 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/many-conf.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | many or some was called with a parser that may succeed without consuming anything. 5 | This is not allowed because the parser would run infinitely. 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/many-env.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | many or some was called with a parser that may succeed without consuming anything. 5 | This is not allowed because the parser would run infinitely. 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/no-metavar-for-option.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | option or name has no metavar. 5 | Defined at: test/OptEnvConf/LintSpec.hs:88:7 in opt-env-conf-test:OptEnvConf.LintSpec 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/no-reader-for-option.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | option or name has no reader. 5 | Defined at: test/OptEnvConf/LintSpec.hs:58:7 in opt-env-conf-test:OptEnvConf.LintSpec 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/some-conf.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | many or some was called with a parser that may succeed without consuming anything. 5 | This is not allowed because the parser would run infinitely. 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/some-env.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | many or some was called with a parser that may succeed without consuming anything. 5 | This is not allowed because the parser would run infinitely. 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/dash-in-short.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | short may not contain a '-'. 5 | Found short '-'. 6 | Defined at: test/OptEnvConf/LintSpec.hs:25:7 in opt-env-conf-test:OptEnvConf.LintSpec 7 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/unknown-default-command.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | defaultCommand was called with an unknown command: b 5 | Defined at: test/OptEnvConf/LintSpec.hs:185:7 in opt-env-conf-test:OptEnvConf.LintSpec 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/three-commands/config.txt: -------------------------------------------------------------------------------- 1 | number 2 | example: 5 3 | number: 4 | # or null 5 |  # 64 bit signed integer 6 | enable extra 7 | enable: 8 | # or null 9 |  10 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/no-option-or-switch-for-dashed.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | long or short has no option or switch. 5 | Defined at: test/OptEnvConf/LintSpec.hs:77:7 in opt-env-conf-test:OptEnvConf.LintSpec 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/empty/help.txt: -------------------------------------------------------------------------------- 1 | Usage: empty 2 | 3 | empty parser 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/help/create.txt: -------------------------------------------------------------------------------- 1 | Usage: example create STR 2 | 3 | create command explanation 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | The item to create 10 | argument: STR 11 | 12 | -------------------------------------------------------------------------------- /opt-env-conf-test/test/OptEnvConf/EnvMapSpec.hs: -------------------------------------------------------------------------------- 1 | module OptEnvConf.EnvMapSpec (spec) where 2 | 3 | import qualified OptEnvConf.EnvMap as EM 4 | import Test.Syd 5 | import Test.Syd.Validity 6 | 7 | spec :: Spec 8 | spec = do 9 | describe "parseEnvMap" $ do 10 | it "produces valid EnvMaps" $ 11 | producesValid EM.parse 12 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/hidden/help.txt: -------------------------------------------------------------------------------- 1 | Usage: hidden 2 | 3 | example with hidden settings 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/secret/opt-short.txt: -------------------------------------------------------------------------------- 1 | secret --first-secret-file FILE_PATH [--second-secret SECRET | --second-secret-file FILE_PATH] [--second-secret SECRET | --second-secret-file FILE_PATH] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sum-type/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | EnvDoc 4 | { envDocVars = "sum-type" :| [] 5 | , envDocDefault = Nothing 6 | , envDocExamples = [] 7 | , envDocMetavar = Just "SUM_TYPE" 8 | , envDocHelp = Just "example" 9 | } 10 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | EnvDoc 4 | { envDocVars = "EXAMPLE" :| [] 5 | , envDocDefault = Nothing 6 | , envDocExamples = [] 7 | , envDocMetavar = Just "BOOL" 8 | , envDocHelp = Just "Example of a yes/no switch" 9 | } 10 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/dash-in-long.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | long may not start with a '-'. 5 | Found long "--switch". 6 | Try long "switch" instead. 7 | Defined at: test/OptEnvConf/LintSpec.hs:33:7 in opt-env-conf-test:OptEnvConf.LintSpec 8 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/unreadable-example.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | example was called with an example that none of the readers succeed in reading. 5 | Example: NaN 6 | Defined at: test/OptEnvConf/LintSpec.hs:132:7 in opt-env-conf-test:OptEnvConf.LintSpec 7 | -------------------------------------------------------------------------------- /opt-env-conf-test/test/OptEnvConf/TestUtils.hs: -------------------------------------------------------------------------------- 1 | module OptEnvConf.TestUtils (pureGoldenChunksFile) where 2 | 3 | import Data.Text (Text) 4 | import Test.Syd 5 | import Text.Colour 6 | 7 | pureGoldenChunksFile :: FilePath -> [Chunk] -> GoldenTest Text 8 | pureGoldenChunksFile fp cs = 9 | pureGoldenTextFile fp $ renderChunksText With24BitColours cs 10 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no-optional/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | EnvDoc 4 | { envDocVars = "EXAMPLE" :| [] 5 | , envDocDefault = Nothing 6 | , envDocExamples = [] 7 | , envDocMetavar = Just "BOOL" 8 | , envDocHelp = Just "Example of a yes/no switch" 9 | } 10 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/greet/config.txt: -------------------------------------------------------------------------------- 1 | Greeting to use 2 | default: "Hello" 3 | example: Greetings 4 | greeting: 5 | # or null 6 |  7 | Whether to be polite 8 | default: False 9 | polite: 10 | # or null 11 |  12 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/only-default.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | This setting parses nothing. 5 | Add an argument, switch, option, env, conf, or value. 6 | Defined at: test/OptEnvConf/LintSpec.hs:25:7 in main:OptEnvConf.LintSpec 7 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/big-config/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | EnvDoc 4 | { envDocVars = "CONFIG_FILE" :| [] 5 | , envDocDefault = Nothing 6 | , envDocExamples = [] 7 | , envDocMetavar = Just "FILE_PATH" 8 | , envDocHelp = Just "Path to the configuration file" 9 | } 10 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | EnvDoc 4 | { envDocVars = "EXAMPLE" :| [] 5 | , envDocDefault = Nothing 6 | , envDocExamples = [] 7 | , envDocMetavar = Just "BOOL" 8 | , envDocHelp = Just "Example of an enable/disable switch" 9 | } 10 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/empty-setting.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | This setting parses nothing. 5 | Add an argument, switch, option, env, conf, or value. 6 | Defined at: test/OptEnvConf/LintSpec.hs:19:7 in opt-env-conf-test:OptEnvConf.LintSpec 7 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable-optional/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | EnvDoc 4 | { envDocVars = "EXAMPLE" :| [] 5 | , envDocDefault = Nothing 6 | , envDocExamples = [] 7 | , envDocMetavar = Just "BOOL" 8 | , envDocHelp = Just "Example of an enable/disable switch" 9 | } 10 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/help/sub.txt: -------------------------------------------------------------------------------- 1 | Usage: example sub COMMAND 2 | 3 | command with subcommand 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Available commands: 10 | foo foo explanation 11 | bar bar explanation 12 | 13 | -------------------------------------------------------------------------------- /opt-env-conf-test/src/OptEnvConf/Args/Gen.hs: -------------------------------------------------------------------------------- 1 | {-# OPTIONS_GHC -Wno-orphans #-} 2 | 3 | module OptEnvConf.Args.Gen where 4 | 5 | import Data.GenValidity 6 | import Data.GenValidity.Containers () 7 | import OptEnvConf.Args 8 | 9 | instance GenValid Dashed 10 | 11 | instance (GenValid a) => GenValid (Tomb a) 12 | 13 | instance GenValid Arg 14 | 15 | instance GenValid Args 16 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/three-commands/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { 3 | enable = lib.mkOption { 4 | default = null; 5 | description = "enable extra"; 6 | type = lib.types.nullOr lib.types.bool; 7 | }; 8 | number = lib.mkOption { 9 | default = null; 10 | description = "number"; 11 | type = lib.types.nullOr lib.types.int; 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/big-config/config.txt: -------------------------------------------------------------------------------- 1 | big configuration object 2 | big: 3 | # or null 4 | # BigConfig 5 | map: # required 6 | : 7 | : 8 |  # 64 bit signed integer 9 | sub: # optional 10 |  11 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/all-or-nothing.txt: -------------------------------------------------------------------------------- 1 | Missing option: --bar This one will not exist 2 | You are seeing this error because at least one, but not all, of the settings in an allOrNothing (or subSettings) parser have been defined. 3 | The following settings have been parsed: 4 | test/OptEnvConf/ErrorSpec.hs:141:19 in opt-env-conf-test:OptEnvConf.ErrorSpec 5 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/greet/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { 3 | greeting = lib.mkOption { 4 | default = null; 5 | description = "Greeting to use"; 6 | type = lib.types.nullOr lib.types.str; 7 | }; 8 | polite = lib.mkOption { 9 | default = null; 10 | description = "Whether to be polite"; 11 | type = lib.types.nullOr lib.types.bool; 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/same-help/config.txt: -------------------------------------------------------------------------------- 1 | int or string 2 | int: 3 | # or null 4 |  # 64 bit signed integer 5 | int or string 6 | string: 7 | # or null 8 |  9 | int or string 10 | other: 11 | # or null 12 |  13 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | ConfDoc 4 | { confDocKeys = 5 | ( "example" :| [] , AnyOfSchema (NullSchema :| [ BoolSchema ]) ) :| 6 | [] 7 | , confDocDefault = Nothing 8 | , confDocExamples = [] 9 | , confDocHelp = Just "Example of a yes/no switch" 10 | } 11 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/three-commands/opt-long.txt: -------------------------------------------------------------------------------- 1 | one (default) first 2 | STR argument 3 | two second 4 | --number|-n number example: 5 5 | --(enable|disable)-enable enable extra 6 | three-very-long-command-name third 7 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no-optional/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | ConfDoc 4 | { confDocKeys = 5 | ( "example" :| [] , AnyOfSchema (NullSchema :| [ BoolSchema ]) ) :| 6 | [] 7 | , confDocDefault = Nothing 8 | , confDocExamples = [] 9 | , confDocHelp = Just "Example of a yes/no switch" 10 | } 11 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | ConfDoc 4 | { confDocKeys = 5 | ( "example" :| [] , AnyOfSchema (NullSchema :| [ BoolSchema ]) ) :| 6 | [] 7 | , confDocDefault = Nothing 8 | , confDocExamples = [] 9 | , confDocHelp = Just "Example of an enable/disable switch" 10 | } 11 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-commands/opt-long.txt: -------------------------------------------------------------------------------- 1 | --config-file Path to the configuration file 2 | top command without subcommands 3 | --name name example: john 4 | sub command with subcommands 5 | a A 6 | b B 7 | c (default) C 8 | d D 9 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sum-type/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | ConfDoc 4 | { confDocKeys = 5 | ( "sum-type" :| [] 6 | , AnyOfSchema (NullSchema :| [ StringSchema ]) 7 | ) :| 8 | [] 9 | , confDocDefault = Nothing 10 | , confDocExamples = [] 11 | , confDocHelp = Just "example" 12 | } 13 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/many-args/show.txt: -------------------------------------------------------------------------------- 1 | Many 2 | Nothing 3 | (Setting 4 | Nothing 5 | (Setting 6 | [] 7 | [ _ ] 8 | True 9 | Nothing 10 | False 11 | Nothing 12 | Nothing 13 | Nothing 14 | [] 15 | False 16 | (Just "ARGUMENT") 17 | (Just "Argument") 18 | Nothing 19 | (fromList []))) -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable-optional/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | ConfDoc 4 | { confDocKeys = 5 | ( "example" :| [] , AnyOfSchema (NullSchema :| [ BoolSchema ]) ) :| 6 | [] 7 | , confDocDefault = Nothing 8 | , confDocExamples = [] 9 | , confDocHelp = Just "Example of an enable/disable switch" 10 | } 11 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/optional/help.txt: -------------------------------------------------------------------------------- 1 | Usage: optional [ARGUMENT] 2 | 3 | optional argument 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Argument 13 | argument: ARGUMENT 14 | 15 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/many-args/help.txt: -------------------------------------------------------------------------------- 1 | Usage: many-args [ARGUMENT] 2 | 3 | many args parser 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Argument 13 | argument: ARGUMENT 14 | 15 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/config-without-load.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | conf or name was called with no way to load configuration. 5 | You can load configuration with withConfig, or explicitly not load any configuration with withoutConfig. 6 | Defined at: test/OptEnvConf/LintSpec.hs:124:7 in opt-env-conf-test:OptEnvConf.LintSpec 7 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/empty/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: empty 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | Options: 11 | -h|--help Show this help text 12 | --version Output version information 13 | 14 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/hidden/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: hidden 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | Options: 11 | -h|--help Show this help text 12 | --version Output version information 13 | 14 | -------------------------------------------------------------------------------- /.hlint.yaml: -------------------------------------------------------------------------------- 1 | - ignore: 2 | name: "Use newtype instead of data" 3 | - ignore: 4 | name: "Use <$>" 5 | - ignore: 6 | name: "Redundant <$>" 7 | - ignore: 8 | name: "Use ++" 9 | - ignore: 10 | name: "Use &&" 11 | - ignore: 12 | name: "Use tuple-section" 13 | - ignore: 14 | name: "Use unless" 15 | - ignore: 16 | name: "Use record patterns" 17 | - ignore: 18 | name: "Redundant fmap" 19 | within: OptEnvConf.RunSpec 20 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/greet/env.txt: -------------------------------------------------------------------------------- 1 | GREET_CONFIG_FILE FILE_PATH Path to the configuration file 2 | GREET_GREETING GREETING Greeting to use default: "Hello" example: Greetings 3 | GREET_POLITE ANY Whether to be polite default: False 4 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/verbose/help.txt: -------------------------------------------------------------------------------- 1 | Usage: verbose [-v] 2 | 3 | verbosity example 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Verbosity level. Use multiple to increase verbosity 13 | switch: -v 14 | 15 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/empty/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt empty 1 3 | .Os 4 | .Sh NAME 5 | .Nm empty 6 | .Nd empty parser 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | empty 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | .Sh OPTIONS 19 | -h|--help Show this help text 20 | --version Output version information: 0.0.0 21 | 22 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/error/all-or-nothing-relevant.txt: -------------------------------------------------------------------------------- 1 | Missing option: --bar This one will not exist 2 | You are seeing this error because at least one, but not all, of the settings in an allOrNothing (or subSettings) parser have been defined. 3 | The following settings have been parsed: 4 | test/OptEnvConf/ErrorSpec.hs:153:21 in opt-env-conf-test:OptEnvConf.ErrorSpec 5 | Hit the 'empty' case of the Parser type, this should not happen. 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/hidden/show.txt: -------------------------------------------------------------------------------- 1 | Check 2 | Nothing 3 | True 4 | (fromList []) 5 | _ 6 | (Setting 7 | Nothing 8 | (Setting 9 | [] 10 | [ _ ] 11 | True 12 | Nothing 13 | False 14 | Nothing 15 | Nothing 16 | (Just _) 17 | [] 18 | True 19 | (Just "STR") 20 | (Just "Example of a hidden setting") 21 | Nothing 22 | (fromList []))) -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-settings/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsOr [] 3 | , AnyDocsSingle 4 | ConfDoc 5 | { confDocKeys = 6 | ( "foo" :| [ "bar" , "quux" ] 7 | , AnyOfSchema (NullSchema :| [ StringSchema ]) 8 | ) :| 9 | [] 10 | , confDocDefault = Nothing 11 | , confDocExamples = [] 12 | , confDocHelp = Just "Example with sub-settings" 13 | } 14 | ] -------------------------------------------------------------------------------- /nix/overlay.nix: -------------------------------------------------------------------------------- 1 | final: prev: 2 | let 3 | overrides = final.callPackage ./overrides.nix { }; 4 | addOverrides = old: { overrides = final.lib.composeExtensions (old.overrides or (_: _: { })) overrides; }; 5 | in 6 | { 7 | haskell = prev.haskell // { 8 | packages = builtins.mapAttrs 9 | (_: haskellPackages: haskellPackages.override addOverrides) 10 | prev.haskell.packages; 11 | }; 12 | haskellPackages = prev.haskellPackages.override addOverrides; 13 | } 14 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/hidden/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt hidden 1 3 | .Os 4 | .Sh NAME 5 | .Nm hidden 6 | .Nd example with hidden settings 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | hidden 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | .Sh OPTIONS 19 | -h|--help Show this help text 20 | --version Output version information: 0.0.0 21 | 22 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/many-args/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | (Just 4 | OptDoc 5 | { optDocTryArgument = True 6 | , optDocTrySwitch = False 7 | , optDocTryOption = False 8 | , optDocDasheds = [] 9 | , optDocDefault = Nothing 10 | , optDocExamples = [] 11 | , optDocMetavar = Just "ARGUMENT" 12 | , optDocHelp = Just "Argument" 13 | }) 14 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/optional/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | (Just 4 | OptDoc 5 | { optDocTryArgument = True 6 | , optDocTrySwitch = False 7 | , optDocTryOption = False 8 | , optDocDasheds = [] 9 | , optDocDefault = Nothing 10 | , optDocExamples = [] 11 | , optDocMetavar = Just "ARGUMENT" 12 | , optDocHelp = Just "Argument" 13 | }) 14 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/no-reader-for-env.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | env or name has no reader. 5 | Defined at: test/OptEnvConf/LintSpec.hs:105:7 in opt-env-conf-test:OptEnvConf.LintSpec 6 | 7 | Invalid Setting: 8 | env or name has no metavar. 9 | Defined at: test/OptEnvConf/LintSpec.hs:105:7 in opt-env-conf-test:OptEnvConf.LintSpec 10 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/some-args/help.txt: -------------------------------------------------------------------------------- 1 | Usage: some-args ARGUMENT [ARGUMENT] 2 | 3 | some args parser 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Argument 13 | argument: ARGUMENT 14 | 15 | Argument 16 | argument: ARGUMENT 17 | 18 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/greet/opt-long.txt: -------------------------------------------------------------------------------- 1 | --config-file Path to the configuration file 2 | -g|--greeting Greeting to use default: "Hello" example: Greetings 3 | SUBJECT Who to greet default: "world" 4 | -p|--polite Whether to be polite default: False 5 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/secret/opt-long.txt: -------------------------------------------------------------------------------- 1 | --first-secret-file First example secret 2 | --second-secret Second example secret, bare or in a file 3 | --second-secret-file Second example secret, bare or in a file 4 | --second-secret Second example secret, bare or in a file, only option 5 | --second-secret-file Second example secret, bare or in a file, only option 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/same-help/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { 3 | int = lib.mkOption { 4 | default = null; 5 | description = "int or string"; 6 | type = lib.types.nullOr lib.types.int; 7 | }; 8 | other = lib.mkOption { 9 | default = null; 10 | description = "int or string"; 11 | type = lib.types.nullOr lib.types.bool; 12 | }; 13 | string = lib.mkOption { 14 | default = null; 15 | description = "int or string"; 16 | type = lib.types.nullOr lib.types.str; 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/some-args/show.txt: -------------------------------------------------------------------------------- 1 | Check 2 | Nothing 3 | True 4 | (fromList []) 5 | _ 6 | (Some 7 | Nothing 8 | (Setting 9 | Nothing 10 | (Setting 11 | [] 12 | [ _ ] 13 | True 14 | Nothing 15 | False 16 | Nothing 17 | Nothing 18 | Nothing 19 | [] 20 | False 21 | (Just "ARGUMENT") 22 | (Just "Argument") 23 | Nothing 24 | (fromList [])))) -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/lint/null-setting.txt: -------------------------------------------------------------------------------- 1 | Setting parser is invalid: 2 | 3 | Invalid Setting: 4 | missing help. 5 | Defined at: test/OptEnvConf/LintSpec.hs:16:6 in opt-env-conf-test:OptEnvConf.LintSpec 6 | 7 | Invalid Setting: 8 | This setting parses nothing. 9 | Add an argument, switch, option, env, conf, or value. 10 | Defined at: test/OptEnvConf/LintSpec.hs:16:6 in opt-env-conf-test:OptEnvConf.LintSpec 11 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/optional/show.txt: -------------------------------------------------------------------------------- 1 | Alt 2 | (Check 3 | Nothing 4 | True 5 | (fromList []) 6 | _ 7 | (Setting 8 | Nothing 9 | (Setting 10 | [] 11 | [ _ ] 12 | True 13 | Nothing 14 | False 15 | Nothing 16 | Nothing 17 | Nothing 18 | [] 19 | False 20 | (Just "ARGUMENT") 21 | (Just "Argument") 22 | Nothing 23 | (fromList [])))) 24 | (Pure _) -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/big-config/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { 3 | big = lib.mkOption { 4 | default = null; 5 | description = "big configuration object"; 6 | type = lib.types.nullOr (lib.types.submodule { 7 | options = { 8 | map = lib.mkOption { 9 | type = lib.types.attrsOf (lib.types.attrsOf lib.types.int); 10 | }; 11 | sub = lib.mkOption { 12 | default = null; 13 | type = lib.types.nullOr lib.types.str; 14 | }; 15 | }; 16 | }); 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/verbose/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | (Just 4 | OptDoc 5 | { optDocTryArgument = False 6 | , optDocTrySwitch = True 7 | , optDocTryOption = False 8 | , optDocDasheds = [ DashedShort 'v' ] 9 | , optDocDefault = Nothing 10 | , optDocExamples = [] 11 | , optDocMetavar = Nothing 12 | , optDocHelp = 13 | Just "Verbosity level. Use multiple to increase verbosity" 14 | }) 15 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/completion/bash-completion-script.bash: -------------------------------------------------------------------------------- 1 | _opt_env_conf_completion_example_executable() 2 | { 3 | local CMDLINE 4 | local IFS=$'\n' 5 | CMDLINE=(--query-opt-env-conf-completion) 6 | CMDLINE+=(--completion-index $COMP_CWORD) 7 | 8 | for arg in ${COMP_WORDS[@]}; do 9 | CMDLINE=(${CMDLINE[@]} --completion-word $arg) 10 | done 11 | 12 | COMPREPLY=( $(/usr/bin/example-executable "${CMDLINE[@]}") ) 13 | } 14 | 15 | complete -o filenames -F _opt_env_conf_completion_example_executable example-executable 16 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/three-commands/help.txt: -------------------------------------------------------------------------------- 1 | Usage: three-commands [COMMAND] 2 | 3 | example with three commands 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Available commands: 13 | one (default) first 14 | two second 15 | three-very-long-command-name third 16 | 17 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no/help.txt: -------------------------------------------------------------------------------- 1 | Usage: yes-no [--[no-]example] 2 | 3 | yesNoSwitch example 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Example of a yes/no switch 13 | switch: --[no-]example 14 | env: EXAMPLE BOOL 15 | config: 16 | example: # or null 17 |  18 | 19 | -------------------------------------------------------------------------------- /opt-env-conf-test/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [0.0.0.3] - 2025-11-20 4 | 5 | ### Added 6 | 7 | * Compabitility with `opt-env-conf >=0.13` 8 | 9 | ## [0.0.0.2] - 2025-03-12 10 | 11 | ### Added 12 | 13 | * Completions test helpers 14 | 15 | 16 | ## [0.0.0.1] - 2024-08-08 17 | 18 | ### Added 19 | 20 | * `settingsParserArgsTest` 21 | * `parserArgsTest` 22 | * `settingsParserEnvTest` 23 | * `parserEnvTest` 24 | * `settingsParserConfTest` 25 | * `parserConfTest` 26 | * `settingsParserTest` 27 | * `parserTest` 28 | 29 | ## [0.0.0.0] - 2024-07-08 30 | 31 | First version 32 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/optional/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt optional 1 3 | .Os 4 | .Sh NAME 5 | .Nm optional 6 | .Nd optional argument 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | optional [ARGUMENT] 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | Argument 19 | argument: ARGUMENT 20 | 21 | .Sh OPTIONS 22 | -h|--help Show this help text 23 | --version Output version information: 0.0.0 24 | ARGUMENT Argument 25 | 26 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/verbose/show.txt: -------------------------------------------------------------------------------- 1 | Check 2 | Nothing 3 | True 4 | (fromList []) 5 | _ 6 | (Many 7 | Nothing 8 | (Setting 9 | Nothing 10 | (Setting 11 | [ DashedShort 'v' ] 12 | [] 13 | False 14 | (Just _) 15 | False 16 | Nothing 17 | Nothing 18 | Nothing 19 | [] 20 | False 21 | Nothing 22 | (Just "Verbosity level. Use multiple to increase verbosity") 23 | Nothing 24 | (fromList [])))) -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | (Just 4 | OptDoc 5 | { optDocTryArgument = False 6 | , optDocTrySwitch = True 7 | , optDocTryOption = False 8 | , optDocDasheds = [ DashedLong ('[' :| "no-]example") ] 9 | , optDocDefault = Nothing 10 | , optDocExamples = [] 11 | , optDocMetavar = Nothing 12 | , optDocHelp = Just "Example of a yes/no switch" 13 | }) 14 | , AnyDocsSingle Nothing 15 | , AnyDocsSingle Nothing 16 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/many-args/docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | (Just 4 | SetDoc 5 | { setDocTryArgument = True 6 | , setDocTrySwitch = False 7 | , setDocTryOption = False 8 | , setDocDasheds = [] 9 | , setDocEnvVars = Nothing 10 | , setDocConfKeys = Nothing 11 | , setDocDefault = Nothing 12 | , setDocExamples = [] 13 | , setDocMetavar = Just "ARGUMENT" 14 | , setDocHelp = Just "Argument" 15 | }) 16 | , AnyDocsSingle Nothing 17 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/many-args/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt many-args 1 3 | .Os 4 | .Sh NAME 5 | .Nm many-args 6 | .Nd many args parser 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | many-args [ARGUMENT] 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | Argument 19 | argument: ARGUMENT 20 | 21 | .Sh OPTIONS 22 | -h|--help Show this help text 23 | --version Output version information: 0.0.0 24 | ARGUMENT Argument 25 | 26 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/optional/docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | (Just 4 | SetDoc 5 | { setDocTryArgument = True 6 | , setDocTrySwitch = False 7 | , setDocTryOption = False 8 | , setDocDasheds = [] 9 | , setDocEnvVars = Nothing 10 | , setDocConfKeys = Nothing 11 | , setDocDefault = Nothing 12 | , setDocExamples = [] 13 | , setDocMetavar = Just "ARGUMENT" 14 | , setDocHelp = Just "Argument" 15 | }) 16 | , AnyDocsSingle Nothing 17 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/secret/env.txt: -------------------------------------------------------------------------------- 1 | FIRST_SECRET_FILE FILE_PATH First example secret 2 | SECOND_SECRET SECRET Second example secret, bare or in a file 3 | SECOND_SECRET_FILE FILE_PATH Second example secret, bare or in a file 4 | second-secret SECRET Second example secret, bare or in a file, only env 5 | second-secret_FILE FILE_PATH Second example secret, bare or in a file, only env 6 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no-optional/help.txt: -------------------------------------------------------------------------------- 1 | Usage: yes-no-optional [--[no-]example] 2 | 3 | yesNoSwitch' example 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Example of a yes/no switch 13 | switch: --[no-]example 14 | env: EXAMPLE BOOL 15 | config: 16 | example: # or null 17 |  18 | 19 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no-optional/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | (Just 4 | OptDoc 5 | { optDocTryArgument = False 6 | , optDocTrySwitch = True 7 | , optDocTryOption = False 8 | , optDocDasheds = [ DashedLong ('[' :| "no-]example") ] 9 | , optDocDefault = Nothing 10 | , optDocExamples = [] 11 | , optDocMetavar = Nothing 12 | , optDocHelp = Just "Example of a yes/no switch" 13 | }) 14 | , AnyDocsSingle Nothing 15 | , AnyDocsSingle Nothing 16 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/many-args/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: many-args [ARGUMENT] 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | Argument 11 | argument: ARGUMENT 12 | 13 | Options: 14 | -h|--help Show this help text 15 | --version Output version information 16 | ARGUMENT Argument 17 | 18 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/optional/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: optional [ARGUMENT] 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | Argument 11 | argument: ARGUMENT 12 | 13 | Options: 14 | -h|--help Show this help text 15 | --version Output version information 16 | ARGUMENT Argument 17 | 18 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | (Just 4 | OptDoc 5 | { optDocTryArgument = False 6 | , optDocTrySwitch = True 7 | , optDocTryOption = False 8 | , optDocDasheds = [ DashedLong ('(' :| "enable|disable)-example") ] 9 | , optDocDefault = Nothing 10 | , optDocExamples = [] 11 | , optDocMetavar = Nothing 12 | , optDocHelp = Just "Example of an enable/disable switch" 13 | }) 14 | , AnyDocsSingle Nothing 15 | , AnyDocsSingle Nothing 16 | ] -------------------------------------------------------------------------------- /opt-env-conf-example/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, base, lib, opt-env-conf, opt-env-conf-test, path 2 | , sydtest, sydtest-discover, text 3 | }: 4 | mkDerivation { 5 | pname = "opt-env-conf-example"; 6 | version = "0.0.0.0"; 7 | src = ./.; 8 | isLibrary = true; 9 | isExecutable = true; 10 | libraryHaskellDepends = [ base opt-env-conf path text ]; 11 | executableHaskellDepends = [ base ]; 12 | testHaskellDepends = [ 13 | base opt-env-conf opt-env-conf-test sydtest 14 | ]; 15 | testToolDepends = [ sydtest-discover ]; 16 | license = "unknown"; 17 | mainProgram = "opt-env-conf-example"; 18 | } 19 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable-optional/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | (Just 4 | OptDoc 5 | { optDocTryArgument = False 6 | , optDocTrySwitch = True 7 | , optDocTryOption = False 8 | , optDocDasheds = [ DashedLong ('(' :| "enable|disable)-example") ] 9 | , optDocDefault = Nothing 10 | , optDocExamples = [] 11 | , optDocMetavar = Nothing 12 | , optDocHelp = Just "Example of an enable/disable switch" 13 | }) 14 | , AnyDocsSingle Nothing 15 | , AnyDocsSingle Nothing 16 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable/help.txt: -------------------------------------------------------------------------------- 1 | Usage: enable-disable [--(enable|disable)-example] 2 | 3 | enableDisableSwitch example 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Example of an enable/disable switch 13 | switch: --(enable|disable)-example 14 | env: EXAMPLE BOOL 15 | config: 16 | example: # or null 17 |  18 | 19 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/with-default/help.txt: -------------------------------------------------------------------------------- 1 | Usage: with-default [-f|--first | [-s|--second]] 2 | 3 | withDefault example 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | first 13 | switch: -f|--first 14 | 15 | second 16 | switch: -s|--second 17 | default: Second 18 | 19 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-settings/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { 3 | foo = lib.mkOption { 4 | default = { }; 5 | type = lib.types.submodule { 6 | options = { 7 | bar = lib.mkOption { 8 | default = { }; 9 | type = lib.types.submodule { 10 | options = { 11 | quux = lib.mkOption { 12 | default = null; 13 | description = "Example with sub-settings"; 14 | type = lib.types.nullOr lib.types.str; 15 | }; 16 | }; 17 | }; 18 | }; 19 | }; 20 | }; 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/secret/nix-options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { 3 | first-secret-file = lib.mkOption { 4 | default = null; 5 | description = "First example secret"; 6 | type = lib.types.nullOr lib.types.str; 7 | }; 8 | second-secret = lib.mkOption { 9 | default = null; 10 | description = "Second example secret, bare or in a file, only conf"; 11 | type = lib.types.nullOr lib.types.str; 12 | }; 13 | second-secret-file = lib.mkOption { 14 | default = null; 15 | description = "Second example secret, bare or in a file, only conf"; 16 | type = lib.types.nullOr lib.types.str; 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/big-config/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsOr 3 | [ AnyDocsSingle 4 | (Just 5 | OptDoc 6 | { optDocTryArgument = False 7 | , optDocTrySwitch = False 8 | , optDocTryOption = True 9 | , optDocDasheds = [ DashedLong ('c' :| "onfig-file") ] 10 | , optDocDefault = Nothing 11 | , optDocExamples = [] 12 | , optDocMetavar = Just "FILE_PATH" 13 | , optDocHelp = Just "Path to the configuration file" 14 | }) 15 | ] 16 | , AnyDocsSingle Nothing 17 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable-optional/help.txt: -------------------------------------------------------------------------------- 1 | Usage: enable-disable-optional [--(enable|disable)-example] 2 | 3 | enableDisableSwitch' example 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Example of an enable/disable switch 13 | switch: --(enable|disable)-example 14 | env: EXAMPLE BOOL 15 | config: 16 | example: # or null 17 |  18 | 19 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sum-type/help.txt: -------------------------------------------------------------------------------- 1 | Usage: sum-type [-a | -b] 2 | 3 | Sum type example 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | a 13 | switch: -a 14 | 15 | b 16 | switch: -b 17 | 18 | example 19 | env: sum-type SUM_TYPE 20 | config: 21 | sum-type: # or null 22 |  23 | default: a 24 | 25 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/verbose/docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | (Just 4 | SetDoc 5 | { setDocTryArgument = False 6 | , setDocTrySwitch = True 7 | , setDocTryOption = False 8 | , setDocDasheds = [ DashedShort 'v' ] 9 | , setDocEnvVars = Nothing 10 | , setDocConfKeys = Nothing 11 | , setDocDefault = Nothing 12 | , setDocExamples = [] 13 | , setDocMetavar = Nothing 14 | , setDocHelp = 15 | Just "Verbosity level. Use multiple to increase verbosity" 16 | }) 17 | , AnyDocsSingle Nothing 18 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/verbose/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt verbose 1 3 | .Os 4 | .Sh NAME 5 | .Nm verbose 6 | .Nd verbosity example 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | verbose [-v] 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | Verbosity level. Use multiple to increase verbosity 19 | switch: -v 20 | 21 | .Sh OPTIONS 22 | -h|--help Show this help text 23 | --version Output version information: 0.0.0 24 | -v Verbosity level. Use multiple to increase verbosity 25 | 26 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-settings/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsOr 3 | [ AnyDocsSingle 4 | EnvDoc 5 | { envDocVars = "CONFIG_FILE" :| [] 6 | , envDocDefault = Nothing 7 | , envDocExamples = [] 8 | , envDocMetavar = Just "FILE_PATH" 9 | , envDocHelp = Just "Path to the configuration file" 10 | } 11 | ] 12 | , AnyDocsSingle 13 | EnvDoc 14 | { envDocVars = "FOO_BAR_QUUX" :| [] 15 | , envDocDefault = Nothing 16 | , envDocExamples = [] 17 | , envDocMetavar = Just "STR" 18 | , envDocHelp = Just "Example with sub-settings" 19 | } 20 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/verbose/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: verbose [-v] 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | Verbosity level. Use multiple to increase verbosity 11 | switch: -v 12 | 13 | Options: 14 | -h|--help Show this help text 15 | --version Output version information 16 | -v Verbosity level. Use multiple to increase verbosity 17 | 18 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-commands/help.txt: -------------------------------------------------------------------------------- 1 | Usage: sub-commands [--config-file FILE_PATH] COMMAND 2 | 3 | example with subcommands 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Path to the configuration file 13 | option: --config-file FILE_PATH 14 | env: CONFIG_FILE FILE_PATH 15 | 16 | Available commands: 17 | top command without subcommands 18 | sub command with subcommands 19 | 20 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/secret/config.txt: -------------------------------------------------------------------------------- 1 | First example secret 2 | first-secret-file: 3 | # or null 4 |  5 | Second example secret, bare or in a file 6 | second-secret: 7 | # or null 8 |  9 | Second example secret, bare or in a file 10 | second-secret-file: 11 | # or null 12 |  13 | Second example secret, bare or in a file, only conf 14 | second-secret: 15 | # or null 16 |  17 | Second example secret, bare or in a file, only conf 18 | second-secret-file: 19 | # or null 20 |  21 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/some-args/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt some-args 1 3 | .Os 4 | .Sh NAME 5 | .Nm some-args 6 | .Nd some args parser 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | some-args ARGUMENT [ARGUMENT] 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | Argument 19 | argument: ARGUMENT 20 | 21 | Argument 22 | argument: ARGUMENT 23 | 24 | .Sh OPTIONS 25 | -h|--help Show this help text 26 | --version Output version information: 0.0.0 27 | ARGUMENT Argument 28 | ARGUMENT Argument 29 | 30 | .Sh ENVIRONMENT VARIABLES 31 | 32 | .Sh CONFIGURATION VALUES 33 | 34 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/greet/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsOr [] 3 | , AnyDocsSingle 4 | ConfDoc 5 | { confDocKeys = 6 | ( "greeting" :| [] 7 | , AnyOfSchema (NullSchema :| [ StringSchema ]) 8 | ) :| 9 | [] 10 | , confDocDefault = Just "\"Hello\"" 11 | , confDocExamples = [ "Greetings" ] 12 | , confDocHelp = Just "Greeting to use" 13 | } 14 | , AnyDocsSingle 15 | ConfDoc 16 | { confDocKeys = 17 | ( "polite" :| [] , AnyOfSchema (NullSchema :| [ BoolSchema ]) ) :| 18 | [] 19 | , confDocDefault = Just "False" 20 | , confDocExamples = [] 21 | , confDocHelp = Just "Whether to be polite" 22 | } 23 | ] -------------------------------------------------------------------------------- /opt-env-conf/src/OptEnvConf/Terminal.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE CPP #-} 2 | 3 | module OptEnvConf.Terminal 4 | ( getTerminalCapabilitiesFromHandle, 5 | ) 6 | where 7 | 8 | #if !defined(mingw32_HOST_OS) 9 | import Text.Colour.Capabilities.FromEnv (getTerminalCapabilitiesFromHandle) 10 | #else 11 | import System.IO (Handle, hIsTerminalDevice) 12 | import Text.Colour.Capabilities (TerminalCapabilities (..)) 13 | 14 | getTerminalCapabilitiesFromHandle :: Handle -> IO TerminalCapabilities 15 | getTerminalCapabilitiesFromHandle h = do 16 | isTerm <- hIsTerminalDevice h 17 | pure $ if isTerm then With8BitColours else WithoutColours 18 | -- Note: This may be conservative. Modern Windows terminals (Windows 10+) 19 | -- support 24-bit RGB colors when VT processing is enabled. 20 | #endif 21 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/with-default/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt with-default 1 3 | .Os 4 | .Sh NAME 5 | .Nm with-default 6 | .Nd withDefault example 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | with-default [-f|--first | [-s|--second]] 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | first 19 | switch: -f|--first 20 | 21 | second 22 | switch: -s|--second 23 | default: Second 24 | 25 | .Sh OPTIONS 26 | -h|--help Show this help text 27 | --version Output version information: 0.0.0 28 | -f|--first first 29 | -s|--second second default: Second 30 | 31 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-settings/help.txt: -------------------------------------------------------------------------------- 1 | Usage: sub-settings [--config-file FILE_PATH] --foo-bar-quux STR 2 | 3 | example with a sub settings 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Path to the configuration file 13 | option: --config-file FILE_PATH 14 | env: CONFIG_FILE FILE_PATH 15 | 16 | Example with sub-settings 17 | option: --foo-bar-quux STR 18 | env: FOO_BAR_QUUX STR 19 | config: 20 | foo.bar.quux: # or null 21 |  22 | 23 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/with-default/show.txt: -------------------------------------------------------------------------------- 1 | Alt 2 | (Setting 3 | Nothing 4 | (Setting 5 | [ DashedShort 'f' , DashedLong ('f' :| "irst") ] 6 | [] 7 | False 8 | (Just _) 9 | False 10 | Nothing 11 | Nothing 12 | Nothing 13 | [] 14 | False 15 | Nothing 16 | (Just "first") 17 | Nothing 18 | (fromList []))) 19 | (Setting 20 | Nothing 21 | (Setting 22 | [ DashedShort 's' , DashedLong ('s' :| "econd") ] 23 | [] 24 | False 25 | (Just _) 26 | False 27 | Nothing 28 | Nothing 29 | (Just _) 30 | [] 31 | False 32 | Nothing 33 | (Just "second") 34 | Nothing 35 | (fromList []))) -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/some-args/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: some-args ARGUMENT [ARGUMENT] 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | Argument 11 | argument: ARGUMENT 12 | 13 | Argument 14 | argument: ARGUMENT 15 | 16 | Options: 17 | -h|--help Show this help text 18 | --version Output version information 19 | ARGUMENT Argument 20 | ARGUMENT Argument 21 | 22 | Environment Variables: 23 | 24 | Configuration Values: 25 | 26 | -------------------------------------------------------------------------------- /stack.yaml: -------------------------------------------------------------------------------- 1 | snapshot: lts-24.16 2 | packages: 3 | - opt-env-conf 4 | - opt-env-conf-test 5 | - opt-env-conf-example 6 | 7 | ghc-options: 8 | "$locals": -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates -Wpartial-fields -Widentities -Wredundant-constraints -Wcpp-undef -O0 -Wunused-packages 9 | 10 | extra-deps: 11 | - github: NorfairKing/safe-coloured-text 12 | commit: 046f10147a058c00c2706d98c341219e3cbc7669 13 | subdirs: 14 | - safe-coloured-text 15 | - safe-coloured-text-layout 16 | - safe-coloured-text-gen 17 | - github: NorfairKing/autodocodec 18 | commit: be4aba9ef133520a8a4087aa26915aaabf1376a7 19 | subdirs: 20 | - autodocodec 21 | - autodocodec-yaml 22 | - autodocodec-schema 23 | - autodocodec-nix 24 | 25 | system-ghc: true 26 | nix: 27 | enable: false 28 | with-hpack: hpack 29 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/completion/fish-completion-script.fish: -------------------------------------------------------------------------------- 1 | function _opt_env_conf_completion_example_executable 2 | set -l cl (commandline --tokenize --current-process) 3 | # Hack around fish issue #3934 4 | set -l cn (commandline --tokenize --cut-at-cursor --current-process) 5 | set -l cn (count $cn) 6 | set -l tmpline --query-opt-env-conf-completion --completion-enriched --completion-index $cn 7 | for arg in $cl 8 | set tmpline $tmpline --completion-word $arg 9 | end 10 | for opt in (/usr/bin/example-executable $tmpline) 11 | if test -d $opt 12 | echo -E "$opt/" 13 | else 14 | echo -E "$opt" 15 | end 16 | end 17 | end 18 | 19 | complete --no-files --command /usr/bin/example-executable --arguments '(_opt_env_conf_completion_example_executable)' 20 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/big-config/help.txt: -------------------------------------------------------------------------------- 1 | Usage: big-config [--config-file FILE_PATH] 2 | 3 | example with a big configuration 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Path to the configuration file 13 | option: --config-file FILE_PATH 14 | env: CONFIG_FILE FILE_PATH 15 | 16 | big configuration object 17 | config: 18 | big: # or null 19 | # BigConfig 20 | map: # required 21 | : 22 | : 23 |  # 64 bit signed integer 24 | sub: # optional 25 |  26 | 27 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt yes-no 1 3 | .Os 4 | .Sh NAME 5 | .Nm yes-no 6 | .Nd yesNoSwitch example 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | yes-no [--[no-]example] 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | Example of a yes/no switch 19 | switch: --[no-]example 20 | env: EXAMPLE BOOL 21 | config: 22 | example: # or null 23 | 24 | 25 | .Sh OPTIONS 26 | -h|--help Show this help text 27 | --version Output version information: 0.0.0 28 | --[no-]example Example of a yes/no switch 29 | 30 | .Sh ENVIRONMENT VARIABLES 31 | EXAMPLE BOOL Example of a yes/no switch 32 | 33 | .Sh CONFIGURATION VALUES 34 | Example of a yes/no switch 35 | example: 36 | # or null 37 | 38 | 39 | -------------------------------------------------------------------------------- /opt-env-conf-example/package.yaml: -------------------------------------------------------------------------------- 1 | name: opt-env-conf-example 2 | version: '0.0.0.0' 3 | copyright: ! 'Copyright: (c) 2024 Tom Sydney Kerckhove' 4 | 5 | extra-source-files: 6 | - test_resources/**/* 7 | - options.nix 8 | 9 | dependencies: 10 | - base <5 11 | 12 | 13 | library: 14 | source-dirs: src/ 15 | ghc-options: -Wall 16 | dependencies: 17 | - opt-env-conf 18 | - path 19 | - text 20 | 21 | executables: 22 | opt-env-conf-example: 23 | main: Main.hs 24 | source-dirs: app 25 | dependencies: 26 | - opt-env-conf-example 27 | 28 | tests: 29 | opt-env-conf-example-test: 30 | main: Spec.hs 31 | source-dirs: test/ 32 | build-tools: sydtest-discover 33 | ghc-options: 34 | - -Wall 35 | - -threaded 36 | - -rtsopts 37 | - -with-rtsopts=-N 38 | dependencies: 39 | - opt-env-conf 40 | - opt-env-conf-example 41 | - opt-env-conf-test 42 | - sydtest 43 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sum-type/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt sum-type 1 3 | .Os 4 | .Sh NAME 5 | .Nm sum-type 6 | .Nd Sum type example 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | sum-type [-a | -b] 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | a 19 | switch: -a 20 | 21 | b 22 | switch: -b 23 | 24 | example 25 | env: sum-type SUM_TYPE 26 | config: 27 | sum-type: # or null 28 | 29 | default: a 30 | 31 | .Sh OPTIONS 32 | -h|--help Show this help text 33 | --version Output version information: 0.0.0 34 | -a a 35 | -b b 36 | 37 | .Sh ENVIRONMENT VARIABLES 38 | sum-type SUM_TYPE example 39 | 40 | .Sh CONFIGURATION VALUES 41 | example 42 | sum-type: 43 | # or null 44 | 45 | 46 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no-optional/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt yes-no-optional 1 3 | .Os 4 | .Sh NAME 5 | .Nm yes-no-optional 6 | .Nd yesNoSwitch' example 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | yes-no-optional [--[no-]example] 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | Example of a yes/no switch 19 | switch: --[no-]example 20 | env: EXAMPLE BOOL 21 | config: 22 | example: # or null 23 | 24 | 25 | .Sh OPTIONS 26 | -h|--help Show this help text 27 | --version Output version information: 0.0.0 28 | --[no-]example Example of a yes/no switch 29 | 30 | .Sh ENVIRONMENT VARIABLES 31 | EXAMPLE BOOL Example of a yes/no switch 32 | 33 | .Sh CONFIGURATION VALUES 34 | Example of a yes/no switch 35 | example: 36 | # or null 37 | 38 | 39 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/some-args/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsSingle 3 | (Just 4 | OptDoc 5 | { optDocTryArgument = True 6 | , optDocTrySwitch = False 7 | , optDocTryOption = False 8 | , optDocDasheds = [] 9 | , optDocDefault = Nothing 10 | , optDocExamples = [] 11 | , optDocMetavar = Just "ARGUMENT" 12 | , optDocHelp = Just "Argument" 13 | }) 14 | , AnyDocsOr 15 | [ AnyDocsSingle 16 | (Just 17 | OptDoc 18 | { optDocTryArgument = True 19 | , optDocTrySwitch = False 20 | , optDocTryOption = False 21 | , optDocDasheds = [] 22 | , optDocDefault = Nothing 23 | , optDocExamples = [] 24 | , optDocMetavar = Just "ARGUMENT" 25 | , optDocHelp = Just "Argument" 26 | }) 27 | ] 28 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/with-default/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | (Just 4 | OptDoc 5 | { optDocTryArgument = False 6 | , optDocTrySwitch = True 7 | , optDocTryOption = False 8 | , optDocDasheds = [ DashedShort 'f' , DashedLong ('f' :| "irst") ] 9 | , optDocDefault = Nothing 10 | , optDocExamples = [] 11 | , optDocMetavar = Nothing 12 | , optDocHelp = Just "first" 13 | }) 14 | , AnyDocsSingle 15 | (Just 16 | OptDoc 17 | { optDocTryArgument = False 18 | , optDocTrySwitch = True 19 | , optDocTryOption = False 20 | , optDocDasheds = [ DashedShort 's' , DashedLong ('s' :| "econd") ] 21 | , optDocDefault = Just "Second" 22 | , optDocExamples = [] 23 | , optDocMetavar = Nothing 24 | , optDocHelp = Just "second" 25 | }) 26 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/with-default/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: with-default [-f|--first | [-s|--second]] 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | first 11 | switch: -f|--first 12 | 13 | second 14 | switch: -s|--second 15 | default: Second 16 | 17 | Options: 18 | -h|--help Show this help text 19 | --version Output version information 20 | -f|--first first 21 | -s|--second second default: Second 22 | 23 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sum-type/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | (Just 4 | OptDoc 5 | { optDocTryArgument = False 6 | , optDocTrySwitch = True 7 | , optDocTryOption = False 8 | , optDocDasheds = [ DashedShort 'a' ] 9 | , optDocDefault = Nothing 10 | , optDocExamples = [] 11 | , optDocMetavar = Nothing 12 | , optDocHelp = Just "a" 13 | }) 14 | , AnyDocsSingle 15 | (Just 16 | OptDoc 17 | { optDocTryArgument = False 18 | , optDocTrySwitch = True 19 | , optDocTryOption = False 20 | , optDocDasheds = [ DashedShort 'b' ] 21 | , optDocDefault = Nothing 22 | , optDocExamples = [] 23 | , optDocMetavar = Nothing 24 | , optDocHelp = Just "b" 25 | }) 26 | , AnyDocsSingle Nothing 27 | , AnyDocsSingle Nothing 28 | , AnyDocsSingle Nothing 29 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/completion/zsh-completion-script.zsh: -------------------------------------------------------------------------------- 1 | #compdef example-executable 2 | 3 | local request 4 | local completions 5 | local word 6 | local index=$((CURRENT - 1)) 7 | 8 | request=(--query-opt-env-conf-completion --completion-enriched --completion-index $index) 9 | for arg in ${words[@]}; do 10 | request=(${request[@]} --completion-word $arg) 11 | done 12 | 13 | IFS=$'\n' completions=($( /usr/bin/example-executable "${request[@]}" )) 14 | 15 | for word in $completions; do 16 | local -a parts 17 | 18 | # Split the line at a tab if there is one. 19 | IFS=$'\t' parts=($( echo $word )) 20 | 21 | if [[ -n $parts[2] ]]; then 22 | if [[ $word[1] == "-" ]]; then 23 | local desc=("$parts[1] ($parts[2])") 24 | compadd -d desc -- $parts[1] 25 | else 26 | local desc=($(print -f "%-019s -- %s" $parts[1] $parts[2])) 27 | compadd -l -d desc -- $parts[1] 28 | fi 29 | else 30 | compadd -f -- $word 31 | fi 32 | done 33 | -------------------------------------------------------------------------------- /opt-env-conf/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, aeson, autodocodec, autodocodec-nix 2 | , autodocodec-schema, autodocodec-yaml, base, containers, hashable 3 | , lib, mtl, path, path-io, safe-coloured-text 4 | , safe-coloured-text-layout, safe-coloured-text-terminfo, selective 5 | , text, validity, validity-containers, validity-text 6 | }: 7 | mkDerivation { 8 | pname = "opt-env-conf"; 9 | version = "0.14.0.0"; 10 | src = ./.; 11 | libraryHaskellDepends = [ 12 | aeson autodocodec autodocodec-nix autodocodec-schema 13 | autodocodec-yaml base containers hashable mtl path path-io 14 | safe-coloured-text safe-coloured-text-layout 15 | safe-coloured-text-terminfo selective text validity 16 | validity-containers validity-text 17 | ]; 18 | homepage = "https://github.com/NorfairKing/opt-env-conf#readme"; 19 | description = "Settings parsing for Haskell: command-line arguments, environment variables, and configuration values"; 20 | license = lib.licenses.lgpl3Only; 21 | } 22 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/greet/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsOr 3 | [ AnyDocsSingle 4 | EnvDoc 5 | { envDocVars = "GREET_CONFIG_FILE" :| [] 6 | , envDocDefault = Nothing 7 | , envDocExamples = [] 8 | , envDocMetavar = Just "FILE_PATH" 9 | , envDocHelp = Just "Path to the configuration file" 10 | } 11 | ] 12 | , AnyDocsSingle 13 | EnvDoc 14 | { envDocVars = "GREET_GREETING" :| [] 15 | , envDocDefault = Just "\"Hello\"" 16 | , envDocExamples = [ "Greetings" ] 17 | , envDocMetavar = Just "GREETING" 18 | , envDocHelp = Just "Greeting to use" 19 | } 20 | , AnyDocsSingle 21 | EnvDoc 22 | { envDocVars = "GREET_POLITE" :| [] 23 | , envDocDefault = Just "False" 24 | , envDocExamples = [] 25 | , envDocMetavar = Just "ANY" 26 | , envDocHelp = Just "Whether to be polite" 27 | } 28 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/same-help/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsOr 3 | [ AnyDocsSingle 4 | EnvDoc 5 | { envDocVars = "INT" :| [] 6 | , envDocDefault = Nothing 7 | , envDocExamples = [] 8 | , envDocMetavar = Just "INT" 9 | , envDocHelp = Just "int or string" 10 | } 11 | , AnyDocsSingle 12 | EnvDoc 13 | { envDocVars = "STRING" :| [] 14 | , envDocDefault = Nothing 15 | , envDocExamples = [] 16 | , envDocMetavar = Just "STR" 17 | , envDocHelp = Just "int or string" 18 | } 19 | ] 20 | , AnyDocsOr 21 | [ AnyDocsSingle 22 | EnvDoc 23 | { envDocVars = "OTHER" :| [] 24 | , envDocDefault = Nothing 25 | , envDocExamples = [] 26 | , envDocMetavar = Just "BOOL" 27 | , envDocHelp = Just "int or string" 28 | } 29 | ] 30 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/default.nix: -------------------------------------------------------------------------------- 1 | { mkDerivation, aeson, autodocodec, base, containers, genvalidity 2 | , genvalidity-aeson, genvalidity-containers, genvalidity-sydtest 3 | , genvalidity-text, lib, mtl, opt-env-conf, path, path-io 4 | , pretty-show, QuickCheck, safe-coloured-text, sydtest 5 | , sydtest-discover, text 6 | }: 7 | mkDerivation { 8 | pname = "opt-env-conf-test"; 9 | version = "0.0.0.3"; 10 | src = ./.; 11 | libraryHaskellDepends = [ 12 | aeson base genvalidity genvalidity-containers opt-env-conf 13 | safe-coloured-text sydtest text 14 | ]; 15 | testHaskellDepends = [ 16 | aeson autodocodec base containers genvalidity-aeson 17 | genvalidity-sydtest genvalidity-text mtl opt-env-conf path path-io 18 | pretty-show QuickCheck safe-coloured-text sydtest text 19 | ]; 20 | testToolDepends = [ sydtest-discover ]; 21 | homepage = "https://github.com/NorfairKing/opt-env-conf#readme"; 22 | description = "A testing companion package for opt-env-conf"; 23 | license = "unknown"; 24 | } 25 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: yes-no [--[no-]example] 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | Example of a yes/no switch 11 | switch: --[no-]example 12 | env: EXAMPLE BOOL 13 | config: 14 | example: # or null 15 |  16 | 17 | Options: 18 | -h|--help Show this help text 19 | --version Output version information 20 | --[no-]example Example of a yes/no switch 21 | 22 | Environment Variables: 23 | EXAMPLE BOOL Example of a yes/no switch 24 | 25 | Configuration Values: 26 | Example of a yes/no switch 27 | example: 28 | # or null 29 |  30 | 31 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt enable-disable 1 3 | .Os 4 | .Sh NAME 5 | .Nm enable-disable 6 | .Nd enableDisableSwitch example 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | enable-disable [--(enable|disable)-example] 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | Example of an enable/disable switch 19 | switch: --(enable|disable)-example 20 | env: EXAMPLE BOOL 21 | config: 22 | example: # or null 23 | 24 | 25 | .Sh OPTIONS 26 | -h|--help Show this help text 27 | --version Output version information: 0.0.0 28 | --(enable|disable)-example Example of an enable/disable switch 29 | 30 | .Sh ENVIRONMENT VARIABLES 31 | EXAMPLE BOOL Example of an enable/disable switch 32 | 33 | .Sh CONFIGURATION VALUES 34 | Example of an enable/disable switch 35 | example: 36 | # or null 37 | 38 | 39 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no-optional/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: yes-no-optional [--[no-]example] 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | Example of a yes/no switch 11 | switch: --[no-]example 12 | env: EXAMPLE BOOL 13 | config: 14 | example: # or null 15 |  16 | 17 | Options: 18 | -h|--help Show this help text 19 | --version Output version information 20 | --[no-]example Example of a yes/no switch 21 | 22 | Environment Variables: 23 | EXAMPLE BOOL Example of a yes/no switch 24 | 25 | Configuration Values: 26 | Example of a yes/no switch 27 | example: 28 | # or null 29 |  30 | 31 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/same-help/help.txt: -------------------------------------------------------------------------------- 1 | Usage: same-help [--int INT | --string STR] [--[no-]other] 2 | 3 | example where multiple options use the same help string 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | int or string 13 | option: --int INT 14 | env: INT INT 15 | config: 16 | int: # or null 17 |  # 64 bit signed integer 18 | option: --string STR 19 | env: STRING STR 20 | config: 21 | string: # or null 22 |  23 | 24 | int or string 25 | switch: --[no-]other 26 | env: OTHER BOOL 27 | config: 28 | other: # or null 29 |  30 | 31 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable-optional/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt enable-disable-optional 1 3 | .Os 4 | .Sh NAME 5 | .Nm enable-disable-optional 6 | .Nd enableDisableSwitch' example 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | enable-disable-optional [--(enable|disable)-example] 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | Example of an enable/disable switch 19 | switch: --(enable|disable)-example 20 | env: EXAMPLE BOOL 21 | config: 22 | example: # or null 23 | 24 | 25 | .Sh OPTIONS 26 | -h|--help Show this help text 27 | --version Output version information: 0.0.0 28 | --(enable|disable)-example Example of an enable/disable switch 29 | 30 | .Sh ENVIRONMENT VARIABLES 31 | EXAMPLE BOOL Example of an enable/disable switch 32 | 33 | .Sh CONFIGURATION VALUES 34 | Example of an enable/disable switch 35 | example: 36 | # or null 37 | 38 | 39 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-settings/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsOr 3 | [ AnyDocsSingle 4 | (Just 5 | OptDoc 6 | { optDocTryArgument = False 7 | , optDocTrySwitch = False 8 | , optDocTryOption = True 9 | , optDocDasheds = [ DashedLong ('c' :| "onfig-file") ] 10 | , optDocDefault = Nothing 11 | , optDocExamples = [] 12 | , optDocMetavar = Just "FILE_PATH" 13 | , optDocHelp = Just "Path to the configuration file" 14 | }) 15 | ] 16 | , AnyDocsSingle 17 | (Just 18 | OptDoc 19 | { optDocTryArgument = False 20 | , optDocTrySwitch = False 21 | , optDocTryOption = True 22 | , optDocDasheds = [ DashedLong ('f' :| "oo-bar-quux") ] 23 | , optDocDefault = Nothing 24 | , optDocExamples = [] 25 | , optDocMetavar = Just "STR" 26 | , optDocHelp = Just "Example with sub-settings" 27 | }) 28 | ] -------------------------------------------------------------------------------- /opt-env-conf/package.yaml: -------------------------------------------------------------------------------- 1 | name: opt-env-conf 2 | version: '0.14.0.0' 3 | github: "NorfairKing/opt-env-conf" 4 | copyright: ! 'Copyright: (c) 2024-2025 Tom Sydney Kerckhove' 5 | license: LGPL-3 6 | license-file: LICENSE 7 | synopsis: 'Settings parsing for Haskell: command-line arguments, environment variables, and configuration values.' 8 | author: "Tom Sydney Kerckhove" 9 | maintainer: "syd@cs-syd.eu" 10 | 11 | extra-source-files: 12 | - CHANGELOG.md 13 | 14 | dependencies: 15 | - base <5 16 | 17 | library: 18 | source-dirs: src/ 19 | ghc-options: -Wall 20 | dependencies: 21 | - aeson 22 | - autodocodec >= 0.3.0.0 23 | - autodocodec-nix 24 | - autodocodec-schema 25 | - autodocodec-yaml 26 | - containers 27 | - hashable 28 | - mtl 29 | - path 30 | - path-io 31 | - path-io 32 | - safe-coloured-text >= 0.3.0.2 33 | - safe-coloured-text-layout >= 0.2.0.0 34 | - selective 35 | - text 36 | - validity 37 | - validity-text 38 | - validity-containers 39 | when: 40 | - condition: "!os(windows)" 41 | dependencies: 42 | - safe-coloured-text-terminfo 43 | -------------------------------------------------------------------------------- /opt-env-conf/src/OptEnvConf/EnvMap.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveGeneric #-} 2 | 3 | module OptEnvConf.EnvMap 4 | ( EnvMap (..), 5 | empty, 6 | parse, 7 | lookup, 8 | insert, 9 | ) 10 | where 11 | 12 | import Data.Map (Map) 13 | import qualified Data.Map as M 14 | import Data.Validity 15 | import Data.Validity.Containers () 16 | import GHC.Generics (Generic) 17 | import Prelude hiding (lookup) 18 | 19 | -- | Abstraction for storing and looking up environment variables 20 | -- 21 | -- This can be faster than [(String, String)] and also cannot represent 22 | -- duplicate keys. 23 | newtype EnvMap = EnvMap {unEnvMap :: Map String String} 24 | deriving (Show, Generic) 25 | 26 | instance Validity EnvMap 27 | 28 | empty :: EnvMap 29 | empty = EnvMap {unEnvMap = M.empty} 30 | 31 | parse :: [(String, String)] -> EnvMap 32 | parse = EnvMap . M.fromList -- TODO fail if there are duplicate keys. 33 | 34 | lookup :: String -> EnvMap -> Maybe String 35 | lookup v (EnvMap m) = M.lookup v m 36 | 37 | insert :: String -> String -> EnvMap -> EnvMap 38 | insert k v (EnvMap m) = EnvMap (M.insert k v m) 39 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sum-type/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: sum-type [-a | -b] 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | a 11 | switch: -a 12 | 13 | b 14 | switch: -b 15 | 16 | example 17 | env: sum-type SUM_TYPE 18 | config: 19 | sum-type: # or null 20 |  21 | default: a 22 | 23 | Options: 24 | -h|--help Show this help text 25 | --version Output version information 26 | -a a 27 | -b b 28 | 29 | Environment Variables: 30 | sum-type SUM_TYPE example 31 | 32 | Configuration Values: 33 | example 34 | sum-type: 35 | # or null 36 |  37 | 38 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/with-default/docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsOr 2 | [ AnyDocsSingle 3 | (Just 4 | SetDoc 5 | { setDocTryArgument = False 6 | , setDocTrySwitch = True 7 | , setDocTryOption = False 8 | , setDocDasheds = [ DashedShort 'f' , DashedLong ('f' :| "irst") ] 9 | , setDocEnvVars = Nothing 10 | , setDocConfKeys = Nothing 11 | , setDocDefault = Nothing 12 | , setDocExamples = [] 13 | , setDocMetavar = Nothing 14 | , setDocHelp = Just "first" 15 | }) 16 | , AnyDocsSingle 17 | (Just 18 | SetDoc 19 | { setDocTryArgument = False 20 | , setDocTrySwitch = True 21 | , setDocTryOption = False 22 | , setDocDasheds = [ DashedShort 's' , DashedLong ('s' :| "econd") ] 23 | , setDocEnvVars = Nothing 24 | , setDocConfKeys = Nothing 25 | , setDocDefault = Just "Second" 26 | , setDocExamples = [] 27 | , setDocMetavar = Nothing 28 | , setDocHelp = Just "second" 29 | }) 30 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: enable-disable [--(enable|disable)-example] 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | Example of an enable/disable switch 11 | switch: --(enable|disable)-example 12 | env: EXAMPLE BOOL 13 | config: 14 | example: # or null 15 |  16 | 17 | Options: 18 | -h|--help Show this help text 19 | --version Output version information 20 | --(enable|disable)-example Example of an enable/disable switch 21 | 22 | Environment Variables: 23 | EXAMPLE BOOL Example of an enable/disable switch 24 | 25 | Configuration Values: 26 | Example of an enable/disable switch 27 | example: 28 | # or null 29 |  30 | 31 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/some-args/docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsSingle 3 | (Just 4 | SetDoc 5 | { setDocTryArgument = True 6 | , setDocTrySwitch = False 7 | , setDocTryOption = False 8 | , setDocDasheds = [] 9 | , setDocEnvVars = Nothing 10 | , setDocConfKeys = Nothing 11 | , setDocDefault = Nothing 12 | , setDocExamples = [] 13 | , setDocMetavar = Just "ARGUMENT" 14 | , setDocHelp = Just "Argument" 15 | }) 16 | , AnyDocsOr 17 | [ AnyDocsSingle 18 | (Just 19 | SetDoc 20 | { setDocTryArgument = True 21 | , setDocTrySwitch = False 22 | , setDocTryOption = False 23 | , setDocDasheds = [] 24 | , setDocEnvVars = Nothing 25 | , setDocConfKeys = Nothing 26 | , setDocDefault = Nothing 27 | , setDocExamples = [] 28 | , setDocMetavar = Just "ARGUMENT" 29 | , setDocHelp = Just "Argument" 30 | }) 31 | , AnyDocsSingle Nothing 32 | ] 33 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable-optional/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: enable-disable-optional [--(enable|disable)-example] 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | Example of an enable/disable switch 11 | switch: --(enable|disable)-example 12 | env: EXAMPLE BOOL 13 | config: 14 | example: # or null 15 |  16 | 17 | Options: 18 | -h|--help Show this help text 19 | --version Output version information 20 | --(enable|disable)-example Example of an enable/disable switch 21 | 22 | Environment Variables: 23 | EXAMPLE BOOL Example of an enable/disable switch 24 | 25 | Configuration Values: 26 | Example of an enable/disable switch 27 | example: 28 | # or null 29 |  30 | 31 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-settings/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt sub-settings 1 3 | .Os 4 | .Sh NAME 5 | .Nm sub-settings 6 | .Nd example with a sub settings 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | sub-settings [--config-file FILE_PATH] --foo-bar-quux STR 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | Path to the configuration file 19 | option: --config-file FILE_PATH 20 | env: CONFIG_FILE FILE_PATH 21 | 22 | Example with sub-settings 23 | option: --foo-bar-quux STR 24 | env: FOO_BAR_QUUX STR 25 | config: 26 | foo.bar.quux: # or null 27 | 28 | 29 | .Sh OPTIONS 30 | -h|--help Show this help text 31 | --version Output version information: 0.0.0 32 | --config-file Path to the configuration file 33 | --foo-bar-quux Example with sub-settings 34 | 35 | .Sh ENVIRONMENT VARIABLES 36 | CONFIG_FILE FILE_PATH Path to the configuration file 37 | FOO_BAR_QUUX STR Example with sub-settings 38 | 39 | .Sh CONFIGURATION VALUES 40 | Example with sub-settings 41 | foo.bar.quux: 42 | # or null 43 | 44 | 45 | -------------------------------------------------------------------------------- /opt-env-conf/src/OptEnvConf/Casing.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE LambdaCase #-} 2 | 3 | module OptEnvConf.Casing 4 | ( -- * Casing 5 | toArgCase, 6 | toEnvCase, 7 | toConfigCase, 8 | 9 | -- * Internal 10 | toShellFunctionCase, 11 | ) 12 | where 13 | 14 | import qualified Data.Char as Char 15 | 16 | -- | Turn a string into arg case for option names 17 | -- 18 | -- Example: @this-is-arg-case@ 19 | toArgCase :: String -> String 20 | toArgCase = toConfigCase 21 | 22 | -- | Turn a string into env case for environment variable names 23 | -- 24 | -- Example: @THIS_IS_ENV_CASE@ 25 | toEnvCase :: String -> String 26 | toEnvCase = map (Char.toUpper . spacer '_') 27 | 28 | -- | Turn a string into config case for configuration value names 29 | -- 30 | -- Example: @this-is-config-case@ 31 | toConfigCase :: String -> String 32 | toConfigCase = map (Char.toLower . spacer '-') 33 | 34 | -- | Turn a string into a string that can be used as a shell function name (for completion) 35 | -- 36 | -- Example: @this_is_shell_function_case@ 37 | toShellFunctionCase :: String -> String 38 | toShellFunctionCase = map (Char.toLower . spacer '_') 39 | 40 | spacer :: Char -> Char -> Char 41 | spacer s = \case 42 | '-' -> s 43 | '_' -> s 44 | '.' -> s 45 | ' ' -> s 46 | '\t' -> s 47 | c -> c 48 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/big-config/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt big-config 1 3 | .Os 4 | .Sh NAME 5 | .Nm big-config 6 | .Nd example with a big configuration 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | big-config [--config-file FILE_PATH] 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | Path to the configuration file 19 | option: --config-file FILE_PATH 20 | env: CONFIG_FILE FILE_PATH 21 | 22 | big configuration object 23 | config: 24 | big: # or null 25 | # BigConfig 26 | map: # required 27 | : 28 | : 29 | # 64 bit signed integer 30 | sub: # optional 31 | 32 | 33 | .Sh OPTIONS 34 | -h|--help Show this help text 35 | --version Output version information: 0.0.0 36 | --config-file Path to the configuration file 37 | 38 | .Sh ENVIRONMENT VARIABLES 39 | CONFIG_FILE FILE_PATH Path to the configuration file 40 | 41 | .Sh CONFIGURATION VALUES 42 | big configuration object 43 | big: 44 | # or null 45 | # BigConfig 46 | map: # required 47 | : 48 | : 49 | # 64 bit signed integer 50 | sub: # optional 51 | 52 | 53 | -------------------------------------------------------------------------------- /opt-env-conf-test/package.yaml: -------------------------------------------------------------------------------- 1 | name: opt-env-conf-test 2 | version: '0.0.0.3' 3 | github: "NorfairKing/opt-env-conf" 4 | copyright: ! 'Copyright: (c) 2024-2025 Tom Sydney Kerckhove' 5 | license: OtherLicense 6 | license-file: LICENSE.md 7 | synopsis: A testing companion package for opt-env-conf 8 | author: "Tom Sydney Kerckhove" 9 | maintainer: "syd@cs-syd.eu" 10 | 11 | extra-source-files: 12 | - CHANGELOG.md 13 | - test_resources/**/* 14 | 15 | dependencies: 16 | - base <5 17 | 18 | 19 | library: 20 | source-dirs: src/ 21 | ghc-options: -Wall 22 | dependencies: 23 | - aeson 24 | - genvalidity 25 | - genvalidity-containers 26 | - opt-env-conf >= 0.9.0.0 27 | - safe-coloured-text 28 | - sydtest 29 | - text 30 | 31 | tests: 32 | opt-env-conf-test: 33 | main: Spec.hs 34 | source-dirs: test/ 35 | build-tools: sydtest-discover 36 | ghc-options: 37 | - -Wall 38 | - -threaded 39 | - -rtsopts 40 | - -with-rtsopts=-N 41 | dependencies: 42 | - QuickCheck 43 | - aeson 44 | - autodocodec 45 | - containers 46 | - genvalidity-aeson 47 | - genvalidity-sydtest 48 | - genvalidity-text 49 | - mtl 50 | - opt-env-conf 51 | - opt-env-conf-test 52 | - path 53 | - path-io 54 | - pretty-show 55 | - safe-coloured-text 56 | - sydtest 57 | - text 58 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/greet/help.txt: -------------------------------------------------------------------------------- 1 | Usage: greet [--config-file FILE_PATH] [-g|--greeting GREETING] [SUBJECT] [-p|--polite] 2 | 3 | hello world example 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Path to the configuration file 13 | option: --config-file FILE_PATH 14 | env: GREET_CONFIG_FILE FILE_PATH 15 | 16 | Greeting to use 17 | option: -g|--greeting GREETING 18 | env: GREET_GREETING GREETING 19 | config: 20 | greeting: # or null 21 |  22 | default: "Hello" 23 | example: Greetings 24 | 25 | Who to greet 26 | argument: SUBJECT 27 | default: "world" 28 | 29 | Whether to be polite 30 | switch: -p|--polite 31 | env: GREET_POLITE ANY 32 | config: 33 | polite: # or null 34 |  35 | default: False 36 | 37 | -------------------------------------------------------------------------------- /opt-env-conf-test/test/OptEnvConf/NonDetSpec.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE ApplicativeDo #-} 2 | 3 | module OptEnvConf.NonDetSpec (spec) where 4 | 5 | import Control.Applicative 6 | import Control.Monad 7 | import Control.Monad.Trans 8 | import OptEnvConf.NonDet 9 | import Test.Syd 10 | 11 | spec :: Spec 12 | spec = do 13 | describe "runNonDet" $ do 14 | it "can guard against previous values" $ 15 | runNonDet 16 | ( do 17 | a <- liftNonDetTList [1, 2 :: Int] 18 | b <- liftNonDetTList [3, 4] 19 | guard $ even $ a + b 20 | pure (a, b) 21 | ) 22 | `shouldBe` [(1, 3), (2, 4)] 23 | it "can recover from failures with <|>" $ 24 | runNonDet 25 | ( do 26 | a <- liftNonDetTList [1, 2 :: Int] 27 | f <- liftNonDetTList [even] <|> liftNonDetTList [odd] 28 | guard $ f a 29 | pure a 30 | ) 31 | `shouldBe` [1, 2] 32 | 33 | describe "runNonDetT" $ do 34 | it "can recover from underlying errors" $ do 35 | let f :: NonDetT (Either String) Int 36 | f = do 37 | i <- liftNonDetTList [1, 2] 38 | if odd i 39 | then do 40 | () <- empty 41 | lift (Left "err") 42 | else pure i 43 | 44 | runNonDetT f `shouldBe` Right [2] 45 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/three-commands/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsCommands 2 | (Just "one") 3 | [ CommandDoc 4 | { commandDocArgument = "one" 5 | , commandDocHelp = "first" 6 | , commandDocs = AnyDocsAnd [] 7 | } 8 | , CommandDoc 9 | { commandDocArgument = "two" 10 | , commandDocHelp = "second" 11 | , commandDocs = 12 | AnyDocsAnd 13 | [ AnyDocsSingle 14 | EnvDoc 15 | { envDocVars = "NUMBER" :| [] 16 | , envDocDefault = Nothing 17 | , envDocExamples = [ "5" ] 18 | , envDocMetavar = Just "INT" 19 | , envDocHelp = Just "number" 20 | } 21 | , AnyDocsOr 22 | [ AnyDocsSingle 23 | EnvDoc 24 | { envDocVars = "ENABLE" :| [] 25 | , envDocDefault = Nothing 26 | , envDocExamples = [] 27 | , envDocMetavar = Just "BOOL" 28 | , envDocHelp = Just "enable extra" 29 | } 30 | ] 31 | ] 32 | } 33 | , CommandDoc 34 | { commandDocArgument = "three-very-long-command-name" 35 | , commandDocHelp = "third" 36 | , commandDocs = AnyDocsAnd [] 37 | } 38 | ] -------------------------------------------------------------------------------- /opt-env-conf-example/options.nix: -------------------------------------------------------------------------------- 1 | { lib }: 2 | { 3 | cache-directory = lib.mkOption { 4 | default = null; 5 | description = "cache directory"; 6 | type = lib.types.nullOr lib.types.str; 7 | }; 8 | example = lib.mkOption { 9 | default = { }; 10 | type = lib.types.submodule { 11 | options = { 12 | log-level = lib.mkOption { 13 | default = null; 14 | description = "minimal severity of log messages"; 15 | type = lib.types.nullOr lib.types.str; 16 | }; 17 | payment = lib.mkOption { 18 | default = { }; 19 | type = lib.types.submodule { 20 | options = { 21 | currency = lib.mkOption { 22 | default = null; 23 | description = "Currency"; 24 | type = lib.types.nullOr lib.types.str; 25 | }; 26 | public-key = lib.mkOption { 27 | default = null; 28 | description = "Public key"; 29 | type = lib.types.nullOr lib.types.str; 30 | }; 31 | secret-key = lib.mkOption { 32 | default = null; 33 | description = "Secret key"; 34 | type = lib.types.nullOr lib.types.str; 35 | }; 36 | }; 37 | }; 38 | }; 39 | }; 40 | }; 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/big-config/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsOr [] 3 | , AnyDocsSingle 4 | ConfDoc 5 | { confDocKeys = 6 | ( "big" :| [] 7 | , AnyOfSchema 8 | (NullSchema :| 9 | [ CommentSchema 10 | "BigConfig" 11 | (ObjectSchema 12 | (ObjectAllOfSchema 13 | (ObjectKeySchema 14 | "map" 15 | Required 16 | (MapSchema 17 | (MapSchema 18 | (IntegerSchema 19 | Bounds 20 | { boundsLower = Just (-9223372036854775808) 21 | , boundsUpper = Just 9223372036854775807 22 | }))) 23 | Nothing :| 24 | [ ObjectKeySchema "sub" (Optional Nothing) StringSchema Nothing 25 | ]))) 26 | ]) 27 | ) :| 28 | [] 29 | , confDocDefault = Nothing 30 | , confDocExamples = [] 31 | , confDocHelp = Just "big configuration object" 32 | } 33 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-settings/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: sub-settings [--config-file FILE_PATH] --foo-bar-quux STR 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | Path to the configuration file 11 | option: --config-file FILE_PATH 12 | env: CONFIG_FILE FILE_PATH 13 | 14 | Example with sub-settings 15 | option: --foo-bar-quux STR 16 | env: FOO_BAR_QUUX STR 17 | config: 18 | foo.bar.quux: # or null 19 |  20 | 21 | Options: 22 | -h|--help Show this help text 23 | --version Output version information 24 | --config-file Path to the configuration file 25 | --foo-bar-quux Example with sub-settings 26 | 27 | Environment Variables: 28 | CONFIG_FILE FILE_PATH Path to the configuration file 29 | FOO_BAR_QUUX STR Example with sub-settings 30 | 31 | Configuration Values: 32 | Example with sub-settings 33 | foo.bar.quux: 34 | # or null 35 |  36 | 37 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-settings/docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsOr 3 | [ AnyDocsSingle 4 | (Just 5 | SetDoc 6 | { setDocTryArgument = False 7 | , setDocTrySwitch = False 8 | , setDocTryOption = True 9 | , setDocDasheds = [ DashedLong ('c' :| "onfig-file") ] 10 | , setDocEnvVars = Just ("CONFIG_FILE" :| []) 11 | , setDocConfKeys = Nothing 12 | , setDocDefault = Nothing 13 | , setDocExamples = [] 14 | , setDocMetavar = Just "FILE_PATH" 15 | , setDocHelp = Just "Path to the configuration file" 16 | }) 17 | , AnyDocsSingle Nothing 18 | ] 19 | , AnyDocsSingle 20 | (Just 21 | SetDoc 22 | { setDocTryArgument = False 23 | , setDocTrySwitch = False 24 | , setDocTryOption = True 25 | , setDocDasheds = [ DashedLong ('f' :| "oo-bar-quux") ] 26 | , setDocEnvVars = Just ("FOO_BAR_QUUX" :| []) 27 | , setDocConfKeys = 28 | Just 29 | (( "foo" :| [ "bar" , "quux" ] 30 | , AnyOfSchema (NullSchema :| [ StringSchema ]) 31 | ) :| 32 | []) 33 | , setDocDefault = Nothing 34 | , setDocExamples = [] 35 | , setDocMetavar = Just "STR" 36 | , setDocHelp = Just "Example with sub-settings" 37 | }) 38 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/same-help/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt same-help 1 3 | .Os 4 | .Sh NAME 5 | .Nm same-help 6 | .Nd example where multiple options use the same help string 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | same-help [--int INT | --string STR] [--[no-]other] 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | int or string 19 | option: --int INT 20 | env: INT INT 21 | config: 22 | int: # or null 23 | # 64 bit signed integer 24 | option: --string STR 25 | env: STRING STR 26 | config: 27 | string: # or null 28 | 29 | 30 | int or string 31 | switch: --[no-]other 32 | env: OTHER BOOL 33 | config: 34 | other: # or null 35 | 36 | 37 | .Sh OPTIONS 38 | -h|--help Show this help text 39 | --version Output version information: 0.0.0 40 | --int int or string 41 | --string int or string 42 | --[no-]other int or string 43 | 44 | .Sh ENVIRONMENT VARIABLES 45 | INT INT int or string 46 | STRING STR int or string 47 | OTHER BOOL int or string 48 | 49 | .Sh CONFIGURATION VALUES 50 | int or string 51 | int: 52 | # or null 53 | # 64 bit signed integer 54 | int or string 55 | string: 56 | # or null 57 | 58 | int or string 59 | other: 60 | # or null 61 | 62 | 63 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/same-help/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsOr 3 | [ AnyDocsSingle 4 | ConfDoc 5 | { confDocKeys = 6 | ( "int" :| [] 7 | , AnyOfSchema 8 | (NullSchema :| 9 | [ IntegerSchema 10 | Bounds 11 | { boundsLower = Just (-9223372036854775808) 12 | , boundsUpper = Just 9223372036854775807 13 | } 14 | ]) 15 | ) :| 16 | [] 17 | , confDocDefault = Nothing 18 | , confDocExamples = [] 19 | , confDocHelp = Just "int or string" 20 | } 21 | , AnyDocsSingle 22 | ConfDoc 23 | { confDocKeys = 24 | ( "string" :| [] 25 | , AnyOfSchema (NullSchema :| [ StringSchema ]) 26 | ) :| 27 | [] 28 | , confDocDefault = Nothing 29 | , confDocExamples = [] 30 | , confDocHelp = Just "int or string" 31 | } 32 | ] 33 | , AnyDocsOr 34 | [ AnyDocsSingle 35 | ConfDoc 36 | { confDocKeys = 37 | ( "other" :| [] , AnyOfSchema (NullSchema :| [ BoolSchema ]) ) :| 38 | [] 39 | , confDocDefault = Nothing 40 | , confDocExamples = [] 41 | , confDocHelp = Just "int or string" 42 | } 43 | ] 44 | ] -------------------------------------------------------------------------------- /opt-env-conf-example/opt-env-conf-example.cabal: -------------------------------------------------------------------------------- 1 | cabal-version: 1.12 2 | 3 | -- This file has been generated from package.yaml by hpack version 0.36.1. 4 | -- 5 | -- see: https://github.com/sol/hpack 6 | 7 | name: opt-env-conf-example 8 | version: 0.0.0.0 9 | copyright: Copyright: (c) 2024 Tom Sydney Kerckhove 10 | build-type: Simple 11 | extra-source-files: 12 | test_resources/documentation.txt 13 | options.nix 14 | 15 | library 16 | exposed-modules: 17 | OptEnvConf.Example 18 | other-modules: 19 | Paths_opt_env_conf_example 20 | hs-source-dirs: 21 | src/ 22 | ghc-options: -Wall 23 | build-depends: 24 | base <5 25 | , opt-env-conf 26 | , path 27 | , text 28 | default-language: Haskell2010 29 | 30 | executable opt-env-conf-example 31 | main-is: Main.hs 32 | other-modules: 33 | Paths_opt_env_conf_example 34 | hs-source-dirs: 35 | app 36 | build-depends: 37 | base <5 38 | , opt-env-conf-example 39 | default-language: Haskell2010 40 | 41 | test-suite opt-env-conf-example-test 42 | type: exitcode-stdio-1.0 43 | main-is: Spec.hs 44 | other-modules: 45 | OptEnvConf.ExampleSpec 46 | Paths_opt_env_conf_example 47 | hs-source-dirs: 48 | test/ 49 | ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N 50 | build-tool-depends: 51 | sydtest-discover:sydtest-discover 52 | build-depends: 53 | base <5 54 | , opt-env-conf 55 | , opt-env-conf-example 56 | , opt-env-conf-test 57 | , sydtest 58 | default-language: Haskell2010 59 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/big-config/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: big-config [--config-file FILE_PATH] 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | Path to the configuration file 11 | option: --config-file FILE_PATH 12 | env: CONFIG_FILE FILE_PATH 13 | 14 | big configuration object 15 | config: 16 | big: # or null 17 | # BigConfig 18 | map: # required 19 | : 20 | : 21 |  # 64 bit signed integer 22 | sub: # optional 23 |  24 | 25 | Options: 26 | -h|--help Show this help text 27 | --version Output version information 28 | --config-file Path to the configuration file 29 | 30 | Environment Variables: 31 | CONFIG_FILE FILE_PATH Path to the configuration file 32 | 33 | Configuration Values: 34 | big configuration object 35 | big: 36 | # or null 37 | # BigConfig 38 | map: # required 39 | : 40 | : 41 |  # 64 bit signed integer 42 | sub: # optional 43 |  44 | 45 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-commands/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt sub-commands 1 3 | .Os 4 | .Sh NAME 5 | .Nm sub-commands 6 | .Nd example with subcommands 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | sub-commands [--config-file FILE_PATH] COMMAND 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | Path to the configuration file 19 | option: --config-file FILE_PATH 20 | env: CONFIG_FILE FILE_PATH 21 | 22 | .Sh COMMANDS 23 | command without subcommands 24 | command: top 25 | name 26 | option: --name NAME 27 | env: NAME NAME 28 | config: 29 | name: # or null 30 | 31 | example: john 32 | 33 | 34 | command with subcommands 35 | command: sub 36 | A 37 | command: a 38 | 39 | B 40 | command: b 41 | 42 | C 43 | command: c (default) 44 | 45 | D 46 | command: d 47 | 48 | 49 | 50 | .Sh OPTIONS 51 | -h|--help Show this help text 52 | --version Output version information: 0.0.0 53 | --config-file Path to the configuration file 54 | top command without subcommands 55 | --name name example: john 56 | sub command with subcommands 57 | a A 58 | b B 59 | c (default) C 60 | d D 61 | 62 | .Sh ENVIRONMENT VARIABLES 63 | CONFIG_FILE FILE_PATH Path to the configuration file 64 | NAME NAME name example: john 65 | 66 | .Sh CONFIGURATION VALUES 67 | name 68 | example: john 69 | name: 70 | # or null 71 | 72 | 73 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/same-help/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsOr 3 | [ AnyDocsSingle 4 | (Just 5 | OptDoc 6 | { optDocTryArgument = False 7 | , optDocTrySwitch = False 8 | , optDocTryOption = True 9 | , optDocDasheds = [ DashedLong ('i' :| "nt") ] 10 | , optDocDefault = Nothing 11 | , optDocExamples = [] 12 | , optDocMetavar = Just "INT" 13 | , optDocHelp = Just "int or string" 14 | }) 15 | , AnyDocsSingle 16 | (Just 17 | OptDoc 18 | { optDocTryArgument = False 19 | , optDocTrySwitch = False 20 | , optDocTryOption = True 21 | , optDocDasheds = [ DashedLong ('s' :| "tring") ] 22 | , optDocDefault = Nothing 23 | , optDocExamples = [] 24 | , optDocMetavar = Just "STR" 25 | , optDocHelp = Just "int or string" 26 | }) 27 | ] 28 | , AnyDocsOr 29 | [ AnyDocsSingle 30 | (Just 31 | OptDoc 32 | { optDocTryArgument = False 33 | , optDocTrySwitch = True 34 | , optDocTryOption = False 35 | , optDocDasheds = [ DashedLong ('[' :| "no-]other") ] 36 | , optDocDefault = Nothing 37 | , optDocExamples = [] 38 | , optDocMetavar = Nothing 39 | , optDocHelp = Just "int or string" 40 | }) 41 | , AnyDocsSingle Nothing 42 | , AnyDocsSingle Nothing 43 | ] 44 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/three-commands/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt three-commands 1 3 | .Os 4 | .Sh NAME 5 | .Nm three-commands 6 | .Nd example with three commands 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | three-commands [COMMAND] 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | .Sh COMMANDS 19 | first 20 | command: one (default) 21 | argument 22 | argument: STR 23 | 24 | 25 | second 26 | command: two 27 | number 28 | option: --number|-n INT 29 | env: NUMBER INT 30 | config: 31 | number: # or null 32 | # 64 bit signed integer 33 | example: 5 34 | 35 | enable extra 36 | switch: --(enable|disable)-enable 37 | env: ENABLE BOOL 38 | config: 39 | enable: # or null 40 | 41 | 42 | 43 | third 44 | command: three-very-long-command-name 45 | 46 | 47 | .Sh OPTIONS 48 | -h|--help Show this help text 49 | --version Output version information: 0.0.0 50 | one (default) first 51 | STR argument 52 | two second 53 | --number|-n number example: 5 54 | --(enable|disable)-enable enable extra 55 | three-very-long-command-name third 56 | 57 | .Sh ENVIRONMENT VARIABLES 58 | NUMBER INT number example: 5 59 | ENABLE BOOL enable extra 60 | 61 | .Sh CONFIGURATION VALUES 62 | number 63 | example: 5 64 | number: 65 | # or null 66 | # 64 bit signed integer 67 | enable extra 68 | enable: 69 | # or null 70 | 71 | 72 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/secret/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsSingle 3 | EnvDoc 4 | { envDocVars = "FIRST_SECRET_FILE" :| [] 5 | , envDocDefault = Nothing 6 | , envDocExamples = [] 7 | , envDocMetavar = Just "FILE_PATH" 8 | , envDocHelp = Just "First example secret" 9 | } 10 | , AnyDocsOr 11 | [ AnyDocsSingle 12 | EnvDoc 13 | { envDocVars = "SECOND_SECRET" :| [] 14 | , envDocDefault = Nothing 15 | , envDocExamples = [] 16 | , envDocMetavar = Just "SECRET" 17 | , envDocHelp = Just "Second example secret, bare or in a file" 18 | } 19 | , AnyDocsSingle 20 | EnvDoc 21 | { envDocVars = "SECOND_SECRET_FILE" :| [] 22 | , envDocDefault = Nothing 23 | , envDocExamples = [] 24 | , envDocMetavar = Just "FILE_PATH" 25 | , envDocHelp = Just "Second example secret, bare or in a file" 26 | } 27 | ] 28 | , AnyDocsOr [] 29 | , AnyDocsOr 30 | [ AnyDocsSingle 31 | EnvDoc 32 | { envDocVars = "second-secret" :| [] 33 | , envDocDefault = Nothing 34 | , envDocExamples = [] 35 | , envDocMetavar = Just "SECRET" 36 | , envDocHelp = 37 | Just "Second example secret, bare or in a file, only env" 38 | } 39 | , AnyDocsSingle 40 | EnvDoc 41 | { envDocVars = "second-secret_FILE" :| [] 42 | , envDocDefault = Nothing 43 | , envDocExamples = [] 44 | , envDocMetavar = Just "FILE_PATH" 45 | , envDocHelp = 46 | Just "Second example secret, bare or in a file, only env" 47 | } 48 | ] 49 | , AnyDocsOr [] 50 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/three-commands/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsCommands 2 | (Just "one") 3 | [ CommandDoc 4 | { commandDocArgument = "one" 5 | , commandDocHelp = "first" 6 | , commandDocs = AnyDocsAnd [] 7 | } 8 | , CommandDoc 9 | { commandDocArgument = "two" 10 | , commandDocHelp = "second" 11 | , commandDocs = 12 | AnyDocsAnd 13 | [ AnyDocsSingle 14 | ConfDoc 15 | { confDocKeys = 16 | ( "number" :| [] 17 | , AnyOfSchema 18 | (NullSchema :| 19 | [ IntegerSchema 20 | Bounds 21 | { boundsLower = Just (-9223372036854775808) 22 | , boundsUpper = Just 9223372036854775807 23 | } 24 | ]) 25 | ) :| 26 | [] 27 | , confDocDefault = Nothing 28 | , confDocExamples = [ "5" ] 29 | , confDocHelp = Just "number" 30 | } 31 | , AnyDocsOr 32 | [ AnyDocsSingle 33 | ConfDoc 34 | { confDocKeys = 35 | ( "enable" :| [] , AnyOfSchema (NullSchema :| [ BoolSchema ]) ) :| 36 | [] 37 | , confDocDefault = Nothing 38 | , confDocExamples = [] 39 | , confDocHelp = Just "enable extra" 40 | } 41 | ] 42 | ] 43 | } 44 | , CommandDoc 45 | { commandDocArgument = "three-very-long-command-name" 46 | , commandDocHelp = "third" 47 | , commandDocs = AnyDocsAnd [] 48 | } 49 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/secret/help.txt: -------------------------------------------------------------------------------- 1 | Usage: secret --first-secret-file FILE_PATH [--second-secret SECRET | --second-secret-file FILE_PATH] [--second-secret SECRET | --second-secret-file FILE_PATH] 2 | 3 | Secrets example 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | First example secret 13 | option: --first-secret-file FILE_PATH 14 | env: FIRST_SECRET_FILE FILE_PATH 15 | config: 16 | first-secret-file: # or null 17 |  18 | 19 | Second example secret, bare or in a file 20 | option: --second-secret SECRET 21 | option: --second-secret-file FILE_PATH 22 | env: SECOND_SECRET SECRET 23 | env: SECOND_SECRET_FILE FILE_PATH 24 | config: 25 | second-secret: # or null 26 |  27 | config: 28 | second-secret-file: # or null 29 |  30 | 31 | Second example secret, bare or in a file, only option 32 | option: --second-secret SECRET 33 | option: --second-secret-file FILE_PATH 34 | 35 | Second example secret, bare or in a file, only env 36 | env: second-secret SECRET 37 | env: second-secret_FILE FILE_PATH 38 | 39 | Second example secret, bare or in a file, only conf 40 | config: 41 | second-secret: # or null 42 |  43 | config: 44 | second-secret-file: # or null 45 |  46 | 47 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/same-help/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: same-help [--int INT | --string STR] [--[no-]other] 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | int or string 11 | option: --int INT 12 | env: INT INT 13 | config: 14 | int: # or null 15 |  # 64 bit signed integer 16 | option: --string STR 17 | env: STRING STR 18 | config: 19 | string: # or null 20 |  21 | 22 | int or string 23 | switch: --[no-]other 24 | env: OTHER BOOL 25 | config: 26 | other: # or null 27 |  28 | 29 | Options: 30 | -h|--help Show this help text 31 | --version Output version information 32 | --int int or string 33 | --string int or string 34 | --[no-]other int or string 35 | 36 | Environment Variables: 37 | INT INT int or string 38 | STRING STR int or string 39 | OTHER BOOL int or string 40 | 41 | Configuration Values: 42 | int or string 43 | int: 44 | # or null 45 |  # 64 bit signed integer 46 | int or string 47 | string: 48 | # or null 49 |  50 | int or string 51 | other: 52 | # or null 53 |  54 | 55 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/greet/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsOr 3 | [ AnyDocsSingle 4 | (Just 5 | OptDoc 6 | { optDocTryArgument = False 7 | , optDocTrySwitch = False 8 | , optDocTryOption = True 9 | , optDocDasheds = [ DashedLong ('c' :| "onfig-file") ] 10 | , optDocDefault = Nothing 11 | , optDocExamples = [] 12 | , optDocMetavar = Just "FILE_PATH" 13 | , optDocHelp = Just "Path to the configuration file" 14 | }) 15 | ] 16 | , AnyDocsSingle 17 | (Just 18 | OptDoc 19 | { optDocTryArgument = False 20 | , optDocTrySwitch = False 21 | , optDocTryOption = True 22 | , optDocDasheds = 23 | [ DashedShort 'g' , DashedLong ('g' :| "reeting") ] 24 | , optDocDefault = Just "\"Hello\"" 25 | , optDocExamples = [ "Greetings" ] 26 | , optDocMetavar = Just "GREETING" 27 | , optDocHelp = Just "Greeting to use" 28 | }) 29 | , AnyDocsSingle 30 | (Just 31 | OptDoc 32 | { optDocTryArgument = True 33 | , optDocTrySwitch = False 34 | , optDocTryOption = False 35 | , optDocDasheds = [] 36 | , optDocDefault = Just "\"world\"" 37 | , optDocExamples = [] 38 | , optDocMetavar = Just "SUBJECT" 39 | , optDocHelp = Just "Who to greet" 40 | }) 41 | , AnyDocsSingle 42 | (Just 43 | OptDoc 44 | { optDocTryArgument = False 45 | , optDocTrySwitch = True 46 | , optDocTryOption = False 47 | , optDocDasheds = [ DashedShort 'p' , DashedLong ('p' :| "olite") ] 48 | , optDocDefault = Just "False" 49 | , optDocExamples = [] 50 | , optDocMetavar = Just "ANY" 51 | , optDocHelp = Just "Whether to be polite" 52 | }) 53 | ] -------------------------------------------------------------------------------- /TODO.smos: -------------------------------------------------------------------------------- 1 | version: 2.0.0 2 | value: 3 | - entry: OptEnvConf 4 | forest: 5 | - entry: checklist for new features 6 | forest: 7 | - Succesful parse test 8 | - Failing parse test with golden errors 9 | - golden show 10 | - golden documentation 11 | - golden lints 12 | - api usage test 13 | - put a metavar inside a reader? 14 | - helpers for parsing tests 15 | - 'errors: if the env var would fail to parse, fail, even if something before parses' 16 | - Default settings for xdg env vars 17 | - entry: Refactors 18 | forest: 19 | - set up weeder 20 | - don't depend on the terminfo on windows 21 | - header: try the lazy parsing in tryPP too 22 | contents: This would potentially save some IO actions being executed, but will 23 | be tricky to keep semantics the same 24 | - entry: Testing 25 | forest: 26 | - header: 'make the run tests comprehensive: at least one test for each parsing 27 | feature' 28 | contents: Setting up weeder does this automatically 29 | - set up doctests 30 | - make good tests for every branch of the runParser function 31 | - entry: Errors 32 | forest: 33 | - suggest typos when options aren't recognised 34 | - maybe show the settings that were defined when throwing the AllOrNothing error 35 | - entry: Documentation 36 | forest: 37 | - 'help with multiple lines: help chunks return lines' 38 | - header: make the alts a list for nicer showing? 39 | contents: then we can get rid of empty too 40 | - make the short opts multi-line when commands are in use 41 | - make the short opts multi-line when there are many 42 | - make multiline help look good too 43 | - make the manpage look great 44 | - when parsing two of the same config values, show them with an or instead of 45 | showing the schema twice 46 | - no need for the extra indent in the settings part of the manpage 47 | - Have 'renderCommandHelpPage' also gather global options on the way 48 | - get rid of all todos 49 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-settings/show.txt: -------------------------------------------------------------------------------- 1 | WithConfig 2 | _ 3 | Nothing 4 | (Check 5 | Nothing 6 | False 7 | (fromList []) 8 | _ 9 | (Alt 10 | (Check 11 | Nothing 12 | False 13 | (fromList []) 14 | _ 15 | (Setting 16 | Nothing 17 | (Setting 18 | [ DashedLong ('c' :| "onfig-file") ] 19 | [ _ ] 20 | False 21 | Nothing 22 | True 23 | (Just 24 | (EnvVarSetting 25 | { envVarSettingVar = "CONFIG_FILE" 26 | , envVarSettingAllowPrefix = True 27 | } :| 28 | [])) 29 | Nothing 30 | Nothing 31 | [] 32 | False 33 | (Just "FILE_PATH") 34 | (Just "Path to the configuration file") 35 | (Just _) 36 | (fromList [])))) 37 | (Check Nothing False (fromList []) _ (Pure _)))) 38 | (Setting 39 | Nothing 40 | (Setting 41 | [ DashedLong ('f' :| "oo-bar-quux") ] 42 | [ _ ] 43 | False 44 | Nothing 45 | True 46 | (Just 47 | (EnvVarSetting 48 | { envVarSettingVar = "FOO_BAR_QUUX" 49 | , envVarSettingAllowPrefix = True 50 | } :| 51 | [])) 52 | (Just 53 | (ConfigValSetting 54 | ("foo" :| [ "bar" , "quux" ]) 55 | BimapCodec 56 | _ 57 | _ 58 | (EitherCodec 59 | PossiblyJointUnion 60 | NullCodec 61 | (BimapCodec _ _ (StringCodec Nothing))) :| 62 | [])) 63 | Nothing 64 | [] 65 | False 66 | (Just "STR") 67 | (Just "Example with sub-settings") 68 | Nothing 69 | (fromList []))) -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-commands/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsOr [] 3 | , AnyDocsCommands 4 | Nothing 5 | [ CommandDoc 6 | { commandDocArgument = "top" 7 | , commandDocHelp = "command without subcommands" 8 | , commandDocs = 9 | AnyDocsSingle 10 | ConfDoc 11 | { confDocKeys = 12 | ( "name" :| [] , AnyOfSchema (NullSchema :| [ StringSchema ]) ) :| 13 | [] 14 | , confDocDefault = Nothing 15 | , confDocExamples = [ "john" ] 16 | , confDocHelp = Just "name" 17 | } 18 | } 19 | , CommandDoc 20 | { commandDocArgument = "sub" 21 | , commandDocHelp = "command with subcommands" 22 | , commandDocs = 23 | AnyDocsAnd 24 | [ AnyDocsCommands 25 | Nothing 26 | [ CommandDoc 27 | { commandDocArgument = "a" 28 | , commandDocHelp = "A" 29 | , commandDocs = AnyDocsAnd [] 30 | } 31 | , CommandDoc 32 | { commandDocArgument = "b" 33 | , commandDocHelp = "B" 34 | , commandDocs = AnyDocsAnd [] 35 | } 36 | ] 37 | , AnyDocsCommands 38 | (Just "c") 39 | [ CommandDoc 40 | { commandDocArgument = "c" 41 | , commandDocHelp = "C" 42 | , commandDocs = AnyDocsAnd [] 43 | } 44 | , CommandDoc 45 | { commandDocArgument = "d" 46 | , commandDocHelp = "D" 47 | , commandDocs = AnyDocsAnd [] 48 | } 49 | ] 50 | ] 51 | } 52 | ] 53 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-commands/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: sub-commands [--config-file FILE_PATH] COMMAND 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | Path to the configuration file 11 | option: --config-file FILE_PATH 12 | env: CONFIG_FILE FILE_PATH 13 | 14 | All commands: 15 | command without subcommands 16 | command: top 17 | name 18 | option: --name NAME 19 | env: NAME NAME 20 | config: 21 | name: # or null 22 |  23 | example: john 24 | 25 | 26 | command with subcommands 27 | command: sub 28 | A 29 | command: a 30 | 31 | B 32 | command: b 33 | 34 | C 35 | command: c (default) 36 | 37 | D 38 | command: d 39 | 40 | 41 | 42 | Options: 43 | -h|--help Show this help text 44 | --version Output version information 45 | --config-file Path to the configuration file 46 | top command without subcommands 47 | --name name example: john 48 | sub command with subcommands 49 | a A 50 | b B 51 | c (default) C 52 | d D 53 | 54 | Environment Variables: 55 | CONFIG_FILE FILE_PATH Path to the configuration file 56 | NAME NAME name example: john 57 | 58 | Configuration Values: 59 | name 60 | example: john 61 | name: 62 | # or null 63 |  64 | 65 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/three-commands/reference.txt: -------------------------------------------------------------------------------- 1 | Usage: three-commands [COMMAND] 2 | 3 | All settings: 4 | Show this help text 5 | switch: -h|--help 6 | 7 | Output version information 8 | switch: --version 9 | 10 | All commands: 11 | first 12 | command: one (default) 13 | argument 14 | argument: STR 15 | 16 | 17 | second 18 | command: two 19 | number 20 | option: --number|-n INT 21 | env: NUMBER INT 22 | config: 23 | number: # or null 24 |  # 64 bit signed integer 25 | example: 5 26 | 27 | enable extra 28 | switch: --(enable|disable)-enable 29 | env: ENABLE BOOL 30 | config: 31 | enable: # or null 32 |  33 | 34 | 35 | third 36 | command: three-very-long-command-name 37 | 38 | 39 | Options: 40 | -h|--help Show this help text 41 | --version Output version information 42 | one (default) first 43 | STR argument 44 | two second 45 | --number|-n number example: 5 46 | --(enable|disable)-enable enable extra 47 | three-very-long-command-name third 48 | 49 | Environment Variables: 50 | NUMBER INT number example: 5 51 | ENABLE BOOL enable extra 52 | 53 | Configuration Values: 54 | number 55 | example: 5 56 | number: 57 | # or null 58 |  # 64 bit signed integer 59 | enable extra 60 | enable: 61 | # or null 62 |  63 | 64 | -------------------------------------------------------------------------------- /opt-env-conf-test/test/OptEnvConf/ReaderSpec.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE LambdaCase #-} 2 | {-# LANGUAGE OverloadedLists #-} 3 | {-# LANGUAGE OverloadedStrings #-} 4 | 5 | module OptEnvConf.ReaderSpec (spec) where 6 | 7 | import Data.GenValidity.Text () 8 | import Data.List.NonEmpty (NonEmpty (..)) 9 | import OptEnvConf.Reader 10 | import Test.Syd 11 | import Test.Syd.Validity 12 | 13 | spec :: Spec 14 | spec = do 15 | describe "renderCommaSeparated" $ 16 | it "escapes commas and backslashes" $ 17 | renderCommaSeparated ("hi" :| [",", "\\", "ho"]) 18 | `shouldBe` "hi,\\,,\\\\,ho" 19 | 20 | describe "parseCommaSeparated" $ do 21 | it "roundtrips with renderCommaSeparated starting from Strings" $ 22 | forAllValid $ \s -> 23 | renderCommaSeparated (parseCommaSeparated s) 24 | `shouldBe` s 25 | it "roundtrips with renderCommaSeparated starting from lists" $ 26 | forAllValid $ \l -> 27 | parseCommaSeparated (renderCommaSeparated l) `shouldBe` l 28 | 29 | describe "commaSeparated" $ do 30 | it "can parse these two ints" $ 31 | runReader (commaSeparated auto) "1,2" 32 | `shouldBe` Right [1, 2 :: Int] 33 | 34 | describe "commaSeparatedList" $ do 35 | it "can parse these two ints" $ 36 | runReader (commaSeparatedList auto) "3, 4" 37 | `shouldBe` Right [3, 4 :: Int] 38 | 39 | describe "commaSeparatedSet" $ do 40 | it "can parse these two ints" $ 41 | runReader (commaSeparatedSet auto) "5, 6" 42 | `shouldBe` Right [5, 6 :: Int] 43 | 44 | describe "maybeReader" $ 45 | it "can parse a bool using this example reader" $ do 46 | let r = maybeReader $ \case 47 | "true" -> Just True 48 | "false" -> Just False 49 | _ -> Nothing 50 | runReader r "true" `shouldBe` Right True 51 | runReader r "false" `shouldBe` Right False 52 | runReader r "yes" `shouldBe` Left "Unparseable value: \"yes\"" 53 | 54 | describe "viaStringCodec" $ 55 | it "can parse a string via its string codec" $ 56 | runReader viaStringCodec "hi" `shouldBe` Right ("hi" :: String) 57 | -------------------------------------------------------------------------------- /opt-env-conf/src/OptEnvConf/Capability.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE DeriveGeneric #-} 2 | {-# LANGUAGE DerivingStrategies #-} 3 | {-# LANGUAGE GeneralizedNewtypeDeriving #-} 4 | 5 | module OptEnvConf.Capability 6 | ( Capabilities (..), 7 | Capability (..), 8 | allCapabilities, 9 | enableCapability, 10 | disableCapability, 11 | missingCapabilities, 12 | 13 | -- * Predefined capabilities 14 | readSecretCapability, 15 | ) 16 | where 17 | 18 | import Data.List.NonEmpty (NonEmpty (..)) 19 | import qualified Data.List.NonEmpty as NE 20 | import Data.Set (Set) 21 | import qualified Data.Set as Set 22 | import Data.String 23 | import Data.Text (Text) 24 | import Data.Validity 25 | import Data.Validity.Containers () 26 | import Data.Validity.Text () 27 | import GHC.Generics (Generic) 28 | 29 | -- Set of disabled capabilities 30 | newtype Capabilities = Capabilities {unCapabilities :: Set Capability} 31 | deriving (Show, Generic) 32 | 33 | instance Validity Capabilities 34 | 35 | allCapabilities :: Capabilities 36 | allCapabilities = Capabilities {unCapabilities = Set.empty} 37 | 38 | enableCapability :: Capability -> Capabilities -> Capabilities 39 | enableCapability cap (Capabilities caps) = 40 | Capabilities (Set.delete cap caps) 41 | 42 | disableCapability :: Capability -> Capabilities -> Capabilities 43 | disableCapability cap (Capabilities caps) = 44 | Capabilities (Set.insert cap caps) 45 | 46 | missingCapabilities :: Capabilities -> Set Capability -> Maybe (NonEmpty Capability) 47 | missingCapabilities (Capabilities caps) requiredCapabilities = 48 | NE.nonEmpty (Set.toList (Set.intersection requiredCapabilities caps)) 49 | 50 | newtype Capability = Capability {unCapability :: Text} 51 | deriving stock (Generic) 52 | deriving newtype (Show, Eq, Ord, IsString) 53 | 54 | instance Validity Capability 55 | 56 | -- | The annotation for any setting reading secrets. 57 | -- 58 | -- We add these so that we can disable them in settings checks, to avoid 59 | -- failing settings checks when secrets are read at runtime instead of 60 | -- build-time. 61 | readSecretCapability :: String 62 | readSecretCapability = "read-secret" 63 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no/docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsSingle Nothing 3 | , AnyDocsOr 4 | [ AnyDocsSingle 5 | (Just 6 | SetDoc 7 | { setDocTryArgument = False 8 | , setDocTrySwitch = True 9 | , setDocTryOption = False 10 | , setDocDasheds = [ DashedLong ('[' :| "no-]example") ] 11 | , setDocEnvVars = Nothing 12 | , setDocConfKeys = Nothing 13 | , setDocDefault = Nothing 14 | , setDocExamples = [] 15 | , setDocMetavar = Nothing 16 | , setDocHelp = Just "Example of a yes/no switch" 17 | }) 18 | , AnyDocsSingle Nothing 19 | , AnyDocsSingle Nothing 20 | , AnyDocsSingle 21 | (Just 22 | SetDoc 23 | { setDocTryArgument = False 24 | , setDocTrySwitch = False 25 | , setDocTryOption = False 26 | , setDocDasheds = [] 27 | , setDocEnvVars = Just ("EXAMPLE" :| []) 28 | , setDocConfKeys = Nothing 29 | , setDocDefault = Nothing 30 | , setDocExamples = [] 31 | , setDocMetavar = Just "BOOL" 32 | , setDocHelp = Just "Example of a yes/no switch" 33 | }) 34 | , AnyDocsSingle 35 | (Just 36 | SetDoc 37 | { setDocTryArgument = False 38 | , setDocTrySwitch = False 39 | , setDocTryOption = False 40 | , setDocDasheds = [] 41 | , setDocEnvVars = Nothing 42 | , setDocConfKeys = 43 | Just 44 | (( "example" :| [] 45 | , AnyOfSchema (NullSchema :| [ BoolSchema ]) 46 | ) :| 47 | []) 48 | , setDocDefault = Nothing 49 | , setDocExamples = [] 50 | , setDocMetavar = Nothing 51 | , setDocHelp = Just "Example of a yes/no switch" 52 | }) 53 | , AnyDocsSingle Nothing 54 | ] 55 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/greet/man.txt: -------------------------------------------------------------------------------- 1 | .Dd $Mdocdate$ 2 | .Dt greet 1 3 | .Os 4 | .Sh NAME 5 | .Nm greet 6 | .Nd hello world example 7 | .Sh VERSION 8 | 0.0.0 9 | .Sh SYNOPSIS 10 | greet [--config-file FILE_PATH] [-g|--greeting GREETING] [SUBJECT] [-p|--polite] 11 | .Sh SETTINGS 12 | Show this help text 13 | switch: -h|--help 14 | 15 | Output version information: 0.0.0 16 | switch: --version 17 | 18 | Path to the configuration file 19 | option: --config-file FILE_PATH 20 | env: GREET_CONFIG_FILE FILE_PATH 21 | 22 | Greeting to use 23 | option: -g|--greeting GREETING 24 | env: GREET_GREETING GREETING 25 | config: 26 | greeting: # or null 27 | 28 | default: "Hello" 29 | example: Greetings 30 | 31 | Who to greet 32 | argument: SUBJECT 33 | default: "world" 34 | 35 | Whether to be polite 36 | switch: -p|--polite 37 | env: GREET_POLITE ANY 38 | config: 39 | polite: # or null 40 | 41 | default: False 42 | 43 | .Sh OPTIONS 44 | -h|--help Show this help text 45 | --version Output version information: 0.0.0 46 | --config-file Path to the configuration file 47 | -g|--greeting Greeting to use default: "Hello" example: Greetings 48 | SUBJECT Who to greet default: "world" 49 | -p|--polite Whether to be polite default: False 50 | 51 | .Sh ENVIRONMENT VARIABLES 52 | GREET_CONFIG_FILE FILE_PATH Path to the configuration file 53 | GREET_GREETING GREETING Greeting to use default: "Hello" example: Greetings 54 | GREET_POLITE ANY Whether to be polite default: False 55 | 56 | .Sh CONFIGURATION VALUES 57 | Greeting to use 58 | default: "Hello" 59 | example: Greetings 60 | greeting: 61 | # or null 62 | 63 | Whether to be polite 64 | default: False 65 | polite: 66 | # or null 67 | 68 | 69 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/yes-no-optional/docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsSingle Nothing 3 | , AnyDocsOr 4 | [ AnyDocsSingle 5 | (Just 6 | SetDoc 7 | { setDocTryArgument = False 8 | , setDocTrySwitch = True 9 | , setDocTryOption = False 10 | , setDocDasheds = [ DashedLong ('[' :| "no-]example") ] 11 | , setDocEnvVars = Nothing 12 | , setDocConfKeys = Nothing 13 | , setDocDefault = Nothing 14 | , setDocExamples = [] 15 | , setDocMetavar = Nothing 16 | , setDocHelp = Just "Example of a yes/no switch" 17 | }) 18 | , AnyDocsSingle Nothing 19 | , AnyDocsSingle Nothing 20 | , AnyDocsSingle 21 | (Just 22 | SetDoc 23 | { setDocTryArgument = False 24 | , setDocTrySwitch = False 25 | , setDocTryOption = False 26 | , setDocDasheds = [] 27 | , setDocEnvVars = Just ("EXAMPLE" :| []) 28 | , setDocConfKeys = Nothing 29 | , setDocDefault = Nothing 30 | , setDocExamples = [] 31 | , setDocMetavar = Just "BOOL" 32 | , setDocHelp = Just "Example of a yes/no switch" 33 | }) 34 | , AnyDocsSingle 35 | (Just 36 | SetDoc 37 | { setDocTryArgument = False 38 | , setDocTrySwitch = False 39 | , setDocTryOption = False 40 | , setDocDasheds = [] 41 | , setDocEnvVars = Nothing 42 | , setDocConfKeys = 43 | Just 44 | (( "example" :| [] 45 | , AnyOfSchema (NullSchema :| [ BoolSchema ]) 46 | ) :| 47 | []) 48 | , setDocDefault = Nothing 49 | , setDocExamples = [] 50 | , setDocMetavar = Nothing 51 | , setDocHelp = Just "Example of a yes/no switch" 52 | }) 53 | , AnyDocsSingle Nothing 54 | ] 55 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable/docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsSingle Nothing 3 | , AnyDocsOr 4 | [ AnyDocsSingle 5 | (Just 6 | SetDoc 7 | { setDocTryArgument = False 8 | , setDocTrySwitch = True 9 | , setDocTryOption = False 10 | , setDocDasheds = [ DashedLong ('(' :| "enable|disable)-example") ] 11 | , setDocEnvVars = Nothing 12 | , setDocConfKeys = Nothing 13 | , setDocDefault = Nothing 14 | , setDocExamples = [] 15 | , setDocMetavar = Nothing 16 | , setDocHelp = Just "Example of an enable/disable switch" 17 | }) 18 | , AnyDocsSingle Nothing 19 | , AnyDocsSingle Nothing 20 | , AnyDocsSingle 21 | (Just 22 | SetDoc 23 | { setDocTryArgument = False 24 | , setDocTrySwitch = False 25 | , setDocTryOption = False 26 | , setDocDasheds = [] 27 | , setDocEnvVars = Just ("EXAMPLE" :| []) 28 | , setDocConfKeys = Nothing 29 | , setDocDefault = Nothing 30 | , setDocExamples = [] 31 | , setDocMetavar = Just "BOOL" 32 | , setDocHelp = Just "Example of an enable/disable switch" 33 | }) 34 | , AnyDocsSingle 35 | (Just 36 | SetDoc 37 | { setDocTryArgument = False 38 | , setDocTrySwitch = False 39 | , setDocTryOption = False 40 | , setDocDasheds = [] 41 | , setDocEnvVars = Nothing 42 | , setDocConfKeys = 43 | Just 44 | (( "example" :| [] 45 | , AnyOfSchema (NullSchema :| [ BoolSchema ]) 46 | ) :| 47 | []) 48 | , setDocDefault = Nothing 49 | , setDocExamples = [] 50 | , setDocMetavar = Nothing 51 | , setDocHelp = Just "Example of an enable/disable switch" 52 | }) 53 | , AnyDocsSingle Nothing 54 | ] 55 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/enable-disable-optional/docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsSingle Nothing 3 | , AnyDocsOr 4 | [ AnyDocsSingle 5 | (Just 6 | SetDoc 7 | { setDocTryArgument = False 8 | , setDocTrySwitch = True 9 | , setDocTryOption = False 10 | , setDocDasheds = [ DashedLong ('(' :| "enable|disable)-example") ] 11 | , setDocEnvVars = Nothing 12 | , setDocConfKeys = Nothing 13 | , setDocDefault = Nothing 14 | , setDocExamples = [] 15 | , setDocMetavar = Nothing 16 | , setDocHelp = Just "Example of an enable/disable switch" 17 | }) 18 | , AnyDocsSingle Nothing 19 | , AnyDocsSingle Nothing 20 | , AnyDocsSingle 21 | (Just 22 | SetDoc 23 | { setDocTryArgument = False 24 | , setDocTrySwitch = False 25 | , setDocTryOption = False 26 | , setDocDasheds = [] 27 | , setDocEnvVars = Just ("EXAMPLE" :| []) 28 | , setDocConfKeys = Nothing 29 | , setDocDefault = Nothing 30 | , setDocExamples = [] 31 | , setDocMetavar = Just "BOOL" 32 | , setDocHelp = Just "Example of an enable/disable switch" 33 | }) 34 | , AnyDocsSingle 35 | (Just 36 | SetDoc 37 | { setDocTryArgument = False 38 | , setDocTrySwitch = False 39 | , setDocTryOption = False 40 | , setDocDasheds = [] 41 | , setDocEnvVars = Nothing 42 | , setDocConfKeys = 43 | Just 44 | (( "example" :| [] 45 | , AnyOfSchema (NullSchema :| [ BoolSchema ]) 46 | ) :| 47 | []) 48 | , setDocDefault = Nothing 49 | , setDocExamples = [] 50 | , setDocMetavar = Nothing 51 | , setDocHelp = Just "Example of an enable/disable switch" 52 | }) 53 | , AnyDocsSingle Nothing 54 | ] 55 | ] -------------------------------------------------------------------------------- /opt-env-conf/opt-env-conf.cabal: -------------------------------------------------------------------------------- 1 | cabal-version: 1.12 2 | 3 | -- This file has been generated from package.yaml by hpack version 0.36.1. 4 | -- 5 | -- see: https://github.com/sol/hpack 6 | 7 | name: opt-env-conf 8 | version: 0.14.0.0 9 | synopsis: Settings parsing for Haskell: command-line arguments, environment variables, and configuration values. 10 | homepage: https://github.com/NorfairKing/opt-env-conf#readme 11 | bug-reports: https://github.com/NorfairKing/opt-env-conf/issues 12 | author: Tom Sydney Kerckhove 13 | maintainer: syd@cs-syd.eu 14 | copyright: Copyright: (c) 2024-2025 Tom Sydney Kerckhove 15 | license: LGPL-3 16 | license-file: LICENSE 17 | build-type: Simple 18 | extra-source-files: 19 | CHANGELOG.md 20 | 21 | source-repository head 22 | type: git 23 | location: https://github.com/NorfairKing/opt-env-conf 24 | 25 | library 26 | exposed-modules: 27 | OptEnvConf 28 | OptEnvConf.Args 29 | OptEnvConf.Capability 30 | OptEnvConf.Casing 31 | OptEnvConf.Check 32 | OptEnvConf.Completer 33 | OptEnvConf.Completion 34 | OptEnvConf.Doc 35 | OptEnvConf.EnvMap 36 | OptEnvConf.Error 37 | OptEnvConf.Lint 38 | OptEnvConf.Main 39 | OptEnvConf.Nix 40 | OptEnvConf.NonDet 41 | OptEnvConf.Output 42 | OptEnvConf.Parser 43 | OptEnvConf.Reader 44 | OptEnvConf.Run 45 | OptEnvConf.Setting 46 | OptEnvConf.Terminal 47 | OptEnvConf.Validation 48 | other-modules: 49 | Paths_opt_env_conf 50 | hs-source-dirs: 51 | src/ 52 | ghc-options: -Wall 53 | build-depends: 54 | aeson 55 | , autodocodec >=0.3.0.0 56 | , autodocodec-nix 57 | , autodocodec-schema 58 | , autodocodec-yaml 59 | , base <5 60 | , containers 61 | , hashable 62 | , mtl 63 | , path 64 | , path-io 65 | , safe-coloured-text >=0.3.0.2 66 | , safe-coloured-text-layout >=0.2.0.0 67 | , selective 68 | , text 69 | , validity 70 | , validity-containers 71 | , validity-text 72 | default-language: Haskell2010 73 | if !os(windows) 74 | build-depends: 75 | safe-coloured-text-terminfo 76 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/help/toplevel-pure.txt: -------------------------------------------------------------------------------- 1 | Usage: example [--config-file FILE_PATH] [--port PORT] [--log-level LOG_LEVEL] [--payment-public-key PUBLIC_KEY --payment-secret-key FILE_PATH [--payment-currency CURRENCY]] COMMAND 2 | 3 | example program description 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Path to the configuration file 13 | option: --config-file FILE_PATH 14 | env: CONFIG_FILE FILE_PATH 15 | 16 | port to serve requests on 17 | option: --port PORT 18 | env: PORT PORT 19 | config: 20 | port: # or null 21 |  # 16 bit unsigned integer 22 | default: 8080 23 | 24 | minimal severity of log messages 25 | option: --log-level LOG_LEVEL 26 | env: LOG_LEVEL LOG_LEVEL 27 | config: 28 | log-level: # or null 29 |  30 | default: "DEBUG" 31 | 32 | Public key 33 | option: --payment-public-key PUBLIC_KEY 34 | env: PAYMENT_PUBLIC_KEY PUBLIC_KEY 35 | config: 36 | payment.public-key: # or null 37 |  38 | 39 | Secret key 40 | option: --payment-secret-key FILE_PATH 41 | env: PAYMENT_SECRET_KEY FILE_PATH 42 | config: 43 | payment.secret-key: # or null 44 |  45 | 46 | Currency 47 | option: --payment-currency CURRENCY 48 | env: PAYMENT_CURRENCY CURRENCY 49 | config: 50 | payment.currency: # or null 51 |  52 | 53 | Available commands: 54 | read read command explanation 55 | create create command explanation 56 | sub command with subcommand 57 | 58 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/help/wrong-command.txt: -------------------------------------------------------------------------------- 1 | Usage: example [--config-file FILE_PATH] [--port PORT] [--log-level LOG_LEVEL] [--payment-public-key PUBLIC_KEY --payment-secret-key FILE_PATH [--payment-currency CURRENCY]] COMMAND 2 | 3 | example program description 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Path to the configuration file 13 | option: --config-file FILE_PATH 14 | env: CONFIG_FILE FILE_PATH 15 | 16 | port to serve requests on 17 | option: --port PORT 18 | env: PORT PORT 19 | config: 20 | port: # or null 21 |  # 16 bit unsigned integer 22 | default: 8080 23 | 24 | minimal severity of log messages 25 | option: --log-level LOG_LEVEL 26 | env: LOG_LEVEL LOG_LEVEL 27 | config: 28 | log-level: # or null 29 |  30 | default: "DEBUG" 31 | 32 | Public key 33 | option: --payment-public-key PUBLIC_KEY 34 | env: PAYMENT_PUBLIC_KEY PUBLIC_KEY 35 | config: 36 | payment.public-key: # or null 37 |  38 | 39 | Secret key 40 | option: --payment-secret-key FILE_PATH 41 | env: PAYMENT_SECRET_KEY FILE_PATH 42 | config: 43 | payment.secret-key: # or null 44 |  45 | 46 | Currency 47 | option: --payment-currency CURRENCY 48 | env: PAYMENT_CURRENCY CURRENCY 49 | config: 50 | payment.currency: # or null 51 |  52 | 53 | Available commands: 54 | read read command explanation 55 | create create command explanation 56 | sub command with subcommand 57 | 58 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/secret/env-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsSingle 3 | ConfDoc 4 | { confDocKeys = 5 | ( "first-secret-file" :| [] 6 | , AnyOfSchema (NullSchema :| [ StringSchema ]) 7 | ) :| 8 | [] 9 | , confDocDefault = Nothing 10 | , confDocExamples = [] 11 | , confDocHelp = Just "First example secret" 12 | } 13 | , AnyDocsOr 14 | [ AnyDocsSingle 15 | ConfDoc 16 | { confDocKeys = 17 | ( "second-secret" :| [] 18 | , AnyOfSchema (NullSchema :| [ StringSchema ]) 19 | ) :| 20 | [] 21 | , confDocDefault = Nothing 22 | , confDocExamples = [] 23 | , confDocHelp = Just "Second example secret, bare or in a file" 24 | } 25 | , AnyDocsSingle 26 | ConfDoc 27 | { confDocKeys = 28 | ( "second-secret-file" :| [] 29 | , AnyOfSchema (NullSchema :| [ StringSchema ]) 30 | ) :| 31 | [] 32 | , confDocDefault = Nothing 33 | , confDocExamples = [] 34 | , confDocHelp = Just "Second example secret, bare or in a file" 35 | } 36 | ] 37 | , AnyDocsOr [] 38 | , AnyDocsOr [] 39 | , AnyDocsOr 40 | [ AnyDocsSingle 41 | ConfDoc 42 | { confDocKeys = 43 | ( "second-secret" :| [] 44 | , AnyOfSchema (NullSchema :| [ StringSchema ]) 45 | ) :| 46 | [] 47 | , confDocDefault = Nothing 48 | , confDocExamples = [] 49 | , confDocHelp = 50 | Just "Second example secret, bare or in a file, only conf" 51 | } 52 | , AnyDocsSingle 53 | ConfDoc 54 | { confDocKeys = 55 | ( "second-secret-file" :| [] 56 | , AnyOfSchema (NullSchema :| [ StringSchema ]) 57 | ) :| 58 | [] 59 | , confDocDefault = Nothing 60 | , confDocExamples = [] 61 | , confDocHelp = 62 | Just "Second example secret, bare or in a file, only conf" 63 | } 64 | ] 65 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/help/toplevel-pure-with-invalid-port.txt: -------------------------------------------------------------------------------- 1 | Usage: example [--config-file FILE_PATH] [--port PORT] [--log-level LOG_LEVEL] [--payment-public-key PUBLIC_KEY --payment-secret-key FILE_PATH [--payment-currency CURRENCY]] COMMAND 2 | 3 | example program description 4 | 5 | Available settings: 6 | Show this help text 7 | switch: -h|--help 8 | 9 | Output version information: 0.0.0 10 | switch: --version 11 | 12 | Path to the configuration file 13 | option: --config-file FILE_PATH 14 | env: CONFIG_FILE FILE_PATH 15 | 16 | port to serve requests on 17 | option: --port PORT 18 | env: PORT PORT 19 | config: 20 | port: # or null 21 |  # 16 bit unsigned integer 22 | default: 8080 23 | 24 | minimal severity of log messages 25 | option: --log-level LOG_LEVEL 26 | env: LOG_LEVEL LOG_LEVEL 27 | config: 28 | log-level: # or null 29 |  30 | default: "DEBUG" 31 | 32 | Public key 33 | option: --payment-public-key PUBLIC_KEY 34 | env: PAYMENT_PUBLIC_KEY PUBLIC_KEY 35 | config: 36 | payment.public-key: # or null 37 |  38 | 39 | Secret key 40 | option: --payment-secret-key FILE_PATH 41 | env: PAYMENT_SECRET_KEY FILE_PATH 42 | config: 43 | payment.secret-key: # or null 44 |  45 | 46 | Currency 47 | option: --payment-currency CURRENCY 48 | env: PAYMENT_CURRENCY CURRENCY 49 | config: 50 | payment.currency: # or null 51 |  52 | 53 | Available commands: 54 | read read command explanation 55 | create create command explanation 56 | sub command with subcommand 57 | 58 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/sub-commands/config-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsOr 3 | [ AnyDocsSingle 4 | EnvDoc 5 | { envDocVars = "CONFIG_FILE" :| [] 6 | , envDocDefault = Nothing 7 | , envDocExamples = [] 8 | , envDocMetavar = Just "FILE_PATH" 9 | , envDocHelp = Just "Path to the configuration file" 10 | } 11 | ] 12 | , AnyDocsCommands 13 | Nothing 14 | [ CommandDoc 15 | { commandDocArgument = "top" 16 | , commandDocHelp = "command without subcommands" 17 | , commandDocs = 18 | AnyDocsSingle 19 | EnvDoc 20 | { envDocVars = "NAME" :| [] 21 | , envDocDefault = Nothing 22 | , envDocExamples = [ "john" ] 23 | , envDocMetavar = Just "NAME" 24 | , envDocHelp = Just "name" 25 | } 26 | } 27 | , CommandDoc 28 | { commandDocArgument = "sub" 29 | , commandDocHelp = "command with subcommands" 30 | , commandDocs = 31 | AnyDocsAnd 32 | [ AnyDocsCommands 33 | Nothing 34 | [ CommandDoc 35 | { commandDocArgument = "a" 36 | , commandDocHelp = "A" 37 | , commandDocs = AnyDocsAnd [] 38 | } 39 | , CommandDoc 40 | { commandDocArgument = "b" 41 | , commandDocHelp = "B" 42 | , commandDocs = AnyDocsAnd [] 43 | } 44 | ] 45 | , AnyDocsCommands 46 | (Just "c") 47 | [ CommandDoc 48 | { commandDocArgument = "c" 49 | , commandDocHelp = "C" 50 | , commandDocs = AnyDocsAnd [] 51 | } 52 | , CommandDoc 53 | { commandDocArgument = "d" 54 | , commandDocHelp = "D" 55 | , commandDocs = AnyDocsAnd [] 56 | } 57 | ] 58 | ] 59 | } 60 | ] 61 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/three-commands/opt-docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsCommands 2 | (Just "one") 3 | [ CommandDoc 4 | { commandDocArgument = "one" 5 | , commandDocHelp = "first" 6 | , commandDocs = 7 | AnyDocsSingle 8 | (Just 9 | OptDoc 10 | { optDocTryArgument = True 11 | , optDocTrySwitch = False 12 | , optDocTryOption = False 13 | , optDocDasheds = [] 14 | , optDocDefault = Nothing 15 | , optDocExamples = [] 16 | , optDocMetavar = Just "STR" 17 | , optDocHelp = Just "argument" 18 | }) 19 | } 20 | , CommandDoc 21 | { commandDocArgument = "two" 22 | , commandDocHelp = "second" 23 | , commandDocs = 24 | AnyDocsAnd 25 | [ AnyDocsSingle 26 | (Just 27 | OptDoc 28 | { optDocTryArgument = False 29 | , optDocTrySwitch = False 30 | , optDocTryOption = True 31 | , optDocDasheds = [ DashedLong ('n' :| "umber") , DashedShort 'n' ] 32 | , optDocDefault = Nothing 33 | , optDocExamples = [ "5" ] 34 | , optDocMetavar = Just "INT" 35 | , optDocHelp = Just "number" 36 | }) 37 | , AnyDocsOr 38 | [ AnyDocsSingle 39 | (Just 40 | OptDoc 41 | { optDocTryArgument = False 42 | , optDocTrySwitch = True 43 | , optDocTryOption = False 44 | , optDocDasheds = [ DashedLong ('(' :| "enable|disable)-enable") ] 45 | , optDocDefault = Nothing 46 | , optDocExamples = [] 47 | , optDocMetavar = Nothing 48 | , optDocHelp = Just "enable extra" 49 | }) 50 | , AnyDocsSingle Nothing 51 | , AnyDocsSingle Nothing 52 | ] 53 | ] 54 | } 55 | , CommandDoc 56 | { commandDocArgument = "three-very-long-command-name" 57 | , commandDocHelp = "third" 58 | , commandDocs = AnyDocsAnd [] 59 | } 60 | ] -------------------------------------------------------------------------------- /opt-env-conf-test/test/OptEnvConf/ToplevelSpec.hs: -------------------------------------------------------------------------------- 1 | module OptEnvConf.ToplevelSpec where 2 | 3 | import Data.Version 4 | import OptEnvConf 5 | import System.Environment 6 | import System.Exit 7 | import Test.Syd 8 | 9 | spec :: Spec 10 | spec = do 11 | let dummyVersion = makeVersion [0, 0, 0] 12 | let dummyProgDesc = "dummy" 13 | let dummyParser = pure 'a' 14 | let dummyRun = runParser dummyVersion dummyProgDesc dummyParser 15 | sequential $ do 16 | it "can fail fast when too many unrecognsied arguments are given" $ 17 | withArgs ["-option1", "option", "--option2", "option", "--option3", "option", "--option4", "option"] $ 18 | dummyRun `shouldThrow` (== ExitFailure 1) 19 | 20 | describe "--help" $ do 21 | it "can show help text with --help" $ 22 | withArgs ["--help"] $ 23 | dummyRun `shouldThrow` (== ExitSuccess) 24 | it "can show help text with --help even when there are more args" $ 25 | withArgs ["--help", "more", "args", "here"] $ 26 | dummyRun `shouldThrow` (== ExitSuccess) 27 | it "can show help text with -h" $ 28 | withArgs ["-h"] $ 29 | dummyRun `shouldThrow` (== ExitSuccess) 30 | it "can show help text with --help even when there are more args" $ 31 | withArgs ["-h", "more", "args", "here"] $ 32 | dummyRun `shouldThrow` (== ExitSuccess) 33 | 34 | describe "--version" $ do 35 | it "can show version info with --version" $ 36 | withArgs ["--version"] $ 37 | dummyRun `shouldThrow` (== ExitSuccess) 38 | 39 | describe "--run-settings-check" $ do 40 | it "can run a settings check with --run-settings-check" $ 41 | withArgs ["--run-settings-check"] $ 42 | dummyRun `shouldThrow` (== ExitSuccess) 43 | it "can run a settings check with --run-settings-check even when there are more args" $ 44 | withArgs ["--run-settings-check", "more", "args", "here"] $ 45 | runParser 46 | dummyVersion 47 | dummyProgDesc 48 | ( many 49 | ( setting 50 | [ help "something that reads args", 51 | argument, 52 | reader str, 53 | metavar "STR" 54 | ] 55 | ) :: 56 | Parser [String] 57 | ) 58 | `shouldThrow` (== ExitSuccess) 59 | -------------------------------------------------------------------------------- /opt-env-conf-test/test_resources/docs/big-config/docs.txt: -------------------------------------------------------------------------------- 1 | AnyDocsAnd 2 | [ AnyDocsOr 3 | [ AnyDocsSingle 4 | (Just 5 | SetDoc 6 | { setDocTryArgument = False 7 | , setDocTrySwitch = False 8 | , setDocTryOption = True 9 | , setDocDasheds = [ DashedLong ('c' :| "onfig-file") ] 10 | , setDocEnvVars = Just ("CONFIG_FILE" :| []) 11 | , setDocConfKeys = Nothing 12 | , setDocDefault = Nothing 13 | , setDocExamples = [] 14 | , setDocMetavar = Just "FILE_PATH" 15 | , setDocHelp = Just "Path to the configuration file" 16 | }) 17 | , AnyDocsSingle Nothing 18 | ] 19 | , AnyDocsSingle 20 | (Just 21 | SetDoc 22 | { setDocTryArgument = False 23 | , setDocTrySwitch = False 24 | , setDocTryOption = False 25 | , setDocDasheds = [] 26 | , setDocEnvVars = Nothing 27 | , setDocConfKeys = 28 | Just 29 | (( "big" :| [] 30 | , AnyOfSchema 31 | (NullSchema :| 32 | [ CommentSchema 33 | "BigConfig" 34 | (ObjectSchema 35 | (ObjectAllOfSchema 36 | (ObjectKeySchema 37 | "map" 38 | Required 39 | (MapSchema 40 | (MapSchema 41 | (IntegerSchema 42 | Bounds 43 | { boundsLower = Just (-9223372036854775808) 44 | , boundsUpper = Just 9223372036854775807 45 | }))) 46 | Nothing :| 47 | [ ObjectKeySchema 48 | "sub" (Optional Nothing) StringSchema Nothing 49 | ]))) 50 | ]) 51 | ) :| 52 | []) 53 | , setDocDefault = Nothing 54 | , setDocExamples = [] 55 | , setDocMetavar = Nothing 56 | , setDocHelp = Just "big configuration object" 57 | }) 58 | ] --------------------------------------------------------------------------------