@Override public String parse( Args parsedArgs ) { String value = parsedArgs.interpretOption( name, withDefault( defaultValue ), identity() ); if ( allowedValues.length > 0 ) { for ( String allowedValue : allowedValues ) { if ( allowedValue.equals( value ) ) { return value; } } throw new IllegalArgumentException( String.format( "'%s' must be one of [%s], not: %s", name, String.join( ",", allowedValues ), value ) ); } return value; }
@Override public String parse( Args parsedArgs ) { return parsedArgs.interpretOption( name, mandatory(), identity() ); }
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() ); } }
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 shouldInterpretOption() { // GIVEN int expectedValue = 42; Args args = Args.parse( "--arg", String.valueOf( expectedValue )); @SuppressWarnings( "unchecked" ) Validator<Integer> validator = mock( Validator.class ); // WHEN int value = args.interpretOption( "arg", mandatory(), toInt(), validator ); // THEN assertEquals( expectedValue, value ); verify( validator ).validate( expectedValue ); }
storeDir = args.interpretOption( Options.STORE_DIR.key(), Converters.mandatory(), Converters.toFile(), Validators.DIRECTORY_IS_WRITABLE ); Config config = Config.defaults( GraphDatabaseSettings.neo4j_home, storeDir.getAbsolutePath() ); enableStacktrace = args.getBoolean( Options.STACKTRACE.key(), Boolean.FALSE, Boolean.TRUE ); processors = args.getNumber( Options.PROCESSORS.key(), null ); idType = args.interpretOption( Options.ID_TYPE.key(), withDefault( (IdType)Options.ID_TYPE.defaultValue() ), TO_ID_TYPE ); badTolerance = parseNumberOrUnlimited( args, Options.BAD_TOLERANCE ); skipBadEntriesLogging, badOutput ); dbConfig = loadDbConfig( args.interpretOption( Options.DATABASE_CONFIG.key(), Converters.optional(), Converters.toFile(), Validators.REGEX_FILE_EXISTS ) ); dbConfig.augment( loadDbConfig( args.interpretOption( Options.ADDITIONAL_CONFIG.key(), Converters.optional(), Converters.toFile(), Validators.REGEX_FILE_EXISTS ) ) ); boolean allowCacheOnHeap = args.getBoolean( Options.CACHE_ON_HEAP.key(),
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() ); } }
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; }
storeDir = args.interpretOption( Options.STORE_DIR.key(), Converters.mandatory(), Converters.toFile(), Validators.DIRECTORY_IS_WRITABLE ); Config config = Config.defaults( GraphDatabaseSettings.neo4j_home, storeDir.getAbsolutePath() ); enableStacktrace = args.getBoolean( Options.STACKTRACE.key(), Boolean.FALSE, Boolean.TRUE ); processors = args.getNumber( Options.PROCESSORS.key(), null ); idType = args.interpretOption( Options.ID_TYPE.key(), withDefault( (IdType)Options.ID_TYPE.defaultValue() ), TO_ID_TYPE ); badTolerance = parseNumberOrUnlimited( args, Options.BAD_TOLERANCE ); skipBadEntriesLogging, badOutput ); dbConfig = loadDbConfig( args.interpretOption( Options.DATABASE_CONFIG.key(), Converters.optional(), Converters.toFile(), Validators.REGEX_FILE_EXISTS ) ); dbConfig.augment( loadDbConfig( args.interpretOption( Options.ADDITIONAL_CONFIG.key(), Converters.optional(), Converters.toFile(), Validators.REGEX_FILE_EXISTS ) ) ); boolean allowCacheOnHeap = args.getBoolean( Options.CACHE_ON_HEAP.key(),