public static CommandLineBuilder UseTimer(this CommandLineBuilder commandLineBuilder) { commandLineBuilder.AddOption(new Option(new[] { "--timer", "-T" }, "Enable the timer, and display how much time was taken") { Argument = new Argument <bool>("timer", () => false) }); commandLineBuilder.UseMiddleware(async(context, next) => { CommandResult rootCommandResult = context.ParseResult.RootCommandResult; bool timer = rootCommandResult.ValueForOption <bool>("-T"); if (timer) { Stopwatch stopWatch = Stopwatch.StartNew(); AppDomain.CurrentDomain.ProcessExit += (s, e) => { Console.WriteLine("Finished running after: {0}", stopWatch.Elapsed); }; } await next(context); }, MiddlewareOrder.Configuration); return(commandLineBuilder); }
public static CommandLineBuilder UseLicense(this CommandLineBuilder commandLineBuilder) { commandLineBuilder.AddOption(new Option(new[] { "--license", "-L" }, "Show the license of the software") { Argument = new Argument <bool>("license", () => false) }); commandLineBuilder.UseMiddleware(async(context, next) => { Logger.Trace("Executing License Middleware."); CommandResult rootCommandResult = context.ParseResult.RootCommandResult; bool license = rootCommandResult.ValueForOption <bool>("-L"); if (license) { Logger.Info(License); } else { await next(context); } }, MiddlewareOrder.Configuration); return(commandLineBuilder); }
public static CommandLineBuilder UseImageCaster(this CommandLineBuilder commandLineBuilder) { commandLineBuilder.AddOption(new Option(new[] { "--config", "-c" }, "Define the configration in part or in whole through arguments") { Argument = new Argument <string>("config") }); commandLineBuilder.AddOption(new Option(new[] { "--file", "-f" }, "Change where ImageCaster should find the configuration file") { Argument = new Argument <FileInfo>("file", () => new FileInfo("imagecaster.yml")).ExistingOnly() }); commandLineBuilder.AddOption(new Option(new[] { "--input", "-i" }, "Change where ImageCaster should look for files") { Argument = new Argument <DirectoryInfo>("input", () => new DirectoryInfo(Directory.GetCurrentDirectory())).ExistingOnly() }); commandLineBuilder.AddOption(new Option(new[] { "--output", "-o" }, "Change where ImageCaster should output created files") { Argument = new Argument <DirectoryInfo>("output", () => new DirectoryInfo(Directory.GetCurrentDirectory())) }); commandLineBuilder.UseMiddleware(async(context, next) => { CommandResult rootCommandResult = context.ParseResult.RootCommandResult; try { FileInfo file = rootCommandResult.ValueForOption <FileInfo>("-f"); Logger.Debug("Executed ImageCaster using configuration file at: {0}", file.FullName); if (!file.Exists) { throw new InvalidOperationException("The configuration path specified at -f points to a location that doesn't exist."); } await next(context); } catch (InvalidOperationException ex) { Logger.Fatal(ex.Message); Environment.Exit((int)ExitCode.NoConfig); } }); return(commandLineBuilder); }
public static CommandLineBuilder UseLogger(this CommandLineBuilder commandLineBuilder) { commandLineBuilder.AddOption(new Option(new[] { "--level", "-l" }, "The minimum logging level use during runtime") { Argument = new Argument <string>("level", () => "Info") }); commandLineBuilder.AddOption(new Option(new[] { "--timestamp", "-t" }, "Include the timestamp when logging") { Argument = new Argument <bool>("timestamp", () => false) }); commandLineBuilder.UseMiddleware(async(context, next) => { CommandResult rootCommandResult = context.ParseResult.RootCommandResult; try { string level = rootCommandResult.ValueForOption <string>("-l"); if (LogLevel.AllLevels.All(lvl => lvl.Name != level)) { Logger.Fatal("An invalid log level was passed to -l ({0}).", level ?? "null"); Environment.Exit((int)ExitCode.InvalidLogLevel); } LogManager.Configuration.Variables["level"] = level; bool timestamp = rootCommandResult.ValueForOption <bool>("-t"); if (timestamp) { LogManager.Configuration.Variables["layout"] = @"[${level:uppercase=true:padding=-5}] [${date:universalTime:true:format=MM/dd HH\:mm\:ss}]"; } await next(context); } catch (InvalidOperationException ex) { Logger.Fatal(ex.Message); Environment.Exit((int)ExitCode.InvalidLogLevel); } }, MiddlewareOrder.Configuration); return(commandLineBuilder); }
public static CommandLineBuilder AddCustomOptions(this CommandLineBuilder builder) { builder.AddOption <bool>( "Enables parallel package creation.", "--parallel"); builder.AddOption <string>( "Set filename for generating project dependency graph.", "--output-graph"); builder.AddOption <bool>( "Warn when possible package downgrade detected.", "--warn-downgrade"); builder.AddOption <bool>( "Terminate tool execution when package downgrade detected.", "--disallow-downgrade"); return(builder); }
/// <summary> /// https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-pack#arguments /// </summary> public static CommandLineBuilder AddDotnetPackOptions(this CommandLineBuilder builder) { builder.AddOption <string>( "Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project.", "--configuration", "-c"); builder.AddOption <bool>( "Forces all dependencies to be resolved even if the last restore was successful. Specifying this flag is the same as deleting the project.assets.json file.", "--force"); builder.AddOption <bool>( "Includes the debug symbols NuGet packages in addition to the regular NuGet packages in the output directory. The sources files are included in the src folder within the symbols package.", "--include-source"); builder.AddOption <bool>( "Includes the debug symbols NuGet packages in addition to the regular NuGet packages in the output directory.", "--include-symbols"); builder.AddOption <bool>( "Allows the command to stop and wait for user input or action (for example, to complete authentication).", "--interactive"); builder.AddOption <bool>( "Doesn't build the project before packing. It also implicitly sets the --no-restore flag.", "--no-build"); builder.AddOption <bool>( "Doesn't execute an implicit restore when running the command.", "--no-restore"); builder.AddOption <bool>( "Doesn't display the startup banner or the copyright message.", "--nologo"); builder.AddOption <string>( "Places the built packages in the directory specified.", "--output", "-o"); builder.AddOption <string>( "Specifies the target runtime to restore packages for.", "--runtime"); builder.AddOption <bool>( "Sets the serviceable flag in the package.", "--serviceable", "-s"); builder.AddOption <string>( "Defines the value for the $(VersionSuffix) MSBuild property in the project.", "--version-suffix"); builder.AddOption <string>( "Sets the verbosity level of the command. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].", "--verbosity", "-v"); return(builder); }