Skip to content

Commit

Permalink
Merge pull request #10 from DarviL82/dev
Browse files Browse the repository at this point in the history
Version 0.1.0 - Fixing terrible errors.
  • Loading branch information
darvil82 authored Nov 6, 2023
2 parents d99a902 + 2798ed7 commit 2413530
Show file tree
Hide file tree
Showing 35 changed files with 844 additions and 480 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/gradle-publish.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Publish to Github Packages

on:
Expand Down
110 changes: 62 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,75 @@
# Lanat

Lanat is a command line argument parser for Java 17 with ease of use and high customization
possibilities in mind.

### Examples
Here is an example of a simple argument parser definition.

```java
@Command.Define
class MyProgram {
@Argument.Define(required = true, positional = true, description = "The name of the user.")
public String name;

@Argument.Define(argType = StringArgumentType.class, description = "The surname of the user.")
public Optional<String> surname;

@Argument.Define(names = {"age", "a"}, description = "The age of the user.", prefix = '+')
public int age = 18;
<div align="center">
<div>
<img src="https://github.com/DarviL82/Lanat/assets/48654552/33f9a03d-1ce3-49f0-839d-475e35d9e816" width="450">
</div>
<br>
<strong>
A command line argument parser for Java 17 with <br>
ease of use and high customization possibilities in mind.
</strong>
</div>

<br><br>


### Example
- First, we define our Command by creating a *Command Template*.

@InitDef
public static void beforeInit(@NotNull CommandBuildHelper cmdBuildHelper) {
// configure the argument "age" to have an argument type of
// number range and set the range to 1-100
cmdBuildHelper.<NumberRangeArgumentType<Integer>, Integer>getArgument("age")
.withArgType(new NumberRangeArgumentType<>(1, 100))
.onOk(v -> System.out.println("The age is valid!"));
}
}

class Test {
public static void main(String[] args) {
// example: david +a20
var myProgram = ArgumentParser.parseFromInto(MyProgram.class, CLInput.from(args));
```java
@Command.Define
class MyProgram {
@Argument.Define(required = true, positional = true, description = "The name of the user.")
public String name;

@Argument.Define(argType = StringArgumentType.class, description = "The surname of the user.")
public Optional<String> surname;

@Argument.Define(names = {"age", "a"}, description = "The age of the user.", prefix = '+')
public int age = 18;
System.out.printf(
"Welcome %s! You are %d years old.%n",
myProgram.name, myProgram.age
);

// if no surname was specified, we'll show "none" instead
System.out.printf("The surname of the user is %s.%n", myProgram.surname.orElse("none"));
@InitDef
public static void beforeInit(@NotNull CommandBuildHelper cmdBuildHelper) {
// configure the argument "age" to have an argument type of
// number range and set the range to 1-100
cmdBuildHelper.<NumberRangeArgumentType<Integer>, Integer>getArgument("age")
.withArgType(new NumberRangeArgumentType<>(1, 100))
.onOk(v -> System.out.println("The age is valid!"));
}
}
```

- Then, let that class definition also serve as the container for the parsed values.
```java
class Test {
public static void main(String[] args) {
// example: david +a20
var myProgram = ArgumentParser.parseFromInto(MyProgram.class, CLInput.from(args));

System.out.printf(
"Welcome %s! You are %d years old.%n",
myProgram.name, myProgram.age
);

// if no surname was specified, we'll show "none" instead
System.out.printf("The surname of the user is %s.%n", myProgram.surname.orElse("none"));
}
}
}
```
```

## Documentation

Javadoc documentation for the latest stable version is available [here](https://darvil82.github.io/Lanat/).

Deep documentation and tutorials comming soon.


## Installation

The package is currently only available on GitHub Packages.

### Gradle

1. Authenticate to GitHub Packages in order to be able to download the package. You can do this by adding the following to your [gradle.properties](https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties) file:
1. Authenticate to GitHub Packages to be able to download the package. You can do this by adding the following to your [gradle.properties](https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties) file:

```
gpr.user=USERNAME
Expand All @@ -70,8 +84,8 @@ The package is currently only available on GitHub Packages.
maven {
url = uri("https://maven.pkg.github.com/darvil82/lanat")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("CI_GITHUB_USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("CI_GITHUB_PASSWORD")
username = project.findProperty("gpr.user") as String?
password = project.findProperty("gpr.key") as String?
}
}
```
Expand All @@ -80,9 +94,9 @@ The package is currently only available on GitHub Packages.

```kotlin
implementation("darvil:lanat")
```

Note that you may need to explicitly specify the version of the package you want to use. (e.g. `darvil:lanat:x.x.x`)
```
> [!NOTE]
> You may need to explicitly specify the version of the package you want to use. (e.g. `darvil:lanat:x.x.x`).

This information is available at the [GitHub Packages documentation](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry#using-a-published-package).

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "darvil"
version = "0.0.3"
version = "0.1.0"
description = "Command line argument parser"

dependencies {
Expand Down
Loading

0 comments on commit 2413530

Please sign in to comment.