🚀The framework to write type-safe and structured command line program easily in Swift.

What's New




  • Added built-in command list to list the subcommands and options of given command.
  • Added built-in command complete to generate and execute the completion scripts for bash and zsh both.


  • Fixed and make the help options with extra available options an std error

logo Commander

testcodecovlicenselangMaintainabilityTest Coverage

Commander is a Swift framework for decoding command-line arguments by integrating with Swift Standard Library Protocols e.g. Encodable & Decodable. With Commander, you just need to focus on writing options model of commands, the rest works will be handled by Commander.

Test Coverage Graph

coverage graph


With Commander, a command and its associated options could be defined as follows:

import Commander

public struct SampleCommand: CommandRepresentable {
  public struct Options: OptionsRepresentable {
    public typealias ArgumentsResolver = AnyArgumentsResolver<String>
    public enum CodingKeys: String, CodingKeysRepresentable {
      case verbose = "verbose"
      case stringValue = "string-value"

    public static let keys: [Options.CodingKeys : Character] = [
      .verbose: "v",
      .stringValue: "s"

    public static let descriptions: [Options.CodingKeys : OptionDescription] = [
      .verbose: .usage("Prints the logs of the command"),
      .stringValue: .usage("Pass a value of String to the command")

    public var verbose: Bool = false
    public var stringValue: String = ""

  public static let symbol: String = "sample"
  public static let usage: String = "Show sample usage of commander"

  public static func main(_ options: Options) throws {
    print("arguments: \(options.arguments)")

Then, configuring the available commands would like this:

import Commander

Commander.commands = [
Commander.usage = "The sample usage command of 'Commander'"
Commander().dispatch() // Call this to dispatch and run the command

After which, arguments can be resolved by declaration of ArgumentsResolver:

public typealias ArgumentsResolver = AnyArgumentsResolver<T> // T must be Decodable

And you can fetch the arguments by:

public static func main(_ options: Options) throws {
  print("arguments: \(options.arguments)") // 'arguments' is being declared in OptionsRepresentable 

It's easy and fun!!!


Commander is released under the MIT license.


  • Swift Tools 4.0.0
View More Packages from this Author


  • None
Last updated: Mon Apr 22 2024 03:14:25 GMT-0900 (Hawaii-Aleutian Daylight Time)