Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/airlift/airline
Java annotation-based framework for parsing Git like command line structures
https://github.com/airlift/airline
Last synced: about 2 months ago
JSON representation
Java annotation-based framework for parsing Git like command line structures
- Host: GitHub
- URL: https://github.com/airlift/airline
- Owner: airlift
- License: apache-2.0
- Created: 2012-07-25T02:37:13.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2022-05-10T16:49:33.000Z (over 2 years ago)
- Last Synced: 2024-08-01T18:24:21.366Z (5 months ago)
- Language: Java
- Homepage:
- Size: 280 KB
- Stars: 846
- Watchers: 50
- Forks: 141
- Open Issues: 28
-
Metadata Files:
- Readme: README.md
- License: license.txt
Awesome Lists containing this project
- awesome-java - Airline - Annotation-based framework for parsing Git-like command-line arguments. (Projects / CLI)
README
# :warning: DEPRECATED :warning:
This project is no longer maintained. We recommend
[Airline 2](https://rvesse.github.io/airline/) or
[Picocli](https://picocli.info/) as a replacement.Airline
=======Airline is a Java annotation-based framework for parsing Git like command line structures.
Latest release is 0.9, available from Maven Central.
```xml
io.airlift
airline
0.9```
Here is a quick example:
```java
public class Git
{
public static void main(String[] args)
{
CliBuilder builder = Cli.builder("git")
.withDescription("the stupid content tracker")
.withDefaultCommand(Help.class)
.withCommands(Help.class, Add.class);builder.withGroup("remote")
.withDescription("Manage set of tracked repositories")
.withDefaultCommand(RemoteShow.class)
.withCommands(RemoteShow.class, RemoteAdd.class);Cli gitParser = builder.build();
gitParser.parse(args).run();
}public static class GitCommand implements Runnable
{
@Option(type = OptionType.GLOBAL, name = "-v", description = "Verbose mode")
public boolean verbose;public void run()
{
System.out.println(getClass().getSimpleName());
}
}@Command(name = "add", description = "Add file contents to the index")
public static class Add extends GitCommand
{
@Arguments(description = "Patterns of files to be added")
public List patterns;@Option(name = "-i", description = "Add modified contents interactively.")
public boolean interactive;
}@Command(name = "show", description = "Gives some information about the remote ")
public static class RemoteShow extends GitCommand
{
@Option(name = "-n", description = "Do not query remote heads")
public boolean noQuery;@Arguments(description = "Remote to show")
public String remote;
}@Command(name = "add", description = "Adds a remote")
public static class RemoteAdd extends GitCommand
{
@Option(name = "-t", description = "Track only a specific branch")
public String branch;@Arguments(description = "Remote repository to add")
public List remote;
}
}
```Assuming you have packaged this as an executable program named 'git', you would be able to execute the following commands:
```shell
$ git add -p file$ git remote add origin [email protected]:airlift/airline.git
$ git -v remote show origin
```Single Command Mode
===================Airline can also be used for simple, single-command programs:
```java
@Command(name = "ping", description = "network test utility")
public class Ping
{
@Inject
public HelpOption helpOption;@Option(name = {"-c", "--count"}, description = "Send count packets")
public int count = 1;public static void main(String... args)
{
Ping ping = SingleCommand.singleCommand(Ping.class).parse(args);if (ping.helpOption.showHelpIfRequested()) {
return;
}ping.run();
}public void run()
{
System.out.println("Ping count: " + count);
}
}
```Assuming you have packaged this as an executable program named 'ping', you would be able to execute the following commands:
```shell
$ ping$ ping -c 5
$ ping --help
```Help System
===========Airline contains a fully automated help system, which generates man-page-like documentation driven by the Java
annotations.As you may have noticed in the git code above, we added `Help.class` to the cli. This command is provided by Airline and works as follows:
```shell
$ git help
usage: git [-v] []The most commonly used git commands are:
add Add file contents to the index
help Display help information
remote Manage set of tracked repositoriesSee 'git help ' for more information on a specific command.
$ git help git
NAME
git - the stupid content trackerSYNOPSIS
git [-v] []OPTIONS
-v
Verbose modeCOMMANDS
help
Display help informationadd
Add file contents to the indexremote show
Gives some information about the remoteremote add
Adds a remote$ git help add
NAME
git add - Add file contents to the indexSYNOPSIS
git [-v] add [-i] [--] [...]OPTIONS
-i
Add modified contents interactively.-v
Verbose mode--
This option can be used to separate command-line options from the
list of argument, (useful when arguments might be mistaken for
command-line options
Patterns of files to be added$ git help remote
NAME
git remote - Manage set of tracked repositoriesSYNOPSIS
git [-v] remote
git [-v] remote add [-t ]
git [-v] remote show [-n]OPTIONS
-v
Verbose modeCOMMANDS
With no arguments, Gives some information about the remoteshow
Gives some information about the remoteWith -n option, Do not query remote heads
add
Adds a remoteWith -t option, Track only a specific branch
$ git help remote show
NAME
git remote show - Gives some information about the remoteSYNOPSIS
git [-v] remote show [-n] [--] []OPTIONS
-n
Do not query remote heads-v
Verbose mode--
This option can be used to separate command-line options from the
list of argument, (useful when arguments might be mistaken for
command-line options
Remote to show
```We have also, add `Help.class` as the default command for git, so if you execute git without any arguments, you will see the following:
```shell
$ git help
usage: git [-v] []The most commonly used git commands are:
add Add file contents to the index
help Display help information
remote Manage set of tracked repositoriesSee 'git help ' for more information on a specific command.
```For simple, single-command programs like ping, use the `HelpOption` option as shown in the example above.
`HelpOption` handles the options `-h` and `--help` and provides the `showHelpIfRequested()` method
to automatically show the following help output:```shell
$ ping -h
NAME
ping - network test utilitySYNOPSIS
ping [(-c | --count )] [(-h | --help)]OPTIONS
-c , --count
Send count packets-h, --help
Display help information
```