{"id":13812634,"url":"https://github.com/SDGGiesbrecht/SDGCommandLine","last_synced_at":"2025-05-14T22:30:54.016Z","repository":{"id":23482987,"uuid":"99160390","full_name":"SDGGiesbrecht/SDGCommandLine","owner":"SDGGiesbrecht","description":"Tools for Implementing a Command Line Interface","archived":false,"fork":false,"pushed_at":"2024-09-08T19:15:53.000Z","size":1420,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-15T08:18:59.756Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://sdggiesbrecht.github.io/SDGCommandLine/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SDGGiesbrecht.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-08-02T20:59:19.000Z","updated_at":"2024-09-08T19:02:54.000Z","dependencies_parsed_at":"2024-01-18T03:46:40.652Z","dependency_job_id":null,"html_url":"https://github.com/SDGGiesbrecht/SDGCommandLine","commit_stats":{"total_commits":272,"total_committers":1,"mean_commits":272.0,"dds":0.0,"last_synced_commit":"502d7bcbbe8b9af1a98c142d27ad635d5d44dda1"},"previous_names":[],"tags_count":65,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDGGiesbrecht%2FSDGCommandLine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDGGiesbrecht%2FSDGCommandLine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDGGiesbrecht%2FSDGCommandLine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SDGGiesbrecht%2FSDGCommandLine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SDGGiesbrecht","download_url":"https://codeload.github.com/SDGGiesbrecht/SDGCommandLine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254239455,"owners_count":22037713,"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":[],"created_at":"2024-08-04T04:00:53.941Z","updated_at":"2025-05-14T22:30:50.186Z","avatar_url":"https://github.com/SDGGiesbrecht.png","language":"Swift","funding_links":["https://paypal.me/JeremyGiesbrecht"],"categories":["The Index"],"sub_categories":["Command Line UI tools"],"readme":"\u003c!--\n README.md\n\n This source file is part of the SDGCommandLine open source project.\n https://sdggiesbrecht.github.io/SDGCommandLine\n\n Copyright ©2017–2024 Jeremy David Giesbrecht and the SDGCommandLine project contributors.\n\n Soli Deo gloria.\n\n Licensed under the Apache Licence, Version 2.0.\n See http://www.apache.org/licenses/LICENSE-2.0 for licence information.\n --\u003e\n\nmacOS • Windows • Web • Ubuntu • tvOS • iOS • Android • Amazon Linux • watchOS\n\n[Documentation](https://sdggiesbrecht.github.io/SDGCommandLine/%F0%9F%87%A8%F0%9F%87%A6EN)\n\n# SDGCommandLine\n\nSDGCommandLine provides tools for implementing a command line interface.\n\n\u003e [יְהַלְלוּ אֶת־שֵׁם יהוה כִּי הוּא צִוָּה וְנִבְרָאוּ׃](https://www.biblegateway.com/passage/?search=Psalm+148\u0026version=WLC;NIV)\n\u003e\n\u003e [May they praise the name of the Lord, for He commanded and they came into being!](https://www.biblegateway.com/passage/?search=Psalm+148\u0026version=WLC;NIV)\n\u003e\n\u003e ―a psalmist\n\n### Features\n\n- Automatic parsing of options and subcommands\n- Automatic `help` subcommand\n- Testable output\n- Colour formatting tools\n    - Automatic `•no‐colour` option\n- Interface localization\n    - Automatic `set‐language` subcommand to set language preferences.\n    - Automatic `•language` option to run in a specific language only once.\n- Versioning tools\n    - Automatic `version` subcommand\n    - Automatic `•use‐version` option to attempt to download and temporarily use a specific version instead of the one which is installed (only for public Swift packages).\n\n### Example Usage\n\nThis example creates a tool with the following interface:\n\n```shell\n$ parrot speak\nSquawk!\n\n$ parrot speak •phrase \"Hello, world!\"\nHello, world!\n```\n\n`main.swift` must consist of the following:\n\n```swift\nParrot.main()\n```\n\nThe rest can be anywhere in the project (but putting it in a separate, testable library module is recommended):\n\n```swift\nimport SDGCommandLine\n\nstruct Parrot: Tool {\n  static let applicationIdentifier: StrictString = \"tld.Developper.Parrot\"\n  static let version: Version? = Version(1, 0, 0)\n  static let packageURL: URL? = URL(string: \"https://website.tld/Parrot\")\n  static let rootCommand: Command = parrot\n}\n\nlet parrot = Command(\n  name: UserFacing\u003cStrictString, MyLocalizations\u003e({ _ in \"parrot\" }),\n  description: UserFacing\u003cStrictString, MyLocalizations\u003e({ _ in \"behaves like a parrot.\" }),\n  subcommands: [speak]\n)\n\nlet speak = Command(\n  name: UserFacing\u003cStrictString, MyLocalizations\u003e({ _ in \"speak\" }),\n  description: UserFacing\u003cStrictString, MyLocalizations\u003e({ _ in \"speaks.\" }),\n  directArguments: [],\n  options: [phrase],\n  execution: { (_, options: Options, output: Command.Output) throws -\u003e Void in\n\n    if let specific = options.value(for: phrase) {\n      output.print(specific)\n    } else {\n      output.print(\"Squawk!\")\n    }\n  }\n)\n\nlet phrase = Option\u003cStrictString\u003e(\n  name: UserFacing\u003cStrictString, MyLocalizations\u003e({ _ in \"phrase\" }),\n  description: UserFacing\u003cStrictString, MyLocalizations\u003e({ _ in \"A custom phrase to speak.\" }),\n  type: ArgumentType.string\n)\n\nenum MyLocalizations: String, InputLocalization {\n  case english = \"en\"\n  static let cases: [MyLocalizations] = [.english]\n  static let fallbackLocalization: MyLocalizations = .english\n}\n```\n\nTests are easy to set up:\n\n```swift\nfunc testParrot() {\n  switch parrot.execute(with: [\"speak\", \"•phrase\", \"Hello, world!\"]) {\n  case .success(let output):\n    XCTAssertEqual(output, \"Hello, world!\")\n  case .failure:\n    XCTFail(\"The parrot is not co‐operating.\")\n  }\n}\n```\n\nSome platforms lack certain features. The compilation conditions which appear throughout the documentation are defined as follows:\n\n```swift\n.define(\"PLATFORM_LACKS_FOUNDATION_PROCESS\", .when(platforms: [.wasi, .tvOS, .iOS, .watchOS])),\n.define(\"PLATFORM_LACKS_FOUNDATION_PROCESS_INFO\", .when(platforms: [.wasi])),\n```\n\n## Importing\n\nSDGCommandLine provides libraries for use with the Swift Package Manager.\n\nSimply add SDGCommandLine as a dependency in `Package.swift` and specify which of the libraries to use:\n\n```swift\nlet package = Package(\n  name: \"MyPackage\",\n  dependencies: [\n    .package(\n      url: \"https://github.com/SDGGiesbrecht/SDGCommandLine\",\n      from: Version(3, 0, 6)\n    ),\n  ],\n  targets: [\n    .target(\n      name: \"MyTarget\",\n      dependencies: [\n        .product(name: \"SDGCommandLine\", package: \"SDGCommandLine\"),\n        .product(name: \"SDGCommandLineTestUtilities\", package: \"SDGCommandLine\"),\n        .product(name: \"SDGExportedCommandLineInterface\", package: \"SDGCommandLine\"),\n      ]\n    )\n  ]\n)\n```\n\nThe modules can then be imported in source files:\n\n```swift\nimport SDGCommandLine\nimport SDGCommandLineTestUtilities\nimport SDGExportedCommandLineInterface\n```\n\n## About\n\nThe SDGCommandLine project is maintained by Jeremy David Giesbrecht.\n\nIf SDGCommandLine saves you money, consider giving some of it as a [donation](https://paypal.me/JeremyGiesbrecht).\n\nIf SDGCommandLine saves you time, consider devoting some of it to [contributing](https://github.com/SDGGiesbrecht/SDGCommandLine) back to the project.\n\n\u003e [Ἄξιος γὰρ ὁ ἐργάτης τοῦ μισθοῦ αὐτοῦ ἐστι.](https://www.biblegateway.com/passage/?search=Luke+10\u0026version=SBLGNT;NIV)\n\u003e\n\u003e [For the worker is worthy of his wages.](https://www.biblegateway.com/passage/?search=Luke+10\u0026version=SBLGNT;NIV)\n\u003e\n\u003e ―‎ישוע/Yeshuʼa\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSDGGiesbrecht%2FSDGCommandLine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FSDGGiesbrecht%2FSDGCommandLine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FSDGGiesbrecht%2FSDGCommandLine/lists"}