Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builder API for creating the CLI #109

Open
dblevins opened this issue Feb 9, 2024 · 0 comments
Open

Builder API for creating the CLI #109

dblevins opened this issue Feb 9, 2024 · 0 comments

Comments

@dblevins
Copy link
Member

dblevins commented Feb 9, 2024

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);
    }
}
dblevins added a commit that referenced this issue Feb 9, 2024
dblevins added a commit that referenced this issue Feb 12, 2024
Refactor test utilities
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant