@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 ); } } }
private void badUsage( AdminCommand.Provider command, IncorrectUsage e ) { outsideWorld.stdErrLine( e.getMessage() ); outsideWorld.stdErrLine( "" ); usage.printUsageForCommand( command, outsideWorld::stdErrLine ); failure(); }
@Test void shouldPrintUsageForACommand() { // given AdminCommand.Provider commandProvider = mockCommand( "bam", "A summary", AdminCommandSection.general() ); AdminCommand.Provider[] commands = new AdminCommand.Provider[]{commandProvider}; final Usage usage = new Usage( "neo4j-admin", new CannedLocator( commands ) ); // when usage.printUsageForCommand( commandProvider, out ); // then InOrder ordered = inOrder( out ); ordered.verify( out ).accept( "usage: neo4j-admin bam " ); 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( "description" ); }
@Test public void shouldPrintNiceHelp() throws Throwable { try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { PrintStream ps = new PrintStream( baos ); Usage usage = new Usage( "neo4j-admin", mock( CommandLocator.class ) ); usage.printUsageForCommand( new SetInitialPasswordCommandProvider(), ps::println ); assertEquals( String.format( "usage: neo4j-admin set-initial-password <password>%n" + "%n" + "environment variables:%n" + " NEO4J_CONF Path to directory which contains neo4j.conf.%n" + " NEO4J_DEBUG Set to anything to enable debug output.%n" + " NEO4J_HOME Neo4j home directory.%n" + " HEAP_SIZE Set JVM maximum heap size during command execution.%n" + " Takes a number and a unit, for example 512m.%n" + "%n" + "Sets the initial password of the initial admin user ('neo4j').%n" ), baos.toString() ); } }
@Test public void shouldPrintNiceHelp() throws Throwable { try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { PrintStream ps = new PrintStream( baos ); Usage usage = new Usage( "neo4j-admin", mock( CommandLocator.class ) ); usage.printUsageForCommand( new SetDefaultAdminCommandProvider(), ps::println ); assertEquals( String.format( "usage: neo4j-admin set-default-admin <username>%n" + "%n" + "environment variables:%n" + " NEO4J_CONF Path to directory which contains neo4j.conf.%n" + " NEO4J_DEBUG Set to anything to enable debug output.%n" + " NEO4J_HOME Neo4j home directory.%n" + " HEAP_SIZE Set JVM maximum heap size during command execution.%n" + " Takes a number and a unit, for example 512m.%n" + "%n" + "Sets the user to become admin if users but no roles are present, for example%n" + "when upgrading to neo4j 3.1 enterprise.%n" ), baos.toString() ); } }
@Test public void shouldPrintNiceHelp() throws Exception { try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { PrintStream ps = new PrintStream( baos ); Usage usage = new Usage( "neo4j-admin", mock( CommandLocator.class ) ); usage.printUsageForCommand( new StoreInfoCommandProvider(), ps::println ); assertEquals( String.format( "usage: neo4j-admin store-info --store=<path-to-dir>%n" + "%n" + "environment variables:%n" + " NEO4J_CONF Path to directory which contains neo4j.conf.%n" + " NEO4J_DEBUG Set to anything to enable debug output.%n" + " NEO4J_HOME Neo4j home directory.%n" + " HEAP_SIZE Set JVM maximum heap size during command execution.%n" + " Takes a number and a unit, for example 512m.%n" + "%n" + "Prints information about a Neo4j database store, such as what version of Neo4j%n" + "created it. Note that this command expects a path to a store directory, for%n" + "example --store=data/databases/graph.db.%n" + "%n" + "options:%n" + " --store=<path-to-dir> Path to database store.%n" ), baos.toString() ); } }
@Test void shouldPrintNiceHelp() throws Exception { try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) { PrintStream ps = new PrintStream( baos ); Usage usage = new Usage( "neo4j-admin", mock( CommandLocator.class ) ); usage.printUsageForCommand( new DumpCommandProvider(), ps::println ); assertEquals( String.format( "usage: neo4j-admin dump [--database=<name>] --to=<destination-path>%n" + "%n" + "environment variables:%n" + " NEO4J_CONF Path to directory which contains neo4j.conf.%n" + " NEO4J_DEBUG Set to anything to enable debug output.%n" + " NEO4J_HOME Neo4j home directory.%n" + " HEAP_SIZE Set JVM maximum heap size during command execution.%n" + " Takes a number and a unit, for example 512m.%n" + "%n" + "Dump a database into a single-file archive. The archive can be used by the load%n" + "command. <destination-path> can be a file or directory (in which case a file%n" + "called <database>.dump will be created). It is not possible to dump a database%n" + "that is mounted in a running Neo4j server.%n" + "%n" + "options:%n" + " --database=<name> Name of database. [default:" + GraphDatabaseSettings.DEFAULT_DATABASE_NAME + "]%n" + " --to=<destination-path> Destination (file or folder) of database dump.%n" ), baos.toString() ); } }
usage.printUsageForCommand( new LoadCommandProvider(), ps::println );
usage.printUsageForCommand( new CheckConsistencyCommandProvider(), ps::println );
usage.printUsageForCommand( new ImportCommandProvider(), ps::println );
usage.printUsageForCommand( provider, outsideWorld::stdErrLine ); failure();