{"id":28726883,"url":"https://github.com/docopt/docopt.clj","last_synced_at":"2025-06-15T13:09:35.348Z","repository":{"id":7755603,"uuid":"9123309","full_name":"docopt/docopt.clj","owner":"docopt","description":"Clojure implementation of the docopt language.","archived":false,"fork":false,"pushed_at":"2013-04-11T12:20:00.000Z","size":226,"stargazers_count":65,"open_issues_count":4,"forks_count":5,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-05-09T19:19:24.182Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/docopt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-30T23:16:16.000Z","updated_at":"2023-08-23T11:43:07.000Z","dependencies_parsed_at":"2022-09-18T11:11:49.082Z","dependency_job_id":null,"html_url":"https://github.com/docopt/docopt.clj","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/docopt/docopt.clj","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.clj","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.clj/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.clj/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.clj/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/docopt","download_url":"https://codeload.github.com/docopt/docopt.clj/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.clj/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259981589,"owners_count":22941150,"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":"2025-06-15T13:09:28.100Z","updated_at":"2025-06-15T13:09:35.339Z","avatar_url":"https://github.com/docopt.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# docopt.clj\n\nClojure implementation of the [docopt](http://docopt.org/) language, version 0.6, \nunder a [MIT license](http://github.com/docopt/docopt.clj/blob/master/LICENSE).\n\n## Usage\n\nAdd `[docopt \"0.6.1\"]` to your dependencies in `project.clj`, and import `docopt.core` in your clojure code. \nThis namespace contains the public API:\n\n- A macro `docopt` wich takes up to two arguments, a docstring and an `args` sequence.  \nThe docstring is optional; if omitted, the macro will try to use the docstring of `#'-main`. The docstring is parsed \nat compile-time, and the `args` are matched at run-time. The `args` should be a sequence of command-line arguments like\n those passed to `-main` or `public static void main(String[] args);`.\n\n- A function `-docopt` which is the run-time equivalent of the `docopt` macro provided for Java interoperability.\n\n- A function `parse` which takes a docstring as argument and returns all the information extracted from it.\nThis function is called by both `docopt` and `-docopt`.\n\n## Example - Clojure\n\n``` clojure\n(ns example.core\n  (:use [docopt.core :only [docopt]]) ; import the docopt macro from docopt.core\n  (:gen-class)\n  \n(defn #^{:doc \"Naval Fate.\n\nUsage:\n  naval_fate ship new \u003cname\u003e...\n  naval_fate ship \u003cname\u003e move \u003cx\u003e \u003cy\u003e [--speed=\u003ckn\u003e]\n  naval_fate ship shoot \u003cx\u003e \u003cy\u003e\n  naval_fate mine (set|remove) \u003cx\u003e \u003cy\u003e [--moored|--drifting]\n  naval_fate -h | --help\n  naval_fate --version\n\nOptions:\n  -h --help     Show this screen.\n  --version     Show version.\n  --speed=\u003ckn\u003e  Speed in knots [default: 10].\n  --moored      Moored (anchored) mine.\n  --drifting    Drifting mine.\"\n:version \"Naval Fate, version 1.2.3.\" }\n  -main [\u0026 args]\n  (let [arg-map (docopt args)] ; with only one argument, docopt parses -main's docstring.\n    (cond \n      (or (nil? arg-map)\n          (arg-map \"--help\")) (println (:doc     (meta #'-main)))\n      (arg-map \"--version\")   (println (:version (meta #'-main)))\n      (arg-map \"mine\")        (println (if (arg-map \"set\") \"Set\" \"Remove\") \n                                       (cond \n                                         (arg-map \"--moored\")   \"moored\" \n                                         (arg-map \"--drifting\") \"drifting\")\n                                       \"mine at (\" (arg-map \"\u003cx\u003e\") \", \" (arg-map \"\u003cy\u003e\") \").\")\n      (arg-map \"new\")         (println \"Create new\" \n                                       (let [[name \u0026 more-names :as names] (arg-map \"\u003cname\u003e\")]\n                                         (if (seq more-names) \n                                           (str \"ships \" (clojure.string/join \", \" names))\n                                           (str \"ship \" name)))\n                                       \".\")\n      (arg-map \"shoot\")       (println \"Shoot at (\" (arg-map \"\u003cx\u003e\") \",\" (arg-map \"\u003cy\u003e\") \").\")\n      (arg-map \"move\")        (println \"Move\" (first (arg-map \"\u003cname\u003e\")) \n                                       \"to (\" (arg-map \"\u003cx\u003e\") \",\" (arg-map \"\u003cy\u003e\")\n                                       (if-let [speed (arg-map \"--speed\")]\n                                         (str \" ) at \" speed \" knots.\")\n                                         \" ).\"))\n      true                    (throw (Exception. \"This ought to never happen.\\n\")))))\n```\n\n## Example - Java interoperability\n\nAssuming you're using Maven, update your `pom.xml` by adding a child to its `repositories` node\n``` xml\n\u003crepository\u003e\n  \u003cid\u003eclojars.org\u003c/id\u003e\n  \u003curl\u003ehttp://clojars.org/repo\u003c/url\u003e\n\u003c/repository\u003e\n```\nand to its `dependencies` node.\n``` xml\n\u003cdependency\u003e\n  \u003cgroupId\u003edocopt\u003c/groupId\u003e\n  \u003cartifactId\u003edocopt\u003c/artifactId\u003e\n  \u003cversion\u003e0.6.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nImport `org.docopt.clj` in your code and call the static method `clj.docopt(String, String[]);` which returns a\n`AbstractMap\u003cString, Object\u003e`.\n\n``` java\nimport java.util.AbstractMap;\nimport org.docopt.clj;\n\npublic class Main {\n  \n  public static void main(String[] args) {\n  \n    String docstring = \"Usage: prog [options]\\n\\nOptions:\\n-h, --help  Print help.\";\n    AbstractMap\u003cString, Object\u003e result = clj.docopt(docstring, args);\n    \n    if (result.get(\"--help\").toString() == \"true\") {\n      System.out.println(docstring);\n    }\n    else {\n      System.out.println(\"You don't need help.\");\n    }\n  }\n}\n```\n\n## Tests\n\nRun `lein test` to validate all tests.\nThe tests are automatically downloaded from the language-agnostic\n`testcases.docopt` file in the reference implementation, master branch commit \n[511d1c57b5](https://github.com/docopt/docopt/tree/511d1c57b59cd2ed663a9f9e181b5160ce97e728).\nPlease feel free to (re)open an issue in case this implementation falls behind.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocopt%2Fdocopt.clj","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdocopt%2Fdocopt.clj","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocopt%2Fdocopt.clj/lists"}