public void VerifyHelpOutput() { var definition = Configuration.Configure<HelpModelTest>(); var help = new Help.HelpProvider().GenerateModelHelp(definition); var f = new ConsoleHelpFormatter(80, 1, 5); f.GetHelp(help).Should().Be.EqualTo(Properties.Resources.HelpOutput); }
private static void ShowHelp(IModelBindingDefinition<CmdLine> definition) { var help = new HelpProvider().GenerateModelHelp(definition); var helpFormatter = new ConsoleHelpFormatter(System.Console.WindowWidth, 1, 5); help.HelpText = Assembly.GetExecutingAssembly().FullName + Environment.NewLine; var helpString = helpFormatter.GetHelp(help); System.Console.Error.WriteLine(helpString); }
public static void WriteHelp(Type modelType, TextWriter writer) { var definition = CreateDefinitionForType(modelType); var helpProvider = new HelpProvider(); var generateHelpMethod = typeof (HelpProvider).GetMethod("GenerateModelHelp").MakeGenericMethod(modelType); var modelHelp = (ModelHelp) generateHelpMethod.Invoke(helpProvider, new[] {definition}); var formatter = new ConsoleHelpFormatter(80, 1, 5); formatter.WriteHelp(modelHelp, writer); }
public void VerifyEmptyModelTestDoesNotBreak() { var definition = Configuration.Configure<EmptyHelpModelTest>(); var help = new Help.HelpProvider().GenerateModelHelp(definition); var f = new ConsoleHelpFormatter(80, 1, 5); f.GetHelp(help).Should().Be.EqualTo("<command> \r\n\r\n\r\n"); }
public static void Main(string[] args) { AppLaunchingCommandLine commandLine; IModelBindingDefinition<AppLaunchingCommandLine> modelBindingDefinition = null; try { modelBindingDefinition = Configuration.Configure<AppLaunchingCommandLine>(); commandLine = modelBindingDefinition.CreateAndBind(args); /* if (commandLine.ProductId == Guid.Empty) { Console.WriteLine(""); Console.WriteLine("***Warning*** - no productId supplied"); Console.WriteLine(""); } */ } catch (Exception /*exception*/) { if (modelBindingDefinition != null) { var help = new HelpProvider(); var formatter = new ConsoleHelpFormatter(); var sw = new StringWriter(); var text = help.GenerateModelHelp(modelBindingDefinition); formatter.WriteHelp(text, sw); Console.Write(sw.ToString()); } else { Console.Write("Sorry - no help available!"); } return; } try { Console.WriteLine("AutomationHost starting"); using (var program = new Program(commandLine)) { Console.WriteLine("To show help, enter 'help'"); program.Run(); } } catch (QuitNowPleaseException) { Console.WriteLine("Goodbye"); } catch (Exception exception) { Console.WriteLine(string.Format("Exception seen {0} {1}", exception.GetType().FullName, exception.Message)); } }
static int Main(string[] args) { GitReleaseNotesEnvironment.Log = new ConsoleLog(); var modelBindingDefinition = Configuration.Configure<GitReleaseNotesArguments>(); if (args.Any(a => a == "/?" || a == "?" || a.Equals("/help", StringComparison.InvariantCultureIgnoreCase))) { var help = new HelpProvider().GenerateModelHelp(modelBindingDefinition); var f = new ConsoleHelpFormatter(); f.WriteHelp(help, Console.Out); return 0; } var exitCode = 0; var arguments = modelBindingDefinition.CreateAndBind(args); // TODO: Convert to context verification (we need the context to be valid, not the arguments) if (!ArgumentVerifier.VerifyArguments(arguments)) { return 1; } var context = arguments.ToContext(); try { var releaseNotesGenerator = new ReleaseNotesGenerator(context, new FileSystem.FileSystem()); releaseNotesGenerator.GenerateReleaseNotes(); Log.WriteLine("Done"); } catch (GitReleaseNotesException ex) { exitCode = -1; Log.WriteLine("An expected error occurred: {0}", ex.Message); } catch (Exception ex) { exitCode = -2; Log.WriteLine("An unexpected error occurred: {0}", ex.Message); } if (Debugger.IsAttached) { Console.WriteLine("Press any key to continue"); Console.ReadKey(); } return exitCode; }
static void Main(string[] args) { var modelBindingDefinition = Args.Configuration.Configure<RunnerCommands>(); var command = modelBindingDefinition.CreateAndBind(args); var helpProvider = new HelpProvider(); var generateModelHelp = helpProvider.GenerateModelHelp(modelBindingDefinition); var formatter = new ConsoleHelpFormatter(); formatter.WriteHelp(generateModelHelp, Console.Out); Console.WriteLine(); //Console.WriteLine("RunProblem: {0}", command.RunProblem.HasValue ? command.RunProblem.Value.ToString() : "No value" ); //Console.WriteLine("Page: {0}", command.Page.HasValue ? command.Page.Value.ToString() : "No value"); }
public void NoArgumentsShouldOutputHelp() { using (var programWriter = new StringWriter()) { Console.SetOut(programWriter); Program.Main(new string[0]); var modelBindingDefinition = Configuration.Configure<GitReleaseNotesArguments>(); var help = new HelpProvider().GenerateModelHelp(modelBindingDefinition); var f = new ConsoleHelpFormatter(80, 1, 5); using (var helpWriter = new StringWriter()) { f.WriteHelp(help, helpWriter); programWriter.ToString().ShouldContain(helpWriter.ToString()); } } }
private static void ShowHelp(IModelBindingDefinition<GitReleaseNotesArguments> modelBindingDefinition, string reason = null) { var help = new HelpProvider().GenerateModelHelp(modelBindingDefinition); var f = new ConsoleHelpFormatter(); f.WriteHelp(help, Console.Out); if (reason != null) { Console.WriteLine(); Console.WriteLine(reason); } }
/// <summary> /// Parses the command line arguments into /// </summary> /// <param name="args">Array of command line arguments.</param> /// <returns>A set of options.</returns> private static Options ParseArguments(string[] args) { var optionModel = Args.Configuration.Configure<Options>(); var options = optionModel.CreateAndBind(args); if (options.Help) { var help = new Args.Help.HelpProvider().GenerateModelHelp(optionModel); var formatter = new ConsoleHelpFormatter(); Console.WriteLine(formatter.GetHelp(help)); } return options; }
static int Main(string[] args) { var modelBindingDefinition = Args.Configuration.Configure<GitReleaseNotesArguments>(); if (args.Any(a => a == "/?")) { var help = new HelpProvider().GenerateModelHelp(modelBindingDefinition); var f = new ConsoleHelpFormatter(); f.WriteHelp(help, Console.Out); return 0; } var arguments = modelBindingDefinition.CreateAndBind(args); if (arguments.IssueTracker == null) { Console.WriteLine("The IssueTracker argument must be provided, see help (/?) for possible options"); return 1; } if (string.IsNullOrEmpty(arguments.OutputFile) || !arguments.OutputFile.EndsWith(".md")) { Console.WriteLine("Specify an output file (*.md)"); return 1; } CreateIssueTrackers(arguments); var issueTracker = IssueTrackers[arguments.IssueTracker.Value]; if (!issueTracker.VerifyArgumentsAndWriteErrorsToConsole(arguments)) return 1; var workingDirectory = arguments.WorkingDirectory ?? Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var gitDirectory = GitDirFinder.TreeWalkForGitDir(workingDirectory); if (string.IsNullOrEmpty(gitDirectory)) { throw new Exception("Failed to find .git directory."); } Console.WriteLine("Git directory found at {0}", gitDirectory); var repositoryRoot = Directory.GetParent(gitDirectory).FullName; var gitHelper = new GitHelper(); var gitRepo = new Repository(gitDirectory); var taggedCommitFinder = new TaggedCommitFinder(gitRepo, gitHelper); var tagToStartFrom = string.IsNullOrEmpty(arguments.FromTag) ? taggedCommitFinder.GetLastTaggedCommit() : taggedCommitFinder.GetTag(arguments.FromTag); var commitsToScan = gitRepo.Commits.TakeWhile(c => c != tagToStartFrom.Commit).ToArray(); if (arguments.Verbose) { Console.WriteLine("Scanning the following commits for issue numbers"); foreach (var commit in commitsToScan) { Console.WriteLine(commit.Message); } } var releaseNotes = issueTracker.ScanCommitMessagesForReleaseNotes(arguments, commitsToScan); new ReleaseNotesWriter(new FileSystem(), repositoryRoot).WriteReleaseNotes(arguments, releaseNotes); return 0; }
private static void ShowHelp(IModelBindingDefinition<Options> argsConfig) { var helpProvider = new HelpProvider(); var help = helpProvider.GenerateModelHelp(argsConfig); var helpFormatter = new ConsoleHelpFormatter(); Console.WriteLine(helpFormatter.GetHelp(help)); Console.ReadKey(); }
/// <summary> /// The main. /// </summary> /// <param name="args"> /// The args. /// </param> private static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine(new string('*', 60)); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Exclude Me! Copy - Copyright 2013 Jaben Cargman"); Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine(new string('*', 60)); Console.ResetColor(); try { var definition = Configuration.Configure<CopyArguments>(); CopyArguments copy = null; try { copy = definition.CreateAndBind(args); } catch { var help = new HelpProvider().GenerateModelHelp(definition); var f = new ConsoleHelpFormatter(80, 1, 5); f.WriteHelp(help, Console.Error); return; } var excludeLike = new HashSet<string>(); if (copy.IgnoreFile.IsSet()) { Console.WriteLine(@" - Loading Ignore File ""{0}""...", copy.IgnoreFile); foreach (var line in File.ReadAllLines(copy.IgnoreFile).Where(x => x.IsSet())) { excludeLike.Add(line); } } if (copy.Exclusions != null) { foreach (var line in copy.Exclusions.Where(x => x.IsSet())) { excludeLike.Add(line); } } if (!Path.IsPathRooted(copy.SourceDirectory)) { copy.SourceDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, copy.SourceDirectory)); } if (!Path.IsPathRooted(copy.DestinationDirectory)) { copy.DestinationDirectory = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, copy.DestinationDirectory)); } Console.WriteLine(@" - Source Directory is ""{0}""", copy.SourceDirectory); Console.WriteLine(@" - Destination Directory is ""{0}""", copy.DestinationDirectory); Console.WriteLine(@" - Directory Recursion is {0}", copy.Recurse ? "ON" : "OFF"); if (!Directory.Exists(copy.SourceDirectory)) { Console.Beep(); Console.Error.WriteLine(@" ! Failure: Source directory ""{0}"" does not exist!", copy.SourceDirectory); Console.WriteLine(); return; } Console.WriteLine(); bool isCancelled = false; Console.CancelKeyPress += (sender, eventArgs) => { isCancelled = true; }; var cancelSource = new CancellationTokenSource(); var cancellationToken = cancelSource.Token; Task<int> copyTask = Task.Factory.StartNew(() => CopyStructure(copy, excludeLike.ToList(), token: cancellationToken), cancellationToken); while (!(copyTask.IsCompleted || copyTask.IsCanceled || copyTask.IsFaulted)) { if (isCancelled) { Console.WriteLine(" * Control-C Pressed. Cancelling!"); cancelSource.Cancel(); } Thread.Sleep(50); } if (copyTask.Result > 0) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(); Console.WriteLine(@" * {0} File(s) Copied!", copyTask.Result); } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("!! Exception: " + ex); } finally { Console.ResetColor(); } Console.WriteLine(); Console.ForegroundColor = ConsoleColor.DarkCyan; Console.WriteLine(new string('*', 60)); Console.ResetColor(); }
private static void ShowHelp(IModelBindingDefinition<ConversionOrder> argsDefinition) { var help = new Args.Help.HelpProvider().GenerateModelHelp(argsDefinition); var f = new ConsoleHelpFormatter(80, 1, 5); Console.WriteLine(f.GetHelp(help)); }
private static void ShowHelp(IModelBindingDefinition<GitReleaseNotesArguments> modelBindingDefinition, string reason = null) { var help = new HelpProvider().GenerateModelHelp(modelBindingDefinition); var bufferWidth = Console.IsOutputRedirected ? 80 : Console.BufferWidth; var f = new ConsoleHelpFormatter(bufferWidth, 1, 5); f.WriteHelp(help, Console.Out); if (reason != null) { Console.WriteLine(); Console.WriteLine(reason); } }
public static void WriteHelp() { var help = new HelpProvider().GenerateModelHelp(Configuration.Configure<Arguments>()); var f = new ConsoleHelpFormatter(Console.BufferWidth, 1, 5); Console.WriteLine(f.GetHelp(help)); }
private static int GenerateReleaseNotes(string[] args) { var modelBindingDefinition = Args.Configuration.Configure<GitReleaseNotesArguments>(); if (args.Any(a => a == "/?" || a == "?" || a.Equals("/help", StringComparison.InvariantCultureIgnoreCase))) { var help = new HelpProvider().GenerateModelHelp(modelBindingDefinition); var f = new ConsoleHelpFormatter(); f.WriteHelp(help, Console.Out); return 0; } var arguments = modelBindingDefinition.CreateAndBind(args); if (!ArgumentVerifier.VerifyArguments(arguments)) { return 1; } var workingDirectory = arguments.WorkingDirectory ?? Directory.GetCurrentDirectory(); var gitDirectory = GitDirFinder.TreeWalkForGitDir(workingDirectory); if (string.IsNullOrEmpty(gitDirectory)) { throw new Exception("Failed to find .git directory."); } Console.WriteLine("Git directory found at {0}", gitDirectory); var repositoryRoot = Directory.GetParent(gitDirectory).FullName; var gitRepo = new Repository(gitDirectory); CreateIssueTrackers(gitRepo, arguments); IIssueTracker issueTracker = null; if (arguments.IssueTracker == null) { var firstOrDefault = _issueTrackers.FirstOrDefault(i => i.Value.RemotePresentWhichMatches); if (firstOrDefault.Value != null) issueTracker = firstOrDefault.Value; } if (issueTracker == null) { if (!_issueTrackers.ContainsKey(arguments.IssueTracker.Value)) throw new Exception(string.Format("{0} is not a known issue tracker", arguments.IssueTracker.Value)); issueTracker = _issueTrackers[arguments.IssueTracker.Value]; } if (!issueTracker.VerifyArgumentsAndWriteErrorsToConsole()) { return 1; } var fileSystem = new FileSystem.FileSystem(); var releaseFileWriter = new ReleaseFileWriter(fileSystem); string outputFile = null; var previousReleaseNotes = new SemanticReleaseNotes(); if (!string.IsNullOrEmpty(arguments.OutputFile)) { outputFile = Path.IsPathRooted(arguments.OutputFile) ? arguments.OutputFile : Path.Combine(repositoryRoot, arguments.OutputFile); previousReleaseNotes = new ReleaseNotesFileReader(fileSystem, repositoryRoot).ReadPreviousReleaseNotes(outputFile); } var categories = arguments.Categories == null ? Categories : Categories.Concat(arguments.Categories.Split(',')).ToArray(); TaggedCommit tagToStartFrom = arguments.AllTags ? GitRepositoryInfoFinder.GetFirstCommit(gitRepo) : GitRepositoryInfoFinder.GetLastTaggedCommit(gitRepo) ?? GitRepositoryInfoFinder.GetFirstCommit(gitRepo); var currentReleaseInfo = GitRepositoryInfoFinder.GetCurrentReleaseInfo(gitRepo); if (!string.IsNullOrEmpty(arguments.Version)) { currentReleaseInfo.Name = arguments.Version; currentReleaseInfo.When = DateTimeOffset.Now; } var releaseNotes = ReleaseNotesGenerator.GenerateReleaseNotes( gitRepo, issueTracker, previousReleaseNotes, categories, tagToStartFrom, currentReleaseInfo, issueTracker.DiffUrlFormat); var releaseNotesOutput = releaseNotes.ToString(); releaseFileWriter.OutputReleaseNotesFile(releaseNotesOutput, outputFile); PublishReleaseIfNeeded(releaseNotesOutput, arguments, issueTracker); return 0; }
private static void OutputHelp(IModelBindingDefinition<ProgramOptions> configuration) { var help = new HelpProvider(); var helpProvider = help.GenerateModelHelp(configuration); var consoleFormatter = new ConsoleHelpFormatter(80, 1, 5); Console.WriteLine(consoleFormatter.GetHelp(helpProvider)); }