{"id":19968206,"url":"https://github.com/sormuras/command-line-interface","last_synced_at":"2025-05-04T01:30:23.331Z","repository":{"id":63847890,"uuid":"569670045","full_name":"sormuras/command-line-interface","owner":"sormuras","description":"Arguments Splitter for Java","archived":false,"fork":false,"pushed_at":"2023-11-13T10:32:35.000Z","size":344,"stargazers_count":6,"open_issues_count":4,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-07T23:51:13.466Z","etag":null,"topics":["arguments-parser","command-line","java"],"latest_commit_sha":null,"homepage":"","language":"Java","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/sormuras.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,"governance":null}},"created_at":"2022-11-23T11:00:14.000Z","updated_at":"2024-11-16T04:07:49.000Z","dependencies_parsed_at":"2023-11-13T11:25:32.930Z","dependency_job_id":"ddf99486-a336-4852-b06c-15a734e91092","html_url":"https://github.com/sormuras/command-line-interface","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sormuras%2Fcommand-line-interface","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sormuras%2Fcommand-line-interface/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sormuras%2Fcommand-line-interface/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sormuras%2Fcommand-line-interface/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sormuras","download_url":"https://codeload.github.com/sormuras/command-line-interface/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252276955,"owners_count":21722447,"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":["arguments-parser","command-line","java"],"created_at":"2024-11-13T02:44:52.203Z","updated_at":"2025-05-04T01:30:22.971Z","avatar_url":"https://github.com/sormuras.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Arguments Splitter\n\nAn Arguments [Splitter](main/main/Splitter.java) splits structured string arrays (`String[]`) into different values\nfollowing a [Schema](main/main/Schema.java). A schema is defined by a list of [Option](main/main/Option.java)s\nspecifying how to transform the strings into argument values.\n\nThere are two pre-defined schemas, a record based schema that uses convention oven configuration and\nan options based schema that offers a programmatic API.\n\n## Record based schema\n\nDefining the Unix's `wc` as an example:\n```java\nrecord WordCountOptions(\n    @Name({\"-c\", \"--bytes\"})           boolean bytes,\n    @Name({\"-m\", \"--chars\"})           boolean chars,\n    @Name({\"-l\", \"--lines\"})           boolean lines,\n    @Name(\"--files0-from\")             Optional\u003cFile\u003e files0From,\n    @Name({\"-w\", \"--words\"})           boolean words,\n    /* unnamed */                      File... files\n) {}\n\nvar splitter = Splitter.of(MethodHandles.lookup(), WordCountOptions.class);\nWordCountOptions options = splitter.split(args);\n// use options instance ...\n```\n\nOption structures are described using Java types.\n\n- Optional flag options (`--verbose`, `--foo=true` or `bar=false`) are described by `boolean` and `Boolean` types\n- Optional single key-value options (`--input foo.txt` or `input=foo.txt`) are described by the `Optional\u003cString\u003e` type\n- Optional repeatable key-value options (`-i foo.txt -i bar.txt` or `inputs=foo.txt,bar.txt`) are described by the `List\u003cString\u003e` type\n- Positional required options (`output.txt`) are described by the `String` type\n- Variadic options (`a.txt b.txt ...`) are described by the `String...` type\n \nNested option structures are single key-value option or repeatable key-value options\ndescribed by custom `record` types.\n\nBy convention, a `_` character in record component names is mapped to `-` character on the command-line.\n\nIn addition to the above conventions record components can be annotated with:\n\n- `@Name` in order to specify names that aren't legal Java names or to bind multiple names to one record component\n- `@Help` in order to provide a help description\n\nMapping to non-`String` or boolean types is done through a [converter resolver](main/main/ConverterResolver.java).\n\n## Options based schema\n\nDefining the Unix's `wc` using the type-safe programmatic API:\n```java\nvar bytes = Option.flag(\"-c\", \"--bytes\");\nvar lines = Option.flag(\"-l\", \"--lines\");\nvar files0From = Option.single(\"--files0-from\").convert(Path::of);\nvar words = Option.flag(\"-w\", \"--words\");\nvar files = Options.varargs(\"files\").convert(Path::of);\n\nvar splitter = Splitter.of(bytes, lines, files0From, words, files);\nArgumentMap argumentMap = splitter.split(args);\n// use argumentMap instance ...\n```\n\nAn option is an immutable class with one or more names, a value converter, and optionally a help text\nand a nested schema.\n\n## Build\n\nHow to build this project and run tests.\n\nSetup JDK 17 or later, and on the command-line run:\n\n```shell\n# run all tests\njava build/build.java\n\n# run single test class\njava build/build.java JarTests\n\n# run one or more methods of a single test class\njava build/build.java JarTests example2 example4\n```\n\nIn an IDE:\n\n- run as java application (`main` method)\n- use name(s) of methods as arguments to limit\n\n## Credits\n\nThis project is inspired by https://github.com/forax/argvester\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsormuras%2Fcommand-line-interface","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsormuras%2Fcommand-line-interface","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsormuras%2Fcommand-line-interface/lists"}