private static AppArgs ParseArgsImpl(String[] args) { if (args.Length == 1 && String.Equals(args[0], HelpOption)) { return(new AppArgs(AppUsageMode.Help)); } if (args.Length == 1 && String.Equals(args[0], VersionOption)) { return(new AppArgs(AppUsageMode.Version)); } ISet <String> parsedOptions = new HashSet <String>(); AppArgs appArgs = new AppArgs(AppUsageMode.Analysis); foreach (String arg in args) { if (arg.StartsWith(SourceOption)) { if (!parsedOptions.Add(SourceOption)) { return(new AppArgs(AppUsageMode.BadSource)); } String source = EnvironmentVariableHelper.ExpandEnvironmentVariables(arg.Substring(SourceOption.Length)); if (String.IsNullOrEmpty(source)) { return(new AppArgs(AppUsageMode.BadSource)); } appArgs.Source = source; } else if (arg.StartsWith(ConfigOption)) { if (!parsedOptions.Add(ConfigOption)) { return(new AppArgs(AppUsageMode.BadConfig)); } String config = EnvironmentVariableHelper.ExpandEnvironmentVariables(arg.Substring(ConfigOption.Length)); if (String.IsNullOrEmpty(config)) { return(new AppArgs(AppUsageMode.BadConfig)); } appArgs.Config = config; } else if (arg.StartsWith(OutputLevelOption)) { if (!parsedOptions.Add(OutputLevelOption)) { return(new AppArgs(AppUsageMode.BadAppUsage)); } if (!Enum.TryParse(arg.Substring(OutputLevelOption.Length), out OutputLevel outputLevel)) { return(new AppArgs(AppUsageMode.BadAppUsage)); } appArgs.OutputLevel = outputLevel; } else { return(new AppArgs(AppUsageMode.BadAppUsage)); } } return(String.IsNullOrEmpty(appArgs.Source) ? new AppArgs(AppUsageMode.BadAppUsage) : appArgs); }
// TODO (std_string) : think about non-recursive version of this impl private ConfigData LoadImpl(String sourceImportName, String parentConfig) { String importName = EnvironmentVariableHelper.ExpandEnvironmentVariables(sourceImportName).Replace("/", "\\"); if (String.IsNullOrEmpty(importName)) { throw new PorterConfigException($"Bad import name value \"{sourceImportName}\" in the config \"{parentConfig}\""); } // TODO (std_string) : we must know how to process case when importName will be relative to porter directory (if 'use_porter_home_directory_while_resolving_path' option is enabled) String importConfigName = Path.IsPathRooted(importName) ? importName : Path.Combine(Path.GetDirectoryName(parentConfig) ?? String.Empty, importName); XDocument document = XDocument.Load(importConfigName); return(LoadImpl(document.Root, importConfigName)); }