private void validateClassifiers( Set<String> availableClassifiers, Set<String> orphans ) throws IncorrectUsage { for ( String classifier : orphans ) { if ( !availableClassifiers.contains( classifier ) ) { throw new IncorrectUsage( "Unknown classifier: " + classifier ); } } }
private void validate() throws IncorrectUsage { for ( String o : parsedArgs.asMap().keySet() ) { if ( !namedArgs.containsKey( o ) ) { throw new IncorrectUsage( format( "unrecognized option: '%s'", o ) ); } } long mandatoryPositionalArgs = positionalArgs.stream() .filter( o -> o instanceof MandatoryPositionalArgument ) .count(); if ( parsedArgs.orphans().size() < mandatoryPositionalArgs ) { throw new IncorrectUsage( "not enough arguments" ); } String excessArgs = parsedArgs.orphans().stream() .skip( positionalArgs.size() ) .collect( Collectors.joining( " " ) ); if ( !excessArgs.isEmpty() ) { throw new IncorrectUsage( format( "unrecognized arguments: '%s'", excessArgs ) ); } }
DatabaseImporter( Args args, Config config, OutsideWorld outsideWorld ) throws IncorrectUsage { this.config = config; try { this.from = args.interpretOption( "from", Converters.mandatory(), Converters.toFile(), Validators.CONTAINS_EXISTING_DATABASE ); } catch ( IllegalArgumentException e ) { throw new IncorrectUsage( e.getMessage() ); } }
@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 ); } } }
throw new IncorrectUsage( "If you specify 'all' this has to be the only classifier. Found ['" + String.join( "','", classifiers ) + "'] as well." );
throw new IncorrectUsage( e.getMessage() ); throw new IncorrectUsage( e.getMessage() );
CsvImporter( Args args, Config databaseConfig, OutsideWorld outsideWorld ) throws IncorrectUsage { this.args = args; this.outsideWorld = outsideWorld; nodesFiles = extractInputFiles( args, "nodes", outsideWorld.errorStream() ); relationshipsFiles = extractInputFiles( args, "relationships", outsideWorld.errorStream() ); reportFileName = args.interpretOption( "report-file", withDefault( ImportCommand.DEFAULT_REPORT_FILE_NAME ), s -> s ); ignoreExtraColumns = args.getBoolean( "ignore-extra-columns", false ); ignoreDuplicateNodes = args.getBoolean( "ignore-duplicate-nodes", false ); ignoreBadRelationships = args.getBoolean( "ignore-missing-nodes", false ); try { validateInputFiles( nodesFiles, relationshipsFiles ); } catch ( IllegalArgumentException e ) { throw new IncorrectUsage( e.getMessage() ); } idType = args.interpretOption( "id-type", withDefault( IdType.STRING ), from -> IdType.valueOf( from.toUpperCase() ) ); inputEncoding = Charset.forName( args.get( "input-encoding", defaultCharset().name() ) ); highIO = args.getBoolean( "high-io", null, true ); // intentionally left as null if not specified this.databaseConfig = databaseConfig; }
@Test void shouldProvideFeedbackIfTheCommandReportsAUsageProblem() { OutsideWorld outsideWorld = mock( OutsideWorld.class ); AdminCommand command = args -> { throw new IncorrectUsage( "the-usage-message" ); }; new AdminTool( cannedCommand( "exception", command ), new NullBlockerLocator(), outsideWorld, false ) .execute( null, null, "exception" ); InOrder inOrder = inOrder( outsideWorld ); inOrder.verify( outsideWorld ).stdErrLine( "the-usage-message" ); verify( outsideWorld ).exit( STATUS_ERROR ); }
throw new IncorrectUsage( e.getMessage() ); throw new IncorrectUsage( "Only one of '--" + ARG_DATABASE + "' and '--backup' can be specified." ); throw new IncorrectUsage( e.getMessage() );
private void validateClassifiers( Set<String> availableClassifiers, Set<String> orphans ) throws IncorrectUsage { for ( String classifier : orphans ) { if ( !availableClassifiers.contains( classifier ) ) { throw new IncorrectUsage( "Unknown classifier: " + classifier ); } } }
DatabaseImporter( Args args, Config config, OutsideWorld outsideWorld ) throws IncorrectUsage { this.config = config; try { this.from = args.interpretOption( "from", Converters.mandatory(), Converters.toFile(), Validators.CONTAINS_EXISTING_DATABASE ); } catch ( IllegalArgumentException e ) { throw new IncorrectUsage( e.getMessage() ); } }
throw new IncorrectUsage( "If you specify 'all' this has to be the only classifier. Found ['" + String.join( "','", classifiers ) + "'] as well." );
throw new IncorrectUsage( e.getMessage() ); throw new IncorrectUsage( e.getMessage() );
@Override public void execute( String[] incomingArguments ) throws IncorrectUsage, CommandFailed { String databaseName; String fromPath; boolean forceOverwrite; try { databaseName = arguments.parse( incomingArguments ).get( ARG_DATABASE ); fromPath = arguments.get( "from" ); forceOverwrite = arguments.getBoolean( "force" ); } catch ( IllegalArgumentException e ) { throw new IncorrectUsage( e.getMessage() ); } Config config = loadNeo4jConfig( homeDir, configDir, databaseName ); try ( FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction() ) { RestoreDatabaseCommand restoreDatabaseCommand = new RestoreDatabaseCommand( fileSystem, new File( fromPath ), config, databaseName, forceOverwrite ); restoreDatabaseCommand.execute(); } catch ( IOException e ) { throw new CommandFailed( "Failed to restore database", e ); } }
CsvImporter( Args args, Config databaseConfig, OutsideWorld outsideWorld ) throws IncorrectUsage { this.args = args; this.outsideWorld = outsideWorld; nodesFiles = extractInputFiles( args, "nodes", outsideWorld.errorStream() ); relationshipsFiles = extractInputFiles( args, "relationships", outsideWorld.errorStream() ); reportFileName = args.interpretOption( "report-file", withDefault( ImportCommand.DEFAULT_REPORT_FILE_NAME ), s -> s ); ignoreExtraColumns = args.getBoolean( "ignore-extra-columns", false ); ignoreDuplicateNodes = args.getBoolean( "ignore-duplicate-nodes", false ); ignoreBadRelationships = args.getBoolean( "ignore-missing-nodes", false ); try { validateInputFiles( nodesFiles, relationshipsFiles ); } catch ( IllegalArgumentException e ) { throw new IncorrectUsage( e.getMessage() ); } idType = args.interpretOption( "id-type", withDefault( IdType.STRING ), from -> IdType.valueOf( from.toUpperCase() ) ); inputEncoding = Charset.forName( args.get( "input-encoding", defaultCharset().name() ) ); highIO = args.getBoolean( "high-io", null, true ); // intentionally left as null if not specified this.databaseConfig = databaseConfig; }
throw new IncorrectUsage( e.getMessage() );
throw new IncorrectUsage( e.getMessage() );