{"id":24302903,"url":"https://github.com/digipolitan/command-line-args","last_synced_at":"2026-05-26T23:02:08.897Z","repository":{"id":98675226,"uuid":"94771232","full_name":"Digipolitan/command-line-args","owner":"Digipolitan","description":null,"archived":false,"fork":false,"pushed_at":"2017-11-13T20:31:59.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-17T00:20:16.947Z","etag":null,"topics":["command-line-arguments","command-line-parser","command-line-tool","swift"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Digipolitan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-19T11:49:23.000Z","updated_at":"2017-10-03T11:25:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"0b98db2c-7141-4b58-90cd-ee30bfbc8929","html_url":"https://github.com/Digipolitan/command-line-args","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Digipolitan%2Fcommand-line-args","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Digipolitan%2Fcommand-line-args/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Digipolitan%2Fcommand-line-args/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Digipolitan%2Fcommand-line-args/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Digipolitan","download_url":"https://codeload.github.com/Digipolitan/command-line-args/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242225916,"owners_count":20092673,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-line-arguments","command-line-parser","command-line-tool","swift"],"created_at":"2025-01-17T00:20:01.780Z","updated_at":"2025-12-06T23:02:16.306Z","avatar_url":"https://github.com/Digipolitan.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"CommandLineArgs\n=================================\n\n[![Swift Version](https://img.shields.io/badge/swift-4.0-orange.svg?style=flat)](https://developer.apple.com/swift/)\n[![Swift Package Manager](https://rawgit.com/jlyonsmith/artwork/master/SwiftPackageManager/swiftpackagemanager-compatible.svg)](https://swift.org/package-manager/)\n[![Twitter](https://img.shields.io/badge/twitter-@Digipolitan-blue.svg?style=flat)](http://twitter.com/Digipolitan)\n\nSwift library to parse and route command line options\n\n## Installation\n\n### SPM\n\nTo install CommandLineArgs with SwiftPackageManager, add the following lines to your `Package.swift`.\n\n```swift\nlet package = Package(\n    name: \"XXX\",\n    products: [\n        .library(\n            name: \"XXX\",\n            targets: [\"XXX\"]),\n    ],\n    dependencies: [\n        .package(url: \"https://github.com/Digipolitan/command-line-args.git\", from: \"1.0.0\")\n    ],\n    targets: [\n        .target(\n            name: \"XXX\",\n            dependencies: [\"CommandLineArgs\"])\n    ]\n)\n```\n\n## The Basics\n\n### Handle single command\n\n1] Create the command subclass\n\n```swift\npublic class MyAppCommand: Command {\n\n    public enum Keys {\n        public static let help: String = CommandLineArgs.Consts.keys.help\n        public static let numbers: String = \"numbers\"\n    }\n\n    public enum Options {\n        public static let help = OptionDefinition(name: Keys.help, type: .boolean, documentation: \"Show help banner of specified command\")\n        public static let numbers = OptionDefinition(name: Keys.numbers, type: .int, alias: \"n\", isMultiple: true)\n    }\n\n    public enum Consts {\n        public static let name: String = \"MyAppName\"\n    }\n\n    public lazy var definition: CommandDefinition = {\n        return CommandDefinition(name: Consts.name, options: [\n          Options.help,\n          Options.numbers\n          ], documentation: \"My App command line tool\")\n    }()\n\n    public func run(_ arguments: [String : Any]) throws {\n      if let numbers = arguments[Keys.numbers] as? [Int] {\n        print(numbers) // display numbers value\n      }\n    }\n}\n```\n\n2] Register \u0026 handle the command inside the CommandLineArgs in your main.swift\n\n```swift\nvar arguments = CommandLine.arguments\narguments[0] = MyAppCommand.Consts.name // Force the app name inside the first app arguments\n\nlet cla = CommandLineArgs()\ncla.root(command: MyAppCommand())\ncla.handle(arguments)\n```\n\n3] Execute your command line app as follow:\n\n- Display the help banner\n\n```sh\n$ MyAppName --help\n```\n\n**Output**\n```sh\nUsage :\n\n\t$ MyAppName [OPTIONS]\n\nMy App command line tool\n\nOptions :\n\n--help Boolean\n  Show help banner of specified command\n\n--numbers|-n Int[]\n```\n\n---\n\n- Execute using full arg name\n\n```sh\n$ MyAppName --numbers 1 2\n```\n\n**Output**\n```sh\n[1, 2]\n```\n\n---\n\n- Execute using alias\n\n```sh\n$ MyAppName -n 1 2 3 4\n```\n\n**Output**\n```sh\n[1, 2, 3, 4]\n```\n\n### Handle node command\n\n```swift\nlet cla = CommandLineArgs()\nlet app = cla.root(command: MyAppCommand())\napp.add(child: StartCommand()) // CommandDefinition name: \"start\"\napp.add(child: StopCommand()) // CommandDefinition name: \"stop\"\n```\n\n* `$ MyAppName --numbers 4 3` will trigger MyAppCommand\n* `$ MyAppName start XXX` will trigger StartCommand\n* `$ MyAppName stop XXX` will trigger StopCommand\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for more details!\n\nThis project adheres to the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md).\nBy participating, you are expected to uphold this code. Please report\nunacceptable behavior to [contact@digipolitan.com](mailto:contact@digipolitan.com).\n\n## License\n\nCommandLineArgs is licensed under the [BSD 3-Clause license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigipolitan%2Fcommand-line-args","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigipolitan%2Fcommand-line-args","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigipolitan%2Fcommand-line-args/lists"}