public CommandLineOptions() { _options = new OptionSet { { "r|rendererName=", "the renderer name to migrate markdown", r => RendererName = r }, { "o|output=", "the output file or folder to save migrated markdown contents", o => Output = o }, { "f|file=", "the path of file that needed to be migrated", f => FilePath = f }, { "p|patterns=", "the glob pattern to find markdown files", p => Patterns.Add(p) }, { "e|excludePatterns=", "the glob pattern to exclude markdown files", e => ExcludePatterns.Add(e) }, { "c|cwd=", "the root path using for glob pattern searching", c => WorkingFolder = c } }; }
/// <summary> /// Reads the config file /// </summary> /// <returns>an empty string if no exception occurs</returns> public bool Read() { Log.Trace(@"ConfigFileHelper.Read() ..."); try { if (!ConfigFileExists) { return(false); } bool isConfigRead = true; ParityFile1 = string.Empty; ParityFile2 = string.Empty; ZParityFile = string.Empty; ParityFile3 = string.Empty; ParityFile4 = string.Empty; ParityFile5 = string.Empty; ParityFile6 = string.Empty; ConfigErrors.Clear(); ConfigWarnings.Clear(); ContentFiles.Clear(); SnapShotSources.Clear(); ExcludePatterns.Clear(); IncludePatterns.Clear(); BlockSizeKB = Constants.DefaultBlockSize; AutoSaveGB = Constants.DefaultAutoSave; foreach (string line in File.ReadLines(ConfigPath)) { string lineStart = line.Trim(); if (string.IsNullOrWhiteSpace(lineStart) || lineStart.StartsWith(@"#")) { continue; } // Not a comment so process the line // split the line by the first space encountered string[] configItem = lineStart.Split(new[] { ' ' }, 2); Log.Trace(@"configItem [{0}]", string.Join(" ", configItem)); string configItemName = configItem[0] ?? string.Empty; Log.Trace(@"configItemName [{0}]", configItemName); string configItemValue = (configItem.Length > 1) ? configItem[1] : string.Empty; Log.Trace(@"configItemValue [{0}]", configItemValue); // ignore the line if it is not an a recognized setting if (!validConfigNames.Contains(configItemName)) { continue; } Log.Trace(@"configItemName found in validConfigNames"); switch (configItemName) { case @"parity": ParityFile1 = configItemValue; break; case @"q-parity": Log.Warn(@"'q-parity' entry in config file will be changed to '2-parity' when config is saved"); ParityFile2 = configItemValue; break; case @"2-parity": // handle legacy 'q-parity' entry by giving it priority over any '2-parity' entry; saving config will rename 'q-parity' to '2-parity' and leave the path unchanged if (string.IsNullOrEmpty(ParityFile2)) { ParityFile2 = configItemValue; } break; case @"z-parity": // #WARNING! Your CPU doesn't have a fast implementation for triple parity. // #WARNING! It's recommended to switch to 'z-parity' instead than '3-parity'. ZParityFile = configItemValue; ParityFile3 = string.Empty; break; case @"3-parity": if (string.IsNullOrWhiteSpace(ZParityFile)) { ParityFile3 = configItemValue; } break; case @"4-parity": ParityFile4 = configItemValue; break; case @"5-parity": ParityFile5 = configItemValue; break; case @"6-parity": ParityFile6 = configItemValue; break; case @"content": ContentFiles.Add(configItemValue); break; case @"disk": case @"data": // Handle older configs { // get the data name, d1,d2,d3 etc string diskName = configItemValue.Split(' ')[0]; // get the path int diskSplitIndex = configItemValue.IndexOf(' '); string diskPath = configItemValue.Substring(diskSplitIndex + 1); // special handling of data sources since order preservation is extremely important if (!string.IsNullOrEmpty(diskName) && !string.IsNullOrEmpty(diskPath)) { SnapShotSources.Add(new SnapShotSource { Name = diskName, DirSource = diskPath }); } } break; case @"exclude": ExcludePatterns.Add(configItemValue); break; case @"include": IncludePatterns.Add(configItemValue); break; case @"block_size": BlockSizeKB = uint.Parse(configItemValue); if (BlockSizeKB < Constants.MinBlockSize || BlockSizeKB > Constants.MaxBlockSize) { isConfigRead = false; } break; case @"autosave": AutoSaveGB = uint.Parse(configItemValue); // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (AutoSaveGB < Constants.MinAutoSave || AutoSaveGB > Constants.MaxAutoSave) { isConfigRead = false; } break; case @"nohidden": Nohidden = true; break; } } return(isConfigRead); } catch (Exception ex) { Log.Error(ex); return(false); } }
/// <summary> /// Reads the config file /// </summary> /// <returns>an empty string if no exception occurrs</returns> public string Read() { try { ParityFile = string.Empty; QParityFile = string.Empty; ContentFiles.Clear(); SnapShotSources.Clear(); ExcludePatterns.Clear(); IncludePatterns.Clear(); BlockSizeKB = 256; AutoSaveGB = 250; foreach (string line in File.ReadLines(ConfigPath)) { string lineStart = line.TrimStart(); if (!string.IsNullOrWhiteSpace(lineStart) && !lineStart.StartsWith("#") ) { // Not a comment, so off we go. int splitIndex = lineStart.IndexOf(' '); string value = lineStart.Substring(splitIndex + 1); if (string.IsNullOrWhiteSpace(value)) { continue; } switch (lineStart.Substring(0, splitIndex).ToLower()) { case "parity": ParityFile = value; break; case "q-parity": QParityFile = value; break; case "content": ContentFiles.Add(value); break; case "disk": { // Step over the disk name int diskSplitIndex = value.IndexOf(' '); SnapShotSources.Add(value.Substring(diskSplitIndex + 1)); } break; case "exclude": ExcludePatterns.Add(value); break; case "include": IncludePatterns.Add(value); break; case "block_size": BlockSizeKB = uint.Parse(value); break; case "nohidden": Nohidden = true; break; case "autosave": AutoSaveGB = uint.Parse(value); break; } } } } catch (Exception ex) { return(ex.Message); } return(string.Empty); }
public CommandLineOptions() { _options = new OptionSet { { "r|rendererName=", "the renderer name to migrate markdown", r => RendererName = r }, { "o|output=", "the output file or folder to save migrated markdown contents", o => Output = o }, { "f|file=", "the path of file that needed to be migrated", f => FilePath = f }, { "p|patterns=", "the glob pattern to find markdown files", p => Patterns.Add(p) }, { "e|excludePatterns=", "the glob pattern to exclude markdown files", e => ExcludePatterns.Add(e) }, { "c|cwd=", "the root path using for glob pattern searching", c => WorkingFolder = c }, { "m|migration", "run migration mode", (m) => RunMode = Mode.Migration }, { "d|diff", "run diff mode", (d) => RunMode = Mode.Diff }, { "j|jsonfolders=", "difffolders, split compare json folders with comma", (j) => JsonFolders = j }, { "dbp|diffBuildPackage", "diff the build result, normally for reference repo", (dbp) => DiffBuildPackage = true }, { "rule|migrationRule=", "customize the migration rule", ParseRule }, { "rpf|reportFile=", "json report file path", (rpf) => JsonReportFile = rpf }, { "ge|generateExcelReport", "generate excel report from json report", (ge) => RunMode = Mode.GenerateExcel }, { "bp|docsetBasePath=", "git local docset basepath", (bp) => BasePath = bp }, { "repourl|reporemoteurl=", "git remote url", (grp) => GitRepoUrl = grp }, { "l|LegacyMode", "run migration in LegacyMode", (l) => UseLegacyMode = true }, { "b|branch=", "migration source branch", (branch) => Branch = branch }, { "df|docsetfolder=", "migration docset folder", (docsetfolder) => DocsetFolder = docsetfolder == "." ? string.Empty : docsetfolder }, }; }
/// <summary> /// Reads the config file /// </summary> /// <returns>an empty string if no exception occurrs</returns> public bool Read() { try { if (!ConfigFileExists) { return(false); } ParityFile1 = string.Empty; ParityFile2 = string.Empty; ParityFile3 = string.Empty; ParityFile4 = string.Empty; ParityFile5 = string.Empty; ParityFile6 = string.Empty; ContentFiles.Clear(); SnapShotSources.Clear(); ExcludePatterns.Clear(); IncludePatterns.Clear(); BlockSizeKB = 256; AutoSaveGB = 250; foreach (string line in File.ReadLines(ConfigPath)) { string lineStart = line.Trim(); if (string.IsNullOrWhiteSpace(lineStart) || lineStart.StartsWith("#")) { continue; } // Not a comment so process the line // split the line by the first space encountered string[] configItem = lineStart.Split(new[] { ' ' }, 2); string configItemName = configItem[0] ?? string.Empty; string configItemValue = (configItem.Length > 1) ? configItem[1] : string.Empty; // ignore the line if it is not an a recognized setting if (!_validConfigNames.Contains(configItemName)) { continue; } switch (configItemName) { case "parity": ParityFile1 = configItemValue; break; case "q-parity": Log.Instance.Warn("'q-parity' entry in config file should be changed to '2-parity'"); ParityFile2 = configItemValue; break; case "2-parity": // handle legacy 'q-parity' entry by giving it priority over any '2-parity' entry; saving config will rename 'q-parity' to '2-parity' and leave the path unchanged if (string.IsNullOrEmpty(ParityFile2)) { ParityFile2 = configItemValue; } break; case "3-parity": ParityFile3 = configItemValue; break; case "4-parity": ParityFile4 = configItemValue; break; case "5-parity": ParityFile5 = configItemValue; break; case "6-parity": ParityFile6 = configItemValue; break; case "content": ContentFiles.Add(configItemValue); break; case "disk": // Step over the disk name int diskSplitIndex = configItemValue.IndexOf(' '); SnapShotSources.Add(configItemValue.Substring(diskSplitIndex + 1)); break; case "exclude": ExcludePatterns.Add(configItemValue); break; case "include": IncludePatterns.Add(configItemValue); break; case "block_size": BlockSizeKB = uint.Parse(configItemValue); break; case "nohidden": Nohidden = true; break; case "autosave": AutoSaveGB = uint.Parse(configItemValue); break; } } } catch (Exception ex) { Log.Instance.Error(ex); return(false); } return(true); }