private void badUsage( String message ) { outsideWorld.stdErrLine( message ); usage.print( outsideWorld::stdErrLine ); failure(); }
@Override public void execute( String... args ) throws IncorrectUsage { if ( args.length > 0 ) { try { AdminCommand.Provider commandProvider = this.locator.findProvider( args[0] ); usage.printUsageForCommand( commandProvider, output ); } catch ( NoSuchElementException e ) { StringBuilder validCommands = new StringBuilder(); locator.getAllProviders() .forEach( commandProvider -> validCommands.append( commandProvider.name() ).append( " " ) ); throw new IncorrectUsage( format( "Unknown command: %s. Available commands are: %s\n", args[0], validCommands ) ); } } else { usage.print( output ); } } }
@Test void shouldPrintUsageWithConfiguration() { AdminCommand.Provider[] commands = new AdminCommand.Provider[]{mockCommand( "bam", "A summary", AdminCommandSection.general() )}; final Usage usage = new Usage( "neo4j-admin", new CannedLocator( commands ) ); usage.print( out ); InOrder ordered = inOrder( out ); ordered.verify( out ).accept( "usage: neo4j-admin <command>" ); ordered.verify( out ).accept( "" ); ordered.verify( out ).accept( "Manage your Neo4j instance." ); ordered.verify( out ).accept( "" ); ordered.verify( out ).accept( "environment variables:" ); ordered.verify( out ).accept( " NEO4J_CONF Path to directory which contains neo4j.conf." ); ordered.verify( out ).accept( " NEO4J_DEBUG Set to anything to enable debug output." ); ordered.verify( out ).accept( " NEO4J_HOME Neo4j home directory." ); ordered.verify( out ).accept( " HEAP_SIZE Set JVM maximum heap size during command execution." ); ordered.verify( out ).accept( " Takes a number and a unit, for example 512m." ); ordered.verify( out ).accept( "" ); ordered.verify( out ).accept( "available commands:" ); ordered.verify( out ).accept( "General" ); ordered.verify( out ).accept( " bam" ); ordered.verify( out ).accept( " A summary" ); ordered.verify( out ).accept( "" ); ordered.verify( out ).accept( "Use neo4j-admin help <command> for more details." ); ordered.verifyNoMoreInteractions(); }
@Test void commandsUnderSameAdminCommandSectionPrintableSectionShouldAppearTogether() { AdminCommand.Provider[] commands = new AdminCommand.Provider[]{ mockCommand( "first-command", "first-command", AdminCommandSection.general() ), mockCommand( "second-command", "second-command", new TestGeneralSection() )}; final Usage usage = new Usage( "neo4j-admin", new CannedLocator( commands ) ); usage.print( out ); InOrder ordered = inOrder( out ); ordered.verify( out ).accept( "usage: neo4j-admin <command>" ); ordered.verify( out ).accept( "" ); ordered.verify( out ).accept( "Manage your Neo4j instance." ); ordered.verify( out ).accept( "" ); ordered.verify( out ).accept( "environment variables:" ); ordered.verify( out ).accept( " NEO4J_CONF Path to directory which contains neo4j.conf." ); ordered.verify( out ).accept( " NEO4J_DEBUG Set to anything to enable debug output." ); ordered.verify( out ).accept( " NEO4J_HOME Neo4j home directory." ); ordered.verify( out ).accept( " HEAP_SIZE Set JVM maximum heap size during command execution." ); ordered.verify( out ).accept( " Takes a number and a unit, for example 512m." ); ordered.verify( out ).accept( "" ); ordered.verify( out ).accept( "available commands:" ); ordered.verify( out ).accept( "General" ); ordered.verify( out ).accept( " first-command" ); ordered.verify( out ).accept( " first-command" ); ordered.verify( out ).accept( " second-command" ); ordered.verify( out ).accept( " second-command" ); ordered.verify( out ).accept( "" ); ordered.verify( out ).accept( "Use neo4j-admin help <command> for more details." ); ordered.verifyNoMoreInteractions(); }