本文整理汇总了C#中CommandLineApplication.ShowHelp方法的典型用法代码示例。如果您正苦于以下问题:C# CommandLineApplication.ShowHelp方法的具体用法?C# CommandLineApplication.ShowHelp怎么用?C# CommandLineApplication.ShowHelp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandLineApplication
的用法示例。
在下文中一共展示了CommandLineApplication.ShowHelp方法的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 int Main(string[] args)
{
try
{
var description = "Creates table and indexes in Microsoft SQL Server database " +
"to be used for distributed caching";
var app = new CommandLineApplication();
app.Name = "sqlservercache";
app.Description = description;
app.HelpOption("-?|-h|--help");
app.Command("create", command =>
{
command.Description = description;
var connectionStringArg = command.Argument(
"[connectionString]",
"The connection string to connect to the database.");
var schemaNameArg = command.Argument("[schemaName]", "Name of the table schema.");
var tableNameArg = command.Argument("[tableName]", "Name of the table to be created.");
command.HelpOption("-?|-h|--help");
command.OnExecute(() =>
{
if (string.IsNullOrEmpty(connectionStringArg.Value)
|| string.IsNullOrEmpty(schemaNameArg.Value)
|| string.IsNullOrEmpty(tableNameArg.Value))
{
_logger.LogWarning("Invalid input");
app.ShowHelp();
return 2;
}
_connectionString = connectionStringArg.Value;
_schemaName = schemaNameArg.Value;
_tableName = tableNameArg.Value;
CreateTableAndIndexes();
return 0;
});
});
// Show help information if no subcommand/option was specified.
app.OnExecute(() =>
{
app.ShowHelp();
return 2;
});
return app.Execute(args);
}
catch (Exception exception)
{
_logger.LogCritical("An error occurred. {Message}", exception.Message);
return 1;
}
}
示例3: Main
static void Main(string[] args)
{
CommandLineApplication commandLineApplication = new CommandLineApplication(throwOnUnexpectedArg: false);
CommandArgument directory = commandLineApplication.Argument("directory", "The directory to search for assemblies");
CommandOption dgmlExport = commandLineApplication.Option("-dg|--dgml <filename>", "Export to a dgml file", CommandOptionType.SingleValue);
CommandOption nonsystem = commandLineApplication.Option("-n|--nonsystem", "List system assemblies", CommandOptionType.NoValue);
CommandOption all = commandLineApplication.Option("-a|--all", "List all assemblies and references.", CommandOptionType.NoValue);
CommandOption noconsole = commandLineApplication.Option("-nc|--noconsole", "Do not show references on console.", CommandOptionType.NoValue);
CommandOption silent = commandLineApplication.Option("-s|--silent", "Do not show any message, only warnings and errors will be shown.", CommandOptionType.NoValue);
commandLineApplication.HelpOption("-? | -h | --help");
commandLineApplication.OnExecute(() =>
{
var consoleLogger = new ConsoleLogger(!silent.HasValue());
var directoryPath = directory.Value;
if (!Directory.Exists(directoryPath))
{
consoleLogger.LogMessage(string.Format("Directory: '{0}' does not exist.", directoryPath));
return -1;
}
var onlyConflicts = !all.HasValue();
var skipSystem = nonsystem.HasValue();
IDependencyAnalyzer analyzer = new DependencyAnalyzer() { DirectoryInfo = new DirectoryInfo(directoryPath) };
consoleLogger.LogMessage(string.Format("Check assemblies in: {0}", analyzer.DirectoryInfo));
var result = analyzer.Analyze(consoleLogger);
if (!noconsole.HasValue())
{
IDependencyVisualizer visualizer = new ConsoleVisualizer(result) { SkipSystem = skipSystem, OnlyConflicts = onlyConflicts };
visualizer.Visualize();
}
if (dgmlExport.HasValue())
{
IDependencyVisualizer export = new DgmlExport(result, string.IsNullOrWhiteSpace(dgmlExport.Value()) ? Path.Combine(analyzer.DirectoryInfo.FullName, "references.dgml") : dgmlExport.Value(), consoleLogger);
export.Visualize();
}
return 0;
});
try
{
if (args == null || args.Length == 0)
commandLineApplication.ShowHelp();
else
commandLineApplication.Execute(args);
}
catch (CommandParsingException cpe)
{
Console.WriteLine(cpe.Message);
commandLineApplication.ShowHelp();
}
}
示例4: Main
public int Main(string[] args)
{
try
{
var app = new CommandLineApplication
{
Name = "razor-tooling",
FullName = "Microsoft Razor Tooling Utility",
Description = "Resolves Razor tooling specific information.",
ShortVersionGetter = GetInformationalVersion,
};
app.HelpOption("-?|-h|--help");
ResolveProtocolCommand.Register(app);
ResolveTagHelpersCommand.Register(app, _assemblyLoadContext);
app.OnExecute(() =>
{
app.ShowHelp();
return 2;
});
return app.Execute(args);
}
catch (Exception ex)
{
Console.WriteLine($"Error: {Environment.NewLine}{ex.Message}.");
return 1;
}
}
示例5: Main
public static int Main(string[] args)
{
var app = new CommandLineApplication();
app.Name = "dotnet";
app.Description = "The .NET CLI";
// Most commonly used commands
app.Command("init", c =>
{
c.Description = "Scaffold a basic .NET application";
c.OnExecute(() => Exec("dotnet-init", c.RemainingArguments));
});
app.Command("compile", c =>
{
c.Description = "Produce assemblies for the project in given directory";
c.OnExecute(() => Exec("dotnet-compile", c.RemainingArguments));
});
app.Command("restore", c =>
{
c.Description = "Restore packages";
c.OnExecute(() => Exec("dotnet-restore", c.RemainingArguments));
});
app.Command("pack", c =>
{
c.Description = "Produce a NuGet package";
c.OnExecute(() => Exec("dotnet-pack", c.RemainingArguments));
});
app.Command("publish", c =>
{
c.Description = "Produce deployable assets";
c.OnExecute(() => Exec("dotnet-publish", c.RemainingArguments));
});
// TODO: Handle unknown commands
app.OnExecute(() =>
{
app.ShowHelp();
return 2;
});
try
{
return app.Execute(args);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
return 1;
}
示例6: Main
public static void Main(string[] args)
{
var app = new CommandLineApplication
{
Name = "Project.Json.Patcher",
Description = "Patch project.json files with new version and release notes",
FullName = "Project.Json Patcher"
};
app.HelpOption("-h|--help");
app.Command("Patch", commandAppConfing =>
{
commandAppConfing.Description = "Patches the project.json file";
CommandOption fileOption = commandAppConfing.Option("-f|--File <FilePath>",
"OPTIONAL. Path to project.json", CommandOptionType.SingleValue);
CommandOption versionOption = commandAppConfing.Option("-v|--Version <Version>",
"Target version of project.json", CommandOptionType.SingleValue);
CommandOption releaseNotesOption = commandAppConfing.Option("-r|--RealeaseNotes <ReleaseNotes>",
"OPTIONAL. Release notes of this version", CommandOptionType.SingleValue);
commandAppConfing.HelpOption("-h|--help");
commandAppConfing.OnExecute(() =>
{
string filePath = GetFilePath(fileOption);
string version = GetVersion(versionOption);
string releaseNotes = releaseNotesOption.Value();
Console.WriteLine($"FilePath: {filePath}, " +
$"Version: {version}, " +
$"ReleaseNotes: {releaseNotes}");
Patch(filePath, version, releaseNotes);
Console.WriteLine("Patching Complete");
return 0;
});
});
app.OnExecute(() =>
{
app.ShowHelp();
return 2;
});
app.Execute(args);
}
示例7: Main
public int Main(params string[] args)
{
ServicePointManager.DefaultConnectionLimit = 1000;
ServicePointManager.MaxServicePoints = 1000;
var proxies = CreateClients().ToList();
if (!proxies.Any())
{
Console.WriteLine("No Bolt servers running ...".Red());
return 1;
}
var app = new CommandLineApplication();
app.Name = "bolt";
app.OnExecute(() =>
{
app.ShowHelp();
return 2;
});
app.Command("test", c =>
{
c.Description = "Tests the Bolt performance.";
var output = c.Option("--output <PATH>", "Directory or configuration file path. If no path is specified then the 'bolt.configuration.json' configuration file will be generated in current directory.", CommandOptionType.SingleValue);
var argRepeats = c.Option("-r <NUMBER>", "Number of repeats for each action.", CommandOptionType.SingleValue);
var argConcurrency = c.Option("-c <NUMBER>", "Concurrency of each action.", CommandOptionType.SingleValue);
c.HelpOption("-?|-h|--help");
int cnt = 100;
int degree = 1;
c.OnExecute(() =>
{
if ( argRepeats.HasValue())
{
cnt = int.Parse(argRepeats.Value());
}
if (argConcurrency.HasValue())
{
degree = int.Parse(argConcurrency.Value());
}
ExecuteActions(proxies, cnt, degree);
Console.WriteLine("Test finished. Press any key to exit program ... ");
System.Console.ReadLine();
return 0;
});
});
return app.Execute(args);
}
示例8: 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;
}
示例9: 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;
}
示例10: Main
public int Main(string[] args)
{
var app = new CommandLineApplication(throwOnUnexpectedArg: false);
app.Name = "Microsoft.Dnx.Project";
app.FullName = app.Name;
app.HelpOption("-?|-h|--help");
// Show help information if no subcommand/option was specified
app.OnExecute(() =>
{
app.ShowHelp();
return 2;
});
app.Command("crossgen", c =>
{
c.Description = "Do CrossGen";
var optionIn = c.Option("--in <INPUT_DIR>", "Input directory", CommandOptionType.MultipleValue);
var optionOut = c.Option("--out <OUTOUT_DIR>", "Output directory", CommandOptionType.SingleValue);
var optionExePath = c.Option("--exePath", "Exe path", CommandOptionType.SingleValue);
var optionRuntimePath = c.Option("--runtimePath <PATH>", "Runtime path", CommandOptionType.SingleValue);
var optionSymbols = c.Option("--symbols", "Use symbols", CommandOptionType.NoValue);
var optionPartial = c.Option("--partial", "Allow partial NGEN", CommandOptionType.NoValue);
c.HelpOption("-?|-h|--help");
c.OnExecute(() =>
{
var crossgenOptions = new CrossgenOptions();
crossgenOptions.InputPaths = optionIn.Values;
crossgenOptions.RuntimePath = optionRuntimePath.Value();
crossgenOptions.CrossgenPath = optionExePath.Value();
crossgenOptions.Symbols = optionSymbols.HasValue();
crossgenOptions.Partial = optionPartial.HasValue();
var gen = new CrossgenManager(crossgenOptions);
if (!gen.GenerateNativeImages())
{
return 1;
}
return 0;
});
});
app.Execute(args);
return 0;
}
示例11: Main
public static int Main(string[] args)
{
var app = new CommandLineApplication
{
Name = "dotnet publish-iis",
FullName = "Asp.Net Core IIS Publisher",
Description = "IIS Publisher for the Asp.Net Core web applications",
};
app.HelpOption("-h|--help");
var publishFolderOption = app.Option("-p|--publish-folder", "The path to the publish output folder", CommandOptionType.SingleValue);
var frameworkOption = app.Option("-f|--framework <FRAMEWORK>", "Target framework of application being published", CommandOptionType.SingleValue);
var configurationOption = app.Option("-c|--configuration <CONFIGURATION>", "Target configuration of application being published", CommandOptionType.SingleValue);
var projectPath = app.Argument("<PROJECT>", "The path to the project (project folder or project.json) being published. If empty the current directory is used.");
app.OnExecute(() =>
{
var publishFolder = publishFolderOption.Value();
var framework = frameworkOption.Value();
if (publishFolder == null || framework == null)
{
app.ShowHelp();
return 2;
}
Reporter.Output.WriteLine($"Configuring the following project for use with IIS: '{publishFolder}'");
var exitCode = new PublishIISCommand(publishFolder, framework, configurationOption.Value(), projectPath.Value).Run();
Reporter.Output.WriteLine("Configuring project completed successfully");
return exitCode;
});
try
{
return app.Execute(args);
}
catch (Exception e)
{
Reporter.Error.WriteLine(e.Message.Red());
Reporter.Output.WriteLine(e.ToString().Yellow());
}
return 1;
}
示例12: 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);
}
示例13: 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;
}
示例14: 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");
// 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);
}
示例15: 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);
}