An extension of the swift argument parser to support config files.
You should be familiar with at least the basics of the swift argument parser which this extends. Build up your command line executable as you normally would when working with the swift argument parser with one exception which is how you start the executable. Once you have your exeutable ready that is where this library comes in to enable config files.
The type that enables the use of config files is
RootCommand is your executable command type that you would normally call
ConfigExecutable you can then build up your command and customize how the config file is interpreted or what flags are used to supply a config file as needed.
The simple case
In the most simple case this is all you need:
Customizing the config file
When you need to customize how the config file is interpreted and converted to the arguments your command expects you create a
ConfigFileInterpreter type and then use
interpretConfig(with:) like this:
ConfigExecutable<YourCommand> .interpretConfig(with: YourConfigFileInterpreter.self) .main()
Customizing the flags
When the default flags of
--config [config_file_path] and
--config-dry-run aren't what you want you can create a
ConfigFlagSettings type and use
customizeFlags(with:) to change them as needed like this:
ConfigExecutable<YourCommand> .interpretConfig(with: YourConfigFileInterpreter.self) // If desired, this is not required .customizeFlags(with: YourConfigFlagSettings.self) .main()
There are example executables that are also used for testing in the
ConfigArgumentParser as a dependency
Add the following line to your package dependencies in your
.package(url: "https://github.com/bscothern/ConfigArgumentParser", .upToNextMinor(from: "0.1.0")),
Then in the targets section add this line as a dependency in your
.product(name: "ConfigArgumentParser", package: "ConfigArgumentParser"),
Because Swift Argument Parser is not stable yet this project is using
.upToNextMinor(from: "0.3.1") for that dependency in order to stay compatible.
Breaking changes will happen on minor versions until version
1.0.0 is reached.
- Because of how
ConfigArgumentParserhas to function to allow normal usage of your commands and the config options you can't have any help messages or auto complete help with supplying the arguments it supports. This means just the
RootCommandand its subcommands help and autocomplete is available making
--config-dry-runmagic hidden commands.