private void ShowPrompt(PvcInitContext ctx, KeyValuePair <string, PvcInitPrompt> prompt) { Console.WriteLine(prompt.Key); if (prompt.Value.Options != null) { var values = new List <string>(); foreach (var option in prompt.Value.Options.Where(x => x.Length > 0)) { if (option.Length == 2) { values.Add(option[1]); } else { values.Add(option[0]); } Console.WriteLine(" [{0}] {1}", values.Count, option[0]); } ctx.Config[prompt.Value.Field] = values[this.ReadOption(values.Count) - 1]; if (ctx.Config[prompt.Value.Field] == null) { ctx.Config[prompt.Value.Field] = ""; } } else { ctx.Config[prompt.Value.Field] = this.ReadValue(ctx.Config.ContainsKey(prompt.Value.Field) && ctx.Config[prompt.Value.Field] == null); } Console.WriteLine(); }
private void InteractWithUser(PvcInitContext ctx, IEnumerable <string> repoFiles) { foreach (var prompt in ctx.Prompts) { this.ShowPrompt(ctx, prompt); // handle 'choose' if (!string.IsNullOrEmpty(prompt.Value.Choose)) { var chooseDirs = repoFiles.Where(x => Path.GetFileName(x).StartsWith(prompt.Value.Choose)).GroupBy(y => Path.GetDirectoryName(y)); var removedFiles = new List <string>(); foreach (var chooseDir in chooseDirs) { if (chooseDir.Count() > 1) { if (string.IsNullOrEmpty(ctx.Config[prompt.Value.Field])) { chooseDir.ToList().ForEach(x => File.Delete(x)); } else { var matchFiles = chooseDir.Where(x => x.EndsWith(ctx.Config[prompt.Value.Field])); chooseDir.Except(matchFiles).ToList().ForEach(x => File.Delete(x)); var matchFile = matchFiles.First(); var newFileDest = Path.Combine(Path.GetDirectoryName(matchFile), prompt.Value.Choose); File.Move(matchFile, newFileDest); removedFiles.Add(matchFile); } } } repoFiles = repoFiles.Except(removedFiles); } } }
private void ShowPrompt(PvcInitContext ctx, KeyValuePair<string, PvcInitPrompt> prompt) { Console.WriteLine(prompt.Key); if (prompt.Value.Options != null) { var values = new List<string>(); foreach (var option in prompt.Value.Options.Where(x => x.Length > 0)) { if (option.Length == 2) values.Add(option[1]); else values.Add(option[0]); Console.WriteLine(" [{0}] {1}", values.Count, option[0]); } ctx.Config[prompt.Value.Field] = values[this.ReadOption(values.Count) - 1]; if (ctx.Config[prompt.Value.Field] == null) ctx.Config[prompt.Value.Field] = ""; } else { ctx.Config[prompt.Value.Field] = this.ReadValue(ctx.Config.ContainsKey(prompt.Value.Field) && ctx.Config[prompt.Value.Field] == null); } Console.WriteLine(); }
private void InteractWithUser(PvcInitContext ctx, IEnumerable<string> repoFiles) { foreach (var prompt in ctx.Prompts) { this.ShowPrompt(ctx, prompt); // handle 'choose' if (!string.IsNullOrEmpty(prompt.Value.Choose)) { var chooseDirs = repoFiles.Where(x => Path.GetFileName(x).StartsWith(prompt.Value.Choose)).GroupBy(y => Path.GetDirectoryName(y)); var removedFiles = new List<string>(); foreach (var chooseDir in chooseDirs) { if (chooseDir.Count() > 1) { if (string.IsNullOrEmpty(ctx.Config[prompt.Value.Field])) { chooseDir.ToList().ForEach(x => File.Delete(x)); } else { var matchFiles = chooseDir.Where(x => x.EndsWith(ctx.Config[prompt.Value.Field])); chooseDir.Except(matchFiles).ToList().ForEach(x => File.Delete(x)); var matchFile = matchFiles.First(); var newFileDest = Path.Combine(Path.GetDirectoryName(matchFile), prompt.Value.Choose); File.Move(matchFile, newFileDest); removedFiles.Add(matchFile); } } } repoFiles = repoFiles.Except(removedFiles); } } }