Search in sources :

Example 1 with Arguments

use of org.neo4j.commandline.arguments.Arguments in project neo4j by neo4j.

the class HelpCommandTest method showsArgumentsAndDescriptionForSpecifiedCommand.

@Test
public void showsArgumentsAndDescriptionForSpecifiedCommand() throws Exception {
    CommandLocator commandLocator = mock(CommandLocator.class);
    AdminCommand.Provider commandProvider = mock(AdminCommand.Provider.class);
    when(commandProvider.name()).thenReturn("foobar");
    Arguments arguments = new Arguments().withDatabase();
    when(commandProvider.allArguments()).thenReturn(arguments);
    when(commandProvider.possibleArguments()).thenReturn(Collections.singletonList(arguments));
    when(commandProvider.description()).thenReturn("This is a description of the foobar command.");
    when(commandLocator.findProvider("foobar")).thenReturn(commandProvider);
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        PrintStream ps = new PrintStream(baos);
        HelpCommand helpCommand = new HelpCommand(new Usage("neo4j-admin", commandLocator), ps::println, commandLocator);
        helpCommand.execute("foobar");
        assertEquals(String.format("usage: neo4j-admin foobar [--database=<name>]%n" + "%n" + "This is a description of the foobar command.%n" + "%n" + "options:%n" + "  --database=<name>   Name of database. [default:graph.db]%n"), baos.toString());
    }
}
Also used : PrintStream(java.io.PrintStream) Arguments(org.neo4j.commandline.arguments.Arguments) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with Arguments

use of org.neo4j.commandline.arguments.Arguments in project neo4j by neo4j.

the class CommandUsage method printDetailed.

void printDetailed(Consumer<String> output) {
    for (Arguments arguments : command.possibleArguments()) {
        String left = format("usage: %s %s", scriptName, command.name());
        output.accept(Arguments.rightColumnFormatted(left, arguments.usage(), left.length() + 1));
    }
    output.accept("");
    output.accept(command.allArguments().description(command.description()));
}
Also used : Arguments(org.neo4j.commandline.arguments.Arguments)

Aggregations

Arguments (org.neo4j.commandline.arguments.Arguments)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 PrintStream (java.io.PrintStream)1 Test (org.junit.Test)1