Swiftpack.co - bscothern/ConfigArgumentParser as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
An extension of Swift Argument Parser that adds support for config files.
.package(url: "https://github.com/bscothern/ConfigArgumentParser.git", from: "v0.2.0")


An extension of the swift argument parser to support config files.

GitHub license SwiftPM Swift Versions

Supported Features

  • Custom Config File Formats.
  • Customizable Flags/Help Messages.
  • Dry runs to show what commands will be run with the config file being used.
  • The ability to auto find and use config files at paths of your choosing.


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 ConfigExecutable<RootCommand>. The RootCommand is your executable command type that you would normally call RootCommand.main() on. With your 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:

    .interpretConfig(with: YourConfigFileInterpreter.self)

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:

    .interpretConfig(with: YourConfigFileInterpreter.self) // If desired, this is not required
    .customizeFlags(with: YourConfigFlagSettings.self)

There are example executables that are also used for testing in the Executables/.

Adding ConfigArgumentParser as a dependency

Add the following line to your package dependencies in your Package.swift file:

.package(url: "https://github.com/bscothern/ConfigArgumentParser", .upToNextMinor(from: "0.2.0")),

Then in the targets section add this line as a dependency in your Package.swift file:

.product(name: "ConfigArgumentParser", package: "ConfigArgumentParser"),

Breaking changes will happen on minor versions until version 1.0.0 is reached.

Known Issues

  • Because of how ConfigArgumentParser has to function to allow normal usage of your commands and the config options you can't have any auto complete help with supplying the arguments it supports.
  • No way to automatically grab and run config file when running executables.
  • You cannot override config settings from the command line.
  • You cannot add aditional settings from the command line when a config file is used.


Stars: 2
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

2 weeks ago

Upgraded to use swift-argument-parser v1.0.1+

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics