All Projects → jbock-java → jbock

jbock-java / jbock

Licence: MIT license
Reflectionless command line parser

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to jbock

jeta
brooth.github.io/jeta
Stars: ✭ 21 (-71.23%)
Mutual labels:  annotation-processing
Placeholderview
This library provides advance views for lists and stacks. Some of the views are build on top of RecyclerView and others are written in their own. Annotations are compiled by annotation processor to generate bind classes. DOCS -->
Stars: ✭ 2,104 (+2782.19%)
Mutual labels:  annotation-processing
copydynamic
Prototype of generating `copyDynamic` extension functions for kotlin data classes
Stars: ✭ 57 (-21.92%)
Mutual labels:  annotation-processing
generate-kotlin-multiple-rounds
Android sample project demonstrating how to generate Kotlin code through annotation processing, and then feeding it into a second round of annotation processing.
Stars: ✭ 25 (-65.75%)
Mutual labels:  annotation-processing
dagger2-ktx
Kotlin extension bridge library for Dagger2 (proof-of-concept)
Stars: ✭ 41 (-43.84%)
Mutual labels:  annotation-processing
Kotlin-Annotation-Processor
Annotation Processor Sample in Kotlin
Stars: ✭ 19 (-73.97%)
Mutual labels:  annotation-processing
AnnotationProcessorStarter
Project to set up basics of a Java annotation processor
Stars: ✭ 19 (-73.97%)
Mutual labels:  annotation-processing
config-cpp
C++ Configuration management library inspired by the Viper package for golang.
Stars: ✭ 21 (-71.23%)
Mutual labels:  command-line-parser
simple-annotation-processor
Simple annotation processor example. Inspired by the idea of "How ButterKnife works?"
Stars: ✭ 54 (-26.03%)
Mutual labels:  annotation-processing
symbok-bundle
Symfony annotations bundle
Stars: ✭ 50 (-31.51%)
Mutual labels:  annotation-processing
HighLite
An SQLite ORM for Android with automatic database migrations built with annotation processing
Stars: ✭ 77 (+5.48%)
Mutual labels:  annotation-processing
RapidORM
Quick solutions for Android ORM
Stars: ✭ 24 (-67.12%)
Mutual labels:  annotation-processing
domino-jackson
Jackson with Annotation processing
Stars: ✭ 46 (-36.99%)
Mutual labels:  annotation-processing
CrowdTruth-core
CrowdTruth framework for crowdsourcing ground truth for training & evaluation of AI systems
Stars: ✭ 45 (-38.36%)
Mutual labels:  annotation-processing
opzioni
The wanna-be-simplest command line arguments library for C++
Stars: ✭ 29 (-60.27%)
Mutual labels:  command-line-parser
piri
Piri is a lightweight annotation processing library that generates static factory methods for your Activities and Fragments.
Stars: ✭ 53 (-27.4%)
Mutual labels:  annotation-processing
command-line-commands
Add a git-like command interface to your app.
Stars: ✭ 40 (-45.21%)
Mutual labels:  command-line-parser
argparser
Simple command-line parser for C/C++ programs
Stars: ✭ 50 (-31.51%)
Mutual labels:  command-line-parser
args
Simple and type-safe commandline argument parser for C++14
Stars: ✭ 63 (-13.7%)
Mutual labels:  command-line-parser
argparse dataclass
Declarative CLIs with argparse and dataclasses
Stars: ✭ 30 (-58.9%)
Mutual labels:  command-line-parser

jbock-compiler jbock

jbock is a command line parser, which uses the well-known annotation names from JCommander and picocli. Being an annotation processor means it doesn't use reflection, but generates a custom parser at compile time instead.

Quick rundown

Create an abstract class, or alternatively a Java interface, and add the @Command annotation. In this so-called command class, each abstract method

  • must return something (not void),
  • must have no arguments, and
  • must be annotated with either @Option, @Parameter or @VarargsParameter.

The multiplicity of options and parameters is determined by the return type of their declaring method. The types boolean, List and Optional (including OptionalInt, yada yada) have a special meaning. See example below.

@Command
abstract class DeleteCommand {

  @Option(names = {"-v", "--verbosity"},
          description = {"A named option. The return type reflects optionality.",
                         "Could use Optional<Integer> too, but using int or Integer",
                         "would make it a 'required option'."})
  abstract OptionalInt verbosity();

  @Parameter(
          index = 0,
          description = {"A required positional parameter. Return type is non-optional.",
                         "Path is a standard type, so no custom converter is needed."})
  abstract Path path();

  @Parameter(
          index = 1,
          description = "An optional positional parameter.")
  abstract Optional<Path> anotherPath();

  @VarargsParameter(
          description = {"A varargs parameter. There can only be one of these.",
                         "The return type must be List-of-something."})
  abstract List<Path> morePaths();
  
  @Option(names = "--dry-run",
          description = "A nullary option, a.k.a. mode flag. Return type is boolean.")
  abstract boolean dryRun();
  
  @Option(names = "-h",
          description = "A repeatable option. Return type is List.")
  abstract List<String> headers(); 
  
  @Option(names = "--charset",
          description = "Named option with a custom converter",
          converter = CharsetConverter.class)
  abstract Optional<Charset> charset();
  
  // sample converter class
  static class CharsetConverter extends StringConverter<Charset> {
    @Override
    protected Charset convert(String token) { return Charset.forName(token); }
  }
}

The generated class is called DeleteCommandParser. It converts a string array to an instance of DeleteCommand:

public static void main(String[] args) {
  DeleteCommand command = new DeleteCommandParser().parseOrExit(args);
  // ...
}

In addition to parseOrExit, the generated parser has a basic and side-effect free parse method. This can be used to fine-tune the help and error messages for your users.

Standard types

Some types don't need a custom converter. See StandardConverters.java.

Subcommands

The @SuperCommand annotation can be used to define a git-like subcommand structure. See javadoc.

Sample projects

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].