public static CliConfig fromConfig(final Config config) { checkNotNull(config); final Map<String, Object> defaultSettings = ImmutableMap.of( DOMAINS_KEY, EMPTY_STRING_LIST, SRV_NAME_KEY, "helios", MASTER_ENDPOINTS_KEY, EMPTY_STRING_LIST ); final Config configWithDefaults = config.withFallback(ConfigFactory.parseMap(defaultSettings)); final List<String> domains = configWithDefaults.getStringList(DOMAINS_KEY); final String srvName = configWithDefaults.getString(SRV_NAME_KEY); final List<URI> masterEndpoints = Lists.newArrayList(); for (final String endpoint : configWithDefaults.getStringList(MASTER_ENDPOINTS_KEY)) { masterEndpoints.add(URI.create(endpoint)); } return new CliConfig(domains, srvName, masterEndpoints); } }
return fromConfig(config); return fromConfig(configFromEnvVar);
/** * Returns a CliConfig instance with values parsed from the specified file. * * <p>If the file is not found, a CliConfig with pre-defined values will be returned. * * @param defaultsFile The file to parse from * * @return The configuration * * @throws IOException If the file exists but could not be read * @throws URISyntaxException If a HELIOS_MASTER env var is present and doesn't parse as a URI */ public static CliConfig fromFile(final File defaultsFile, final Map<String, String> environmentVariables) throws IOException, URISyntaxException { final Config config; if (defaultsFile.exists() && defaultsFile.canRead()) { config = ConfigFactory.parseFile(defaultsFile); } else { config = ConfigFactory.empty(); } return fromEnvVar(config, environmentVariables); }
private List<Target> computeTargets(final ArgumentParser parser, final List<String> explicitEndpoints, final List<String> domainsArguments, final String srvName) { if (explicitEndpoints != null && !explicitEndpoints.isEmpty()) { final List<Target> targets = Lists.newArrayListWithExpectedSize(explicitEndpoints.size()); for (final String endpoint : explicitEndpoints) { targets.add(Target.from(URI.create(endpoint))); } return targets; } else if (domainsArguments != null && !domainsArguments.isEmpty()) { final Iterable<String> domains = parseDomains(domainsArguments); return Target.from(srvName, domains); } else if (!cliConfig.getMasterEndpoints().isEmpty()) { final List<URI> cliConfigMasterEndpoints = cliConfig.getMasterEndpoints(); final List<Target> targets = Lists.newArrayListWithExpectedSize( cliConfigMasterEndpoints.size()); for (final URI endpoint : cliConfigMasterEndpoints) { targets.add(Target.from(endpoint)); } return targets; } else if (!cliConfig.getDomainsString().isEmpty()) { final Iterable<String> domains = parseDomainsString(cliConfig.getDomainsString()); return Target.from(srvName, domains); } handleError(parser, new ArgumentParserException( "no masters specified. Use the -z or -d option to specify which helios " + "cluster/master to connect to", parser)); return ImmutableList.of(); }
.description(format("%s%n%n%s%n%s", NAME_AND_VERSION, HELP_ISSUES, HELP_WIKI)); cliConfig = CliConfig.fromUserConfig(System.getenv()); this.username = (username == null) ? cliConfig.getUsername() : username; this.json = equal(options.getBoolean(globalArgs.jsonArg.getDest()), true); this.loggingConfig = new LoggingConfig(options.getInt(globalArgs.verbose.getDest()),
/** * Returns a CliConfig instance with values from a config file from under the users home * directory: * * <p><user.home>/.helios/config * * <p>If the file is not found, a CliConfig with pre-defined values will be returned. * * @return The configuration * * @throws IOException If the file exists but could not be read * @throws URISyntaxException If a HELIOS_MASTER env var is present and doesn't parse as a URI */ public static CliConfig fromUserConfig(final Map<String, String> environmentVariables) throws IOException, URISyntaxException { final String userHome = System.getProperty("user.home"); final String defaults = userHome + File.separator + CONFIG_PATH; final File defaultsFile = new File(defaults); return fromFile(defaultsFile, environmentVariables); }
.setDefault(cliConfig.getSrvName()) .help("master srv name");
private List<Target> computeTargets(final ArgumentParser parser, final List<String> explicitEndpoints, final List<String> domainsArguments, final String srvName) { if (explicitEndpoints != null && !explicitEndpoints.isEmpty()) { final List<Target> targets = Lists.newArrayListWithExpectedSize(explicitEndpoints.size()); for (final String endpoint : explicitEndpoints) { targets.add(Target.from(URI.create(endpoint))); } return targets; } else if (domainsArguments != null && !domainsArguments.isEmpty()) { final Iterable<String> domains = parseDomains(domainsArguments); return Target.from(srvName, domains); } else if (!cliConfig.getMasterEndpoints().isEmpty()) { final List<URI> cliConfigMasterEndpoints = cliConfig.getMasterEndpoints(); List<Target> targets = Lists.newArrayListWithExpectedSize(cliConfigMasterEndpoints.size()); for (final URI endpoint : cliConfigMasterEndpoints) { targets.add(Target.from(endpoint)); } return targets; } else if (!cliConfig.getDomainsString().isEmpty()) { final Iterable<String> domains = parseDomainsString(cliConfig.getDomainsString()); return Target.from(srvName, domains); } handleError(parser, new ArgumentParserException( "no masters specified. Use the -z or -d option to specify which helios " + "cluster/master to connect to", parser)); return ImmutableList.of(); }
.description(format("%s%n%n%s%n%s", NAME_AND_VERSION, HELP_ISSUES, HELP_WIKI)); cliConfig = CliConfig.fromUserConfig(); this.username = (username == null) ? cliConfig.getUsername() : username; this.json = equal(options.getBoolean(globalArgs.jsonArg.getDest()), true); this.loggingConfig = new LoggingConfig(options.getInt(globalArgs.verbose.getDest()),
/** * Returns a CliConfig instance with values from a config file from under the users home * directory: * * <user.home>/.helios/config * * If the file is not found, a CliConfig with pre-defined values will be returned. * * @return The configuration * @throws IOException If the file exists but could not be read * @throws URISyntaxException If a HELIOS_MASTER env var is present and doesn't parse as a URI */ public static CliConfig fromUserConfig() throws IOException, URISyntaxException { final String userHome = System.getProperty("user.home"); final String defaults = userHome + File.separator + CONFIG_PATH; final File defaultsFile = new File(defaults); return fromFile(defaultsFile); }
.setDefault(cliConfig.getSrvName()) .help("master srv name");
public static CliConfig fromConfig(final Config config) { checkNotNull(config); final Map<String, Object> defaultSettings = ImmutableMap.of( DOMAINS_KEY, EMPTY_STRING_LIST, SRV_NAME_KEY, "helios", MASTER_ENDPOINTS_KEY, EMPTY_STRING_LIST ); final Config configWithDefaults = config.withFallback(ConfigFactory.parseMap(defaultSettings)); final List<String> domains = configWithDefaults.getStringList(DOMAINS_KEY); final String srvName = configWithDefaults.getString(SRV_NAME_KEY); final List<URI> masterEndpoints = Lists.newArrayList(); for (final String endpoint : configWithDefaults.getStringList(MASTER_ENDPOINTS_KEY)) { masterEndpoints.add(URI.create(endpoint)); } return new CliConfig(domains, srvName, masterEndpoints); } }
/** * Returns a CliConfig instance with values parsed from the specified file. * * If the file is not found, a CliConfig with pre-defined values will be returned. * * @param defaultsFile The file to parse from * @return The configuration * @throws IOException If the file exists but could not be read * @throws URISyntaxException If a HELIOS_MASTER env var is present and doesn't parse as a URI */ public static CliConfig fromFile(final File defaultsFile) throws IOException, URISyntaxException { final Config config; if (defaultsFile.exists() && defaultsFile.canRead()) { config = ConfigFactory.parseFile(defaultsFile); } else { config = ConfigFactory.empty(); } return fromEnvVar(config); }
public static CliConfig fromEnvVar(final Config config) throws URISyntaxException { final String master = environment.get("HELIOS_MASTER"); if (master == null) { return fromConfig(config); return fromConfig(configFromEnvVar);