Skip to content

Builder API for creating the CLI #109

@dblevins

Description

@dblevins

Builders can be used to construct the exact environment needed.

For example:

import org.tomitribe.crest.Main;

public class Example {

    public static void main(String[] args) {
        final Main main = Main.builder()
                .properties(System.getProperties())
                .env(System.getenv())
                .out(System.out)
                .err(System.err)
                .in(System.in)
                .exit(System::exit)
                .command(PizzaCommands.class)
                .command(SandwichCommands.class)
                .build();

        main.run(args);
    }
}

The above can be reduced further using the following convenience builder method that defaults most the above:

import org.tomitribe.crest.Main;

public class Example {

    public static void main(String[] args) {
        final Main main = Main.systemDefaults()
                .command(PizzaCommands.class)
                .command(SandwichCommands.class)
                .build();

        main.run(args);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions