/// <summary> /// Gets the conventional base-path value. /// </summary> /// <param name="args">The arguments.</param> /// <returns></returns> /// <exception cref="ArgumentException"></exception> public static string GetBasePathValue(this ProgramArgs args) { var isBasePathRequired = args.HasArg(ProgramArgs.BasePathRequired, requiresValue: false); if (!args.HasArg(ProgramArgs.BasePath, isBasePathRequired)) { return(null); } var basePath = args.GetArgValue(ProgramArgs.BasePath); if (!Directory.Exists(basePath)) { throw new ArgumentException($"{basePath} does not exist."); } return(basePath); }
/// <summary> /// Gets the conventional settings file path. /// </summary> /// <param name="args">The arguments.</param> /// <returns></returns> public static string GetSettingsFilePath(this ProgramArgs args) { if (!args.HasArg(ProgramArgs.SettingsFile, requiresValue: false)) { return(null); } var settingsFileName = args.GetArgValue(ProgramArgs.SettingsFile); return(settingsFileName); }
public static IConfigurationBuilder WithSettingsJsonFile(this IConfigurationBuilder builder, string basePath, string settingsFileName) { if (builder == null) { return(null); } var args = new ProgramArgs(Environment.GetCommandLineArgs()); if (string.IsNullOrEmpty(settingsFileName)) { settingsFileName = defaultSettingsFileName; } var isBasePathRequired = args.HasArg(ProgramArgs.BasePathRequired, requiresValue: false); if (args.HasArg(ProgramArgs.BasePath, isBasePathRequired)) { basePath = args.GetArgValue(ProgramArgs.BasePath); if (!Directory.Exists(basePath)) { throw new ArgumentException($"{basePath} does not exist."); } builder.SetBasePath(basePath); if (args.HasArg(ProgramArgs.SettingsFile, requiresValue: false)) { settingsFileName = args.GetArgValue(ProgramArgs.SettingsFile); builder.AddJsonFile(settingsFileName, optional: true, reloadOnChange: true); } } else if (!string.IsNullOrEmpty(basePath)) { if (!Directory.Exists(basePath)) { throw new ArgumentException($"{basePath} does not exist."); } builder.SetBasePath(basePath); builder.AddJsonFile(settingsFileName, optional: true, reloadOnChange: true); } return(builder); }
/// <summary> /// Converts <see cref="FeedsMetadata"/> to root directory. /// </summary> /// <param name="meta">The meta.</param> /// <param name="args">The arguments.</param> /// <returns></returns> /// <exception cref="DirectoryNotFoundException">The expected root directory is not here.</exception> public static string ToRootDirectory(this FeedsMetadata meta, ProgramArgs args) { var basePath = args.HasArg(ProgramArgs.BasePath, requiresValue: false) ? args.GetBasePathValue() : Directory.GetCurrentDirectory(); var rootDirectory = meta.FeedsDirectory.StartsWith("./") ? ProgramFileUtility.GetCombinedPath(basePath, meta.FeedsDirectory) : meta.FeedsDirectory; rootDirectory = Path.GetFullPath(rootDirectory); if (!Directory.Exists(rootDirectory)) { Directory.CreateDirectory(rootDirectory); } return(rootDirectory); }
public void Start(ProgramArgs args) { var basePath = args.HasArg(ProgramArgs.BasePath, requiresValue: false) ? args.GetBasePathValue() : Directory.GetCurrentDirectory(); this.SetMetadata(); this.SetDataRoot(basePath); var container = this.GetContainerReference(); var appJson = this.DownloadAppFile(container); var jO = JObject.Parse(appJson); this.WriteServerMeta(jO); this.DownloadFeedFiles(container); this.WriteFeedFiles(jO); this.WriteAppFile(jO); this.UploadAppFile(container); }
/// <summary> /// Determines whether args contain the <see cref="ProgramArgs.Help"/> flag. /// </summary> /// <param name="args">The arguments.</param> public static bool IsHelpRequest(this ProgramArgs args) { return(args.HasArg(ProgramArgs.Help, requiresValue: false)); }