本文整理汇总了C#中CommandLineApplication.VersionOption方法的典型用法代码示例。如果您正苦于以下问题:C# CommandLineApplication.VersionOption方法的具体用法?C# CommandLineApplication.VersionOption怎么用?C# CommandLineApplication.VersionOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandLineApplication
的用法示例。
在下文中一共展示了CommandLineApplication.VersionOption方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static int Main( string[] args )
{
try
{
var app = new CommandLineApplication();
app.Name = "sgv";
app.Description = "SimpleGitVersion commands.";
app.HelpOption( "-?|-h|--help" );
app.VersionOption( "--version", GetVersion, GetInformationalVersion );
var optVerbose = app.Option( "-v|--verbose", "Verbose output", CommandOptionType.NoValue );
app.Command( "info", c =>
{
c.Description = "Display SimpleGitVersion information from Git repository.";
var optionProject = c.Option( "-p|--project <PATH>", "Path to a project, solution or any path under the solution directory, default is current directory", CommandOptionType.SingleValue );
c.HelpOption( "-?|-h|--help" );
c.OnExecute( () =>
{
ConsoleLoggerAdapter logger = new ConsoleLoggerAdapter( true );
string path = optionProject.Value() ?? Directory.GetCurrentDirectory();
SimpleRepositoryInfo info = SimpleRepositoryInfo.LoadFromPath( logger, path, ( log, hasRepoXml, options ) =>
{
options.IgnoreDirtyWorkingFolder = true;
} );
return 0;
} );
} );
app.Command( "prebuild", c =>
{
c.Description = "Creates or updates Properties/SGVVersionInfo.cs files from Git repository.";
var optionProject = c.Option( "-p|--project <PATH>", "Path to project, default is current directory", CommandOptionType.SingleValue );
c.HelpOption( "-?|-h|--help" );
c.OnExecute( () =>
{
ConsoleLoggerAdapter logger = new ConsoleLoggerAdapter( optVerbose.HasValue() );
string path = optionProject.Value() ?? Directory.GetCurrentDirectory();
var ctx = new DNXSolution( path, logger );
if( ctx.IsValid )
{
var project = ctx.FindFromPath( path );
if( project != null )
{
project.CreateOrUpdateSGVVersionInfoFile();
}
else logger.Warn( "Project not found." );
}
return 0;
} );
} );
app.Command( "update", c =>
{
c.Description = "Updates version properties in project.json files based on Git repository.";
var optionProject = c.Option( "-p|--project <PATH>", "Path to project, default is current directory", CommandOptionType.SingleValue );
c.HelpOption( "-?|-h|--help" );
c.OnExecute( () =>
{
ConsoleLoggerAdapter logger = new ConsoleLoggerAdapter( optVerbose.HasValue() );
string path = optionProject.Value() ?? Directory.GetCurrentDirectory();
var ctx = new DNXSolution( path, logger );
if( ctx.IsValid )
{
ctx.UpdateProjectFiles();
}
return 0;
} );
} );
app.Command( "restore", c =>
{
c.Description = "Restores project.json files that differ only by version properties for this solution.";
var optionProject = c.Option( "-p|--project <PATH>", "Path to project, default is current directory", CommandOptionType.SingleValue );
c.HelpOption( "-?|-h|--help" );
c.OnExecute( () =>
{
ConsoleLoggerAdapter logger = new ConsoleLoggerAdapter( optVerbose.HasValue() );
string path = optionProject.Value() ?? Directory.GetCurrentDirectory();
var ctx = new DNXSolution( path, logger );
if( ctx.IsValid )
{
ctx.RestoreProjectFilesFromGitThatDifferOnlyByVersion();
}
return 0;
} );
} );
// Show help information if no subcommand/option was specified.
app.OnExecute( () =>
{
app.ShowHelp();
return 2;
} );
return app.Execute( args );
}
//.........这里部分代码省略.........
示例2: Main
public static int Main(string[] args)
{
#if DEBUG
if (args.Contains("--debug"))
{
args = args.Skip(1).ToArray();
while (!Debugger.IsAttached)
{
}
Debugger.Break();
}
#endif
var app = new CommandLineApplication();
app.Name = "trestle";
app.FullName = "Trestle";
app.HelpOption("-h|--help");
app.VersionOption("--version", typeof(Program).GetTypeInfo().Assembly.GetName().Version.ToString());
PublishCommand.Register(app);
NormalizeCommand.Register(app);
ImportsCommand.Register(app);
UpdatePackageCommand.Register(app);
UpdateReleaseLabelCommand.Register(app);
RemovePackageCommand.Register(app);
CompilationOptionsCommand.Register(app);
app.OnExecute(() =>
{
app.ShowHelp();
return 0;
});
var exitCode = 0;
try
{
exitCode = app.Execute(args);
}
catch (CommandParsingException ex)
{
ex.Command.ShowHelp();
}
catch (Exception ex)
{
exitCode = 1;
Console.WriteLine(ex.Message);
Console.WriteLine(ex);
}
return exitCode;
}
示例3: Main
public static int Main(string[] args)
{
var app = new CommandLineApplication();
app.Name = "nuget3";
app.FullName = "NuGet Command Line";
app.HelpOption(XPlatUtility.HelpOption);
app.VersionOption("--version", typeof(Program).GetTypeInfo().Assembly.GetName().Version.ToString());
var verbosity = app.Option(XPlatUtility.VerbosityOption, "The verbosity of logging to use. Allowed values: Debug, Verbose, Information, Minimal, Warning, Error.", CommandOptionType.SingleValue);
XPlatUtility.SetConnectionLimit();
XPlatUtility.SetUserAgent();
EnsureLog(XPlatUtility.GetLogLevel(verbosity));
RestoreCommand.Register(app, Log);
app.OnExecute(() =>
{
app.ShowHelp();
return 0;
});
var exitCode = 0;
try
{
exitCode = app.Execute(args);
}
catch (Exception e)
{
EnsureLog(XPlatUtility.GetLogLevel(verbosity));
// Log the error
Log.LogError(ExceptionUtilities.DisplayMessage(e));
// Log the stack trace as verbose output.
Log.LogVerbose(e.ToString());
exitCode = 1;
}
// Limit the exit code range to 0-255 to support POSIX
if (exitCode < 0 || exitCode > 255)
{
exitCode = 1;
}
return exitCode;
}
示例4: Create
public static CommandLineApplication Create(ref string[] args)
{
EnsureValidDispatchRecipient(ref args);
var app = new CommandLineApplication()
{
// Technically, the real "dotnet-ef.dll" is in Microsoft.EntityFrameworkCore.Tools,
// but this name is what the help usage displays
Name = "dotnet ef",
FullName = "Entity Framework .NET Core CLI Commands"
};
app.HelpOption();
app.VerboseOption();
app.VersionOption(GetVersion);
var commonOptions = new CommonCommandOptions
{
// required
Assembly = app.Option(AssemblyOptionTemplate + " <ASSEMBLY>",
"The assembly file to load."),
// optional
StartupAssembly = app.Option(StartupAssemblyOptionTemplate + " <ASSEMBLY>",
"The assembly file containing the startup class."),
DataDirectory = app.Option(DataDirectoryOptionTemplate + " <DIR>",
"The folder used as the data directory (defaults to current working directory)."),
ProjectDirectory = app.Option(ProjectDirectoryOptionTemplate + " <DIR>",
"The folder used as the project directory (defaults to current working directory)."),
ContentRootPath = app.Option(ContentRootPathOptionTemplate + " <DIR>",
"The folder used as the content root path for the application (defaults to application base directory)."),
RootNamespace = app.Option(RootNamespaceOptionTemplate + " <NAMESPACE>",
"The root namespace of the target project (defaults to the project assembly name).")
};
app.Command("database", c => DatabaseCommand.Configure(c, commonOptions));
app.Command("dbcontext", c => DbContextCommand.Configure(c, commonOptions));
app.Command("migrations", c => MigrationsCommand.Configure(c, commonOptions));
app.OnExecute(
() =>
{
WriteLogo();
app.ShowHelp();
});
return app;
}
示例5: Main
public int Main(string[] args)
{
#if DEBUG
// Add our own debug helper because DNU is usually run from a wrapper script,
// making it too late to use the DNX one. Technically it's possible to use
// the DNX_OPTIONS environment variable, but that's difficult to do per-command
// on Windows
if (args.Any(a => string.Equals(a, "--debug", StringComparison.OrdinalIgnoreCase)))
{
args = args.Where(a => !string.Equals(a, "--debug", StringComparison.OrdinalIgnoreCase)).ToArray();
Console.WriteLine($"Process Id: {Process.GetCurrentProcess().Id}");
Console.WriteLine("Waiting for Debugger to attach...");
SpinWait.SpinUntil(() => Debugger.IsAttached);
}
#endif
var app = new CommandLineApplication();
app.Name = "dnu";
app.FullName = "Microsoft .NET Development Utility";
var optionVerbose = app.Option("-v|--verbose", "Show verbose output", CommandOptionType.NoValue);
app.HelpOption("-?|-h|--help");
app.VersionOption("--version", () => _runtimeEnv.GetShortVersion(), () => _runtimeEnv.GetFullVersion());
// Show help information if no subcommand/option was specified
app.OnExecute(() =>
{
app.ShowHelp();
return 2;
});
var reportsFactory = new ReportsFactory(_runtimeEnv, optionVerbose.HasValue());
BuildConsoleCommand.Register(app, reportsFactory, _hostServices);
CommandsConsoleCommand.Register(app, reportsFactory, _environment);
InstallConsoleCommand.Register(app, reportsFactory, _environment);
ListConsoleCommand.Register(app, reportsFactory, _environment);
PackConsoleCommand.Register(app, reportsFactory, _hostServices);
PackagesConsoleCommand.Register(app, reportsFactory);
PublishConsoleCommand.Register(app, reportsFactory, _environment, _hostServices);
RestoreConsoleCommand.Register(app, reportsFactory, _environment);
SourcesConsoleCommand.Register(app, reportsFactory);
WrapConsoleCommand.Register(app, reportsFactory);
FeedsConsoleCommand.Register(app, reportsFactory);
return app.Execute(args);
}
示例6: Create
public static CommandLineApplication Create()
{
var app = new CommandLineApplication()
{
Name = "dotnet ef",
FullName = "Entity Framework 6 .NET Core CLI Commands"
};
app.HelpOption();
app.VersionOption(GetVersion);
app.Command("database", c => DatabaseCommand.Configure(c));
app.Command("migrations", c => MigrationsCommand.Configure(c));
app.OnExecute(() => app.ShowHelp());
return app;
}
示例7: Main
public int Main(string[] args)
{
var app = new CommandLineApplication();
app.Name = "zippy";
app.FullName = "zippy - Distribute Your Stuff";
app.Description = "General purpose package distribution tool for your stuff (yes, all your stuff™)";
app.HelpOption("-?|-h|--help");
app.VersionOption("-v|--version", () => GetVersion());
// Show help information if no subcommand/option was specified
app.OnExecute(() =>
{
app.ShowHelp();
return 2;
});
RegisterPackCommand(app);
RegisterPushCommand(app);
RegisterInstallCommand(app);
return app.Execute(args);
}
示例8: Main
public int Main(string[] args)
{
var app = new CommandLineApplication(throwOnUnexpectedArg: true);
app.Name = "srclib-csharp";
app.FullName = "Scrlib C# toolchain";
app.HelpOption("-?|-h|--help");
app.VersionOption("--version", () => _runtimeEnv.GetShortVersion(), () => _runtimeEnv.GetFullVersion());
// Show help information if no subcommand/option was specified
app.OnExecute(() =>
{
app.ShowHelp();
return 2;
});
ScanConsoleCommand.Register(app, _env);
GraphConsoleCommand.Register(app, _env, _loadContextAccessor, _runtimeEnv);
DepresolveConsoleCommand.Register(app, _env, _runtimeEnv);
return app.Execute(args);
}
示例9: Main
public static void Main(string[] args)
{
CommandLineApplication app = new CommandLineApplication();
app.HelpOption("--help|-h|-?"); // 使其支持显示帮助信息
app.VersionOption("--version|-v", "1.0.0"); // 使其支持显示版本信息。为了简化起见,直接返回静态的 1.0.0
// 添加 argument,这里我们允许传入这个 argument 的多个值。
CommandArgument argOperator = app.Argument("operator", "算式类型,有效值:加、减、乘、除,可以设置多个类型", multipleValues: true);
// 添加多个 options,注意设置全写和简写的方式,很简单。这应该是基于约定的解析处理方式。
CommandOption optMin = app.Option("--minValue -min <value>", "最小值,默认为0", CommandOptionType.SingleValue);
CommandOption optMax = app.Option("--maxValue -max <value>", "最大值,默认为100", CommandOptionType.SingleValue);
CommandOption optCount = app.Option("--count -c <value>", "生成的算式数量,默认为10", CommandOptionType.SingleValue);
// 传入一个委托方法,当下面的 Execute 执行后会执行我们的委托方法,完成我们需要处理的工作。 委托方法需要返回一个 int,反映执行结果,一如经典的控制台程序需要的那样。
app.OnExecute(() =>
{
return OnAppExecute(argOperator, optMin, optMax, optCount);
});
// 开始执行,把控制台传入的参数直接传递给 CommandLineApplication。
app.Execute(args);
}
示例10: Main
public int Main(string[] args)
{
var app = new CommandLineApplication
{
Name = "dnx lessy",
Description = "Your patner in web building",
FullName = "Lessy - Less code more Fun"
};
app.VersionOption(
"--version",
Configuration["version"]);
app.HelpOption("-?|-h|--help");
app.Command("db:seed", c =>
{
c.Description = "Seed data to DB.";
c.HelpOption("-?|-h|--help");
c.OnExecute(() =>
{
Console.WriteLine("Seeding data");
var res = SeedLanguages.AddData(_serviceProvider);
if (res) {
Console.WriteLine("Data saved");
} else
{
Console.WriteLine("Data already exist");
}
return 0;
});
});
app.OnExecute(() =>
{
app.ShowHelp();
return 2;
});
return app.Execute(args);
}
示例11: Main
public virtual int Main([NotNull] string[] args)
{
Check.NotNull(args, nameof(args));
Console.CancelKeyPress += (_, __) => _applicationShutdown.RequestShutdown();
var app = new CommandLineApplication
{
Name = "dnx ef",
FullName = "Entity Framework Commands"
};
app.VersionOption(
"--version",
ProductInfo.GetVersion());
app.HelpOption("-?|-h|--help");
app.OnExecute(
() =>
{
ShowLogo();
app.ShowHelp();
});
app.Command(
"database",
database =>
{
database.Description = "Commands to manage your database";
database.HelpOption("-?|-h|--help");
database.OnExecute(() => database.ShowHelp());
database.Command(
"update",
update =>
{
update.Description = "Updates the database to a specified migration";
var migrationName = update.Argument(
"[migration]",
"the target migration. If '0', all migrations will be reverted. If omitted, all pending migrations will be applied");
var context = update.Option(
"-c|--context <context>",
"The DbContext to use. If omitted, the default DbContext is used");
update.HelpOption("-?|-h|--help");
update.OnExecute(() => UpdateDatabase(migrationName.Value, context.Value()));
});
});
app.Command(
"dbcontext",
dbcontext =>
{
dbcontext.Description = "Commands to manage your DbContext types";
dbcontext.HelpOption("-?|-h|--help");
dbcontext.OnExecute(() => dbcontext.ShowHelp());
dbcontext.Command(
"list",
list =>
{
list.Description = "List your DbContext types";
list.HelpOption("-?|-h|--help");
list.OnExecute(() => ListContexts());
});
dbcontext.Command(
"scaffold",
scaffold =>
{
scaffold.Description = "Scaffolds a DbContext and entity type classes for a specified database";
var connection = scaffold.Argument(
"[connection]",
"The connection string of the database");
var provider = scaffold.Argument(
"[provider]",
"The provider to use. For example, EntityFramework.SqlServer");
var dbContextClassName = scaffold.Option(
"-c|--context-class-name <name>",
"Name of the generated DbContext class.");
var outputPath = scaffold.Option(
"-o|--output-path <path>",
"Directory of the project where the classes should be output. If omitted, the top-level project directory is used.");
var tableFilters = scaffold.Option(
"-t|--tables <filter>",
"Selects for which tables to generate classes. "
+ "<filter> is a comma-separated list of schema:table entries where either schema or table can be * to indicate 'any'.");
var useFluentApiOnly = scaffold.Option(
"-u|--fluent-api",
"Exclusively use fluent API to configure the model. If omitted, the output code will use attributes, where possible, instead.");
scaffold.HelpOption("-?|-h|--help");
scaffold.OnExecute(
async () =>
{
if (string.IsNullOrEmpty(connection.Value))
{
_logger.Value.LogError("Missing required argument '{0}'", connection.Name);
scaffold.ShowHelp();
return 1;
}
if (string.IsNullOrEmpty(provider.Value))
{
_logger.Value.LogError("Missing required argument '{0}'", provider.Name);
scaffold.ShowHelp();
//.........这里部分代码省略.........
示例12: Main
static void Main(string[] args)
{
var mainModule = System.Diagnostics.Process.GetCurrentProcess().MainModule;
var app = new CommandLineApplication();
app.Name = System.IO.Path.GetFileName(mainModule.FileName);
app.FullName = "DemoApp For this CommandLineApplication";
var optionVerbose = app.Option("-v|--verbose", "Show verbose output", CommandOptionType.NoValue);
// Show help information if no subcommand/option was specified
app.OnExecute(() =>
{
if (optionVerbose.HasValue())
{
Console.WriteLine("You've specified the verbose option");
}
Console.WriteLine("Do something");
return 0;
});
app.Command("subcommand", command =>
{
command.Description = "Produce something in the subcomamnd";
var optionNames = command.Argument("[names]", "A list of files names you want to process.", multipleValues: true);
var optionOut = command.Option("--out <OUTPUT_DIR>", "Output directory", CommandOptionType.SingleValue);
command.HelpOption("-?|-h|--help");
command.OnExecute(() =>
{
if (optionOut.HasValue())
{
Console.WriteLine($"Your output directory is {optionOut.Value()}");
}
Console.WriteLine($"Your names are {string.Join(",", optionNames.Values)}");
Console.WriteLine("Do something in the sub command");
return 0;
});
});
app.HelpOption("-?|-h|--help");
app.VersionOption("--version",
() => mainModule.FileVersionInfo.ProductVersion,
() => $"File Version: {mainModule.FileVersionInfo.FileVersion}{Environment.NewLine}Product Version:{mainModule.FileVersionInfo.ProductVersion}");
app.OnException(HandleException);
app.Execute(args);
}
示例13: Main
public static int Main([NotNull] string[] args)
{
Check.NotNull(args, nameof(args));
var cancellationTokenSource = new CancellationTokenSource();
Console.CancelKeyPress += (_, __) => cancellationTokenSource.Cancel();
var app = new CommandLineApplication
{
Name = "dnx ef",
FullName = "Entity Framework Commands"
};
app.VersionOption(
"--version",
ProductInfo.GetVersion());
app.HelpOption("-?|-h|--help");
app.OnExecute(
() =>
{
ShowLogo();
app.ShowHelp();
});
app.Command(
"database",
database =>
{
database.Description = "Commands to manage your database";
database.HelpOption("-?|-h|--help");
database.OnExecute(() => database.ShowHelp());
database.Command(
"update",
update =>
{
update.Description = "Updates the database to a specified migration";
var migrationName = update.Argument(
"[migration]",
"The target migration. If '0', all migrations will be reverted. If omitted, all pending migrations will be applied");
var context = update.Option(
"-c|--context <context>",
"The DbContext to use. If omitted, the default DbContext is used");
var targetProject = update.Option(
"-p|--targetProject <project>",
"The project with the Migration classes. If omitted, the current project is used.");
var environment = update.Option(
"-e|--environment <environment>",
"The environment to use. If omitted, \"Development\" is used.");
var verbose = update.Option(
"-v|--verbose",
"Show verbose output");
update.HelpOption("-?|-h|--help");
update.OnExecute(
() =>
{
if (!ValidateProject(targetProject.Value()))
{
return 1;
}
return CreateExecutor(
targetProject.Value(),
environment.Value(),
verbose.HasValue())
.UpdateDatabase(
migrationName.Value,
context.Value());
});
});
});
app.Command(
"dbcontext",
dbcontext =>
{
dbcontext.Description = "Commands to manage your DbContext types";
dbcontext.HelpOption("-?|-h|--help");
dbcontext.OnExecute(() => dbcontext.ShowHelp());
dbcontext.Command(
"list",
list =>
{
list.Description = "List your DbContext types";
var targetProject = list.Option(
"-p|--targetProject <project>",
"The project with the DbContext classes. If omitted, the current project is used.");
var environment = list.Option(
"-e|--environment <environment>",
"The environment to use. If omitted, \"Development\" is used.");
var json = list.Option(
"--json",
"Use json output");
var verbose = list.Option(
"-v|--verbose",
"Show verbose output");
list.HelpOption("-?|-h|--help");
list.OnExecute(
() =>
{
if (!ValidateProject(targetProject.Value()))
{
return 1;
}
//.........这里部分代码省略.........
示例14: Main
public static int Main(string[] args)
{
#if DNX451
ServicePointManager.DefaultConnectionLimit = 1024;
// Work around a Mono issue that makes restore unbearably slow,
// due to some form of contention when requests are processed
// concurrently. Restoring sequentially is *much* faster in this case.
if (RuntimeEnvironmentHelper.IsMono)
{
ServicePointManager.DefaultConnectionLimit = 1;
}
#endif
#if DEBUG
// Add our own debug helper because DNU is usually run from a wrapper script,
// making it too late to use the DNX one. Technically it's possible to use
// the DNX_OPTIONS environment variable, but that's difficult to do per-command
// on Windows
if (args.Any(a => string.Equals(a, "--debug", StringComparison.OrdinalIgnoreCase)))
{
args = args.Where(a => !string.Equals(a, "--debug", StringComparison.OrdinalIgnoreCase)).ToArray();
Console.WriteLine($"Process Id: {Process.GetCurrentProcess().Id}");
Console.WriteLine("Waiting for Debugger to attach...");
SpinWait.SpinUntil(() => Debugger.IsAttached);
}
#endif
var environment = PlatformServices.Default.Application;
var runtimeEnv = PlatformServices.Default.Runtime;
var app = new CommandLineApplication();
app.Name = "dnu";
app.FullName = "Microsoft .NET Development Utility";
var optionVerbose = app.Option("-v|--verbose", "Show verbose output", CommandOptionType.NoValue);
app.HelpOption("-?|-h|--help");
app.VersionOption("--version", () => runtimeEnv.GetShortVersion(), () => runtimeEnv.GetFullVersion());
// Show help information if no subcommand/option was specified
app.OnExecute(() =>
{
app.ShowHelp();
return 2;
});
// Defer reading option verbose until AFTER execute.
var reportsFactory = new ReportsFactory(runtimeEnv, () => optionVerbose.HasValue());
BuildConsoleCommand.Register(app, reportsFactory);
CommandsConsoleCommand.Register(app, reportsFactory, environment);
InstallConsoleCommand.Register(app, reportsFactory, environment);
ListConsoleCommand.Register(app, reportsFactory, environment);
PackConsoleCommand.Register(app, reportsFactory);
PackagesConsoleCommand.Register(app, reportsFactory);
PublishConsoleCommand.Register(app, reportsFactory, environment);
RestoreConsoleCommand.Register(app, reportsFactory, environment, runtimeEnv);
WrapConsoleCommand.Register(app, reportsFactory);
FeedsConsoleCommand.Register(app, reportsFactory);
ClearCacheConsoleCommand.Register(app, reportsFactory);
try
{
return app.Execute(args);
}
catch (CommandParsingException ex)
{
AnsiConsole.GetError(useConsoleColor: runtimeEnv.OperatingSystem == "Windows").WriteLine($"Error: {ex.Message}".Red().Bold());
ex.Command.ShowHelp();
return 1;
}
#if DEBUG
catch
{
throw;
}
#else
catch (AggregateException aex)
{
foreach (var exception in aex.InnerExceptions)
{
DumpException(exception, runtimeEnv);
}
return 1;
}
catch (Exception ex)
{
DumpException(ex, runtimeEnv);
return 1;
}
#endif
}
示例15: Main
public virtual int Main([NotNull] string[] args)
{
Check.NotNull(args, nameof(args));
Console.CancelKeyPress += (sender, eventArgs) =>
{
_applicationShutdown.RequestShutdown();
};
var app = new CommandLineApplication
{
Name = "ef",
FullName = "Entity Framework Commands"
};
app.VersionOption(
"--version",
typeof(Program).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
.InformationalVersion);
app.HelpOption("-?|-h|--help");
app.OnExecute(
() =>
{
ShowLogo();
app.ShowHelp();
});
app.Command(
"database",
database =>
{
database.Description = "Commands to manage your database";
database.HelpOption("-?|-h|--help");
database.OnExecute(() => database.ShowHelp());
database.Command(
"update",
update =>
{
update.Description = "Updates the database to a specified migration";
var migrationName = update.Argument(
"[migration]",
"the target migration. If '0', all migrations will be reverted. If omitted, all pending migrations will be applied");
var context = update.Option(
"-c|--context <context>",
"The DbContext to use. If omitted, the default DbContext is used");
var startupProject = update.Option(
"-s|--startupProject <project>",
"The start-up project to use. If omitted, the current project is used");
update.HelpOption("-?|-h|--help");
update.OnExecute(() => ApplyMigration(migrationName.Value, context.Value(), startupProject.Value()));
});
});
app.Command(
"dbcontext",
dbcontext =>
{
dbcontext.Description = "Commands to manage your DbContext types";
dbcontext.HelpOption("-?|-h|--help");
dbcontext.OnExecute(() => dbcontext.ShowHelp());
dbcontext.Command(
"list",
list =>
{
list.Description = "List your DbContext types";
list.HelpOption("-?|-h|--help");
list.OnExecute(() => ListContexts());
});
dbcontext.Command(
"scaffold",
scaffold =>
{
scaffold.Description = "Scaffolds a DbContext and entity type classes for a specified database";
var connection = scaffold.Argument(
"[connection]",
"The connection string of the database");
var provider = scaffold.Argument(
"[provider]",
"The provider to use. For example, EntityFramework.SqlServer");
scaffold.HelpOption("-?|-h|--help");
scaffold.OnExecute(
async () =>
{
if (string.IsNullOrEmpty(connection.Value))
{
_logger.LogError("Missing required argument '{0}'", connection.Name);
scaffold.ShowHelp();
return 1;
}
if (string.IsNullOrEmpty(provider.Value))
{
_logger.LogError("Missing required argument '{0}'", provider.Name);
return 1;
}
await ReverseEngineerAsync(
connection.Value,
provider.Value,
_applicationShutdown.ShutdownRequested);
//.........这里部分代码省略.........