{"id":17316995,"url":"https://github.com/pcj/google-options","last_synced_at":"2025-06-21T12:38:22.033Z","repository":{"id":57722030,"uuid":"75777106","full_name":"pcj/google-options","owner":"pcj","description":"Command line argument parsing library from the folks at Google (java).","archived":false,"fork":false,"pushed_at":"2016-12-07T07:50:58.000Z","size":120,"stargazers_count":71,"open_issues_count":0,"forks_count":7,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-28T02:53:35.484Z","etag":null,"topics":["argument-parser","java"],"latest_commit_sha":null,"homepage":"https://pcj.github.io/google-options/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pcj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-06T22:26:36.000Z","updated_at":"2024-12-31T10:05:36.000Z","dependencies_parsed_at":"2022-09-26T21:50:29.768Z","dependency_job_id":null,"html_url":"https://github.com/pcj/google-options","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcj%2Fgoogle-options","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcj%2Fgoogle-options/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcj%2Fgoogle-options/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcj%2Fgoogle-options/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pcj","download_url":"https://codeload.github.com/pcj/google-options/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248888759,"owners_count":21178101,"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":["argument-parser","java"],"created_at":"2024-10-15T13:15:08.929Z","updated_at":"2025-04-14T13:32:15.311Z","avatar_url":"https://github.com/pcj.png","language":"Java","readme":"# google-options [![Build Status](https://travis-ci.org/pcj/google-options.svg?branch=master)](https://travis-ci.org/pcj/google-options) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.pcj/google-options/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.pcj/google-options) [![JavaDoc](https://img.shields.io/badge/apidoc-1.0.0-orange.svg)](https://pcj.github.io/google-options/)\n\n\u003ctable\u003e\u003ctr\u003e\n\u003ctd\u003e\u003cimg src=\"https://avatars0.githubusercontent.com/u/1342004?v=3\u0026s=200\" width=\"120\"/\u003e\u003c/td\u003e\n\u003ctd\u003e\u003cimg src=\"http://icons.iconarchive.com/icons/cornmanthe3rd/plex/128/System-settings-icon.png\" width=\"120\"/\u003e\u003c/td\u003e\n\u003c/tr\u003e\u003ctr\u003e\n\u003ctd\u003eGoogle\u003c/td\u003e\n\u003ctd\u003eOptions\u003c/td\u003e\n\u003c/tr\u003e\u003c/table\u003e\n\nThis is the command-line arguments parser from the\n[Bazel Project](http://bazel.build).  The\n`com.google.devtools.common.options` package has been split out into a\nseparate jar for general utility.\n\n# Installation\n\n### Bazel\n\n```python\nmaven_jar(\n    name = \"com_github_pcj_google_options\",\n    artifact = \"com.github.pcj:google-options:jar:1.0.0\",\n    sha1 = \"85d54fe6771e5ff0d54827b0a3315c3e12fdd0c7\",\n)\n```\n\n### Gradle\n\n```groovy\ndependencies {\n  compile 'com.github.pcj:google-options:1.0.0'\n}\n```\n\n### Maven\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.pcj\u003c/groupId\u003e\n  \u003cartifactId\u003egoogle-options\u003c/artifactId\u003e\n  \u003cversion\u003e1.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n# Usage\n\nCreate a class that extends `OptionsBase` and defines your `@Option`(s).\n\n```java\npackage example;\n\nimport com.google.devtools.common.options.Option;\nimport com.google.devtools.common.options.OptionsBase;\n\nimport java.util.List;\n\n/**\n * Command-line options definition for example server.\n */\npublic class ServerOptions extends OptionsBase {\n\n  @Option(\n      name = \"help\",\n      abbrev = 'h',\n      help = \"Prints usage info.\",\n      defaultValue = \"true\"\n    )\n  public boolean help;\n\n  @Option(\n      name = \"host\",\n      abbrev = 'o',\n      help = \"The server host.\",\n      category = \"startup\",\n      defaultValue = \"\"\n  )\n  public String host;\n\n  @Option(\n    name = \"port\",\n    abbrev = 'p',\n    help = \"The server port.\",\n    category = \"startup\",\n    defaultValue = \"8080\"\n    )\n    public int port;\n\n  @Option(\n    name = \"dir\",\n    abbrev = 'd',\n    help = \"Name of directory to serve static files.\",\n    category = \"startup\",\n    allowMultiple = true,\n    defaultValue = \"\"\n    )\n    public List\u003cString\u003e dirs;\n\n}\n```\n\nParse the arguments and use them.\n\n```java\npackage example;\n\nimport com.google.devtools.common.options.OptionsParser;\nimport java.util.Collections;\n\npublic class Server {\n\n  public static void main(String[] args) {\n    OptionsParser parser = OptionsParser.newOptionsParser(ServerOptions.class);\n    parser.parseAndExitUponError(args);\n    ServerOptions options = parser.getOptions(ServerOptions.class);\n    if (options.host.isEmpty() || options.port \u003c 0 || options.dirs.isEmpty()) {\n      printUsage(parser);\n      return;\n    }\n\n    System.out.format(\"Starting server at %s:%d...\\n\", options.host, options.port);\n    for (String dirname : options.dirs) {\n      System.out.format(\"\\\\--\u003e Serving static files at \u003c%s\u003e\\n\", dirname);\n    }\n  }\n\n  private static void printUsage(OptionsParser parser) {\n    System.out.println(\"Usage: java -jar server.jar OPTIONS\");\n    System.out.println(parser.describeOptions(Collections.\u003cString, String\u003eemptyMap(),\n                                              OptionsParser.HelpVerbosity.LONG));\n  }\n\n}\n```\n\nPlease consult the\n[tests](src/test/java/com/google/devtools/common/options/) and\n[source code](src/main/java/com/google/devtools/common/options/) for\nmore detailed information.\n\n[JavaDoc API documentation](https://pcj.github.io/google-options/) is housed in the gh-pages branch.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcj%2Fgoogle-options","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpcj%2Fgoogle-options","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcj%2Fgoogle-options/lists"}