All Projects → pcj → google-options

pcj / google-options

Licence: Apache-2.0 license
Command line argument parsing library from the folks at Google (java).

Programming Languages

java
68154 projects - #9 most used programming language
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to google-options

Argumentum
C++ command line parsing library
Stars: ✭ 92 (+50.82%)
Mutual labels:  argument-parser
Deno Cliffy
Command line framework for deno 🦕 Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...
Stars: ✭ 149 (+144.26%)
Mutual labels:  argument-parser
argparse
Parser for command-line arguments
Stars: ✭ 24 (-60.66%)
Mutual labels:  argument-parser
Clikt
Multiplatform command line interface parsing for Kotlin
Stars: ✭ 1,658 (+2618.03%)
Mutual labels:  argument-parser
Yaap
Yet Another (Swift) Argument Parser
Stars: ✭ 124 (+103.28%)
Mutual labels:  argument-parser
Flags
⛳ Simple, extensible, header-only C++17 argument parser released into the public domain.
Stars: ✭ 187 (+206.56%)
Mutual labels:  argument-parser
Argh
Argh! A minimalist argument handler.
Stars: ✭ 752 (+1132.79%)
Mutual labels:  argument-parser
args
Simple and type-safe commandline argument parser for C++14
Stars: ✭ 63 (+3.28%)
Mutual labels:  argument-parser
Argparse.jl
Package for parsing command-line arguments to Julia programs.
Stars: ✭ 131 (+114.75%)
Mutual labels:  argument-parser
Argumentparser
Faster, easier, more declarative parsing of command line arguments in Objective-C/Foundation.
Stars: ✭ 251 (+311.48%)
Mutual labels:  argument-parser
Sywac
🚫 🐭 Asynchronous, single package CLI framework for Node
Stars: ✭ 109 (+78.69%)
Mutual labels:  argument-parser
Programoptions.hxx
Single-header program options parsing library for C++11
Stars: ✭ 112 (+83.61%)
Mutual labels:  argument-parser
Lyra
A simple to use, composable, command line parser for C++ 11 and beyond
Stars: ✭ 238 (+290.16%)
Mutual labels:  argument-parser
Typescript To Cli
Transform your typescript module into a CLI
Stars: ✭ 101 (+65.57%)
Mutual labels:  argument-parser
jsonargparse
Implement minimal boilerplate CLIs derived from type hints and parse from command line, config files and environment variables
Stars: ✭ 168 (+175.41%)
Mutual labels:  argument-parser
Argh
Rust derive-based argument parsing optimized for code size
Stars: ✭ 803 (+1216.39%)
Mutual labels:  argument-parser
Argagg
A simple C++11 command line argument parser
Stars: ✭ 180 (+195.08%)
Mutual labels:  argument-parser
argparser
Simple command-line parser for C/C++ programs
Stars: ✭ 50 (-18.03%)
Mutual labels:  argument-parser
sf
Simple Bash framework which provides argument parsing, usage output and text formatting variables
Stars: ✭ 16 (-73.77%)
Mutual labels:  argument-parser
Commanddotnet
A modern framework for building modern CLI apps
Stars: ✭ 251 (+311.48%)
Mutual labels:  argument-parser

google-options Build Status Maven Central JavaDoc

Google Options

This is the command-line arguments parser from the Bazel Project. The com.google.devtools.common.options package has been split out into a separate jar for general utility.

Installation

Bazel

maven_jar(
    name = "com_github_pcj_google_options",
    artifact = "com.github.pcj:google-options:jar:1.0.0",
    sha1 = "85d54fe6771e5ff0d54827b0a3315c3e12fdd0c7",
)

Gradle

dependencies {
  compile 'com.github.pcj:google-options:1.0.0'
}

Maven

<dependency>
  <groupId>com.github.pcj</groupId>
  <artifactId>google-options</artifactId>
  <version>1.0.0</version>
</dependency>

Usage

Create a class that extends OptionsBase and defines your @Option(s).

package example;

import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionsBase;

import java.util.List;

/**
 * Command-line options definition for example server.
 */
public class ServerOptions extends OptionsBase {

  @Option(
      name = "help",
      abbrev = 'h',
      help = "Prints usage info.",
      defaultValue = "true"
    )
  public boolean help;

  @Option(
      name = "host",
      abbrev = 'o',
      help = "The server host.",
      category = "startup",
      defaultValue = ""
  )
  public String host;

  @Option(
    name = "port",
    abbrev = 'p',
    help = "The server port.",
    category = "startup",
    defaultValue = "8080"
    )
    public int port;

  @Option(
    name = "dir",
    abbrev = 'd',
    help = "Name of directory to serve static files.",
    category = "startup",
    allowMultiple = true,
    defaultValue = ""
    )
    public List<String> dirs;

}

Parse the arguments and use them.

package example;

import com.google.devtools.common.options.OptionsParser;
import java.util.Collections;

public class Server {

  public static void main(String[] args) {
    OptionsParser parser = OptionsParser.newOptionsParser(ServerOptions.class);
    parser.parseAndExitUponError(args);
    ServerOptions options = parser.getOptions(ServerOptions.class);
    if (options.host.isEmpty() || options.port < 0 || options.dirs.isEmpty()) {
      printUsage(parser);
      return;
    }

    System.out.format("Starting server at %s:%d...\n", options.host, options.port);
    for (String dirname : options.dirs) {
      System.out.format("\\--> Serving static files at <%s>\n", dirname);
    }
  }

  private static void printUsage(OptionsParser parser) {
    System.out.println("Usage: java -jar server.jar OPTIONS");
    System.out.println(parser.describeOptions(Collections.<String, String>emptyMap(),
                                              OptionsParser.HelpVerbosity.LONG));
  }

}

Please consult the tests and source code for more detailed information.

JavaDoc API documentation is housed in the gh-pages branch.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].