本文整理汇总了C#中CommandLine.CommandLineParser类的典型用法代码示例。如果您正苦于以下问题:C# CommandLineParser类的具体用法?C# CommandLineParser怎么用?C# CommandLineParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandLineParser类属于CommandLine命名空间,在下文中一共展示了CommandLineParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetOptions
public static Options GetOptions(string[] args)
{
var options = new Options();
ICommandLineParser parser = new CommandLineParser();
try
{
if (!parser.ParseArguments(args, options))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Error: was unable to parse some arguments");
Console.ResetColor();
Console.WriteLine(options.GetUsage());
Environment.Exit(-1);
}
}
catch (ArgumentException ae)
{
if (ae.Message == "shortName")
{
Console.Error.WriteLine("Short name attribute can't be NULL or Length > 1");
}
}
if (string.IsNullOrWhiteSpace(options.Operation))
{
Console.WriteLine("Error parsing arguments: No <operation> option specified");
Console.WriteLine(options.GetUsage());
Environment.Exit(1);
}
return options;
}
开发者ID:DmitriySokhach,项目名称:KanbanizeTFSToolkit,代码行数:31,代码来源:Options.cs
示例2: Main
static void Main(string[] args)
{
var options = new Options();
var parser = new CommandLineParser();
if (parser.ParseArguments(args, options))
{
if (!string.IsNullOrEmpty(options.Name))
{
switch(options.Name)
{
case "ClassicObserver":
ClassicObserver();
break;
case "EventObserver":
EventObserver();
break;
case "Factory":
Factory();
break;
case "Combine":
Combine();
break;
default:
break;
}
}
}
else
{
Console.Write("No argument");
}
Console.ReadLine();
}
开发者ID:zyq524,项目名称:miscellaneous,代码行数:33,代码来源:Program.cs
示例3: Main
private static void Main(string[] args)
{
AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var configFileName = string.Empty;
var unattendedMode = false;
int numThreads = -1;
var options = new CommandLineOptions();
ICommandLineParser parser = new CommandLineParser();
var writer = new StringWriter();
if (parser.ParseArguments(args, options, writer))
{
configFileName = options.SessionFile;
unattendedMode = options.Unattended;
numThreads = options.NumberOfThreads;
}
if (writer.GetStringBuilder().Length > 0)
{
MessageBox.Show(writer.GetStringBuilder().ToString());
}
else
{
var f = new Form1(configFileName, unattendedMode, numThreads)
{
StartPosition = FormStartPosition.CenterScreen
};
Application.Run(f);
}
}
开发者ID:ErikEJ,项目名称:SqlQueryStress,代码行数:32,代码来源:Program.cs
示例4: Main
public static int Main(string[] args)
{
ICommandLineParser parser = new CommandLineParser();
var options = new ProgramOptions();
if (!parser.ParseArguments(args, options, Console.Error))
{
return 1;
}
// Archiving the source to a temporary file.
string zipFileName = Path.GetTempFileName();
ZipCompress(options.SourcePath, zipFileName, options.ArchivePassword, options.CompressionLevel);
// Uploading the archive to Azure Storage.
UploadFileToBlobStorage(zipFileName, options);
// Removing the temporary file.
try
{
File.Delete(zipFileName);
}
catch (Exception ex)
{
Trace.WriteLine(ex);
}
return 0;
}
开发者ID:VictorHaydin,项目名称:WindowsAzureTools,代码行数:29,代码来源:Program.cs
示例5: Main
static void Main(string[] args)
{
Options commandLineOptions = new Options();
ICommandLineParser commandParser = new CommandLineParser();
if (commandParser.ParseArguments(args, commandLineOptions, Console.Error))
{
if (ValidateOptions(commandLineOptions))
{
try
{
TaskProcessor concatTask = new TaskProcessor();
concatTask.ProcessTask(commandLineOptions);
}
catch (Exception ex)
{
StringBuilder errorMessage = new StringBuilder();
errorMessage.AppendLine(messageUnexpectedError);
if (commandLineOptions.DebugMessages)
{
errorMessage.AppendFormat(messageUnhandledException, ex.ToString(), ex.Message, ex.StackTrace);
}
System.Console.Error.WriteLine(errorMessage.ToString());
Environment.ExitCode = 1;
}
}
}
else
{
// Command line params could not be parsed,
// or help was requested
Environment.ExitCode = -1;
}
}
开发者ID:stchan,项目名称:PdfMiniTools,代码行数:33,代码来源:Program.cs
示例6: Main
static void Main(string[] args)
{
CommandLineOption options = new CommandLineOption();
ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings
{
MutuallyExclusive = true,
CaseSensitive = true,
HelpWriter = Console.Error
});
bool success = parser.ParseArguments(args, options);
if (true == success)
{
Run(options.FileName, options.Overwrite);
}
else
{
if (args.Length != 0 && args[0] != "-h")
{
NotifyAndExit("Input arguments are invalid. Type PostBuild.exe -h for help. Press any key to exit.");
}
}
}
开发者ID:thanhtranTSD,项目名称:BuildEventer-1,代码行数:25,代码来源:Program.cs
示例7: Main
static int Main(string[] args)
{
Options options = new Options();
ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error) { MutuallyExclusive = true });
if (!parser.ParseArguments(args, options))
{
return 1;
}
using (var output = options.OutputFile == null ? Console.Out : File.CreateText(options.OutputFile))
{
var file = options.Source;
if (File.Exists(file))
{
ProcessFile(file, file, options, output);
}
else if (Directory.Exists(file))
{
var writer = new StringWriter();
ProcessDirectory(file, options, writer);
var text = writer.ToString();
WriteHeaders(text, options, output);
output.Write(text);
}
else
{
Console.Error.WriteLine($"File not found: {file}");
return 1;
}
}
return 0;
}
开发者ID:nodatime,项目名称:tzvalidate,代码行数:32,代码来源:Program.cs
示例8: Main
static void Main(params string[] args)
{
#if DEBUG
Assembly.LoadFile(Path.Combine(Directory.GetCurrentDirectory(), "Aqueduct.Appia.Razor.dll"));
#endif
var options = new Options();
ICommandLineParser parser = new CommandLineParser();
parser.ParseArguments(args, options);
if (string.IsNullOrEmpty(options.ExportPath) == false)
{
var exporter = new HtmlExporter(options.ExportPath,
new Configuration(),
new Aqueduct.Appia.Core.Bootstrapper())
{ Verbose = options.Verbose };
exporter.Initialise();
exporter.Export();
}
else
{
var ip = options.Address == "*" ? IPAddress.Any : IPAddress.Parse(options.Address);
var nancyHost = new NancyHost(ip, options.Port, new Aqueduct.Appia.Core.Bootstrapper());
nancyHost.Start();
Console.WriteLine(String.Format("Nancy now listening - navigate to http://{0}:{1}/. Press enter to stop", options.Address, options.Port));
Console.ReadKey();
nancyHost.Stop();
Console.WriteLine("Stopped. Good bye!");
}
}
开发者ID:aqueduct,项目名称:Appia,代码行数:33,代码来源:Program.cs
示例9: Main
static void Main(string[] args)
{
try
{
var options = new Options();
var parser = new CommandLineParser(new CommandLineParserSettings(Console.Error));
if (!parser.ParseArguments(args, options))
Environment.Exit(1);
using(var ctx = ZmqContext.Create())
{
using (ZmqSocket receiver = ctx.CreateSocket(SocketType.PULL),
sender = ctx.CreateSocket(SocketType.PUSH))
{
receiver.Connect(options.pullEndPoint);
sender.Connect(options.pushEndPoint);
while (true)
{
var rcvdMsg = receiver.Receive(Encoding.UTF8);
Console.WriteLine("Pulled : " + rcvdMsg);
var sndMsg = options.rcvdMessageTag.Replace("#msg#", rcvdMsg);
Thread.Sleep(options.delay);
Console.WriteLine("Pushing: " + sndMsg);
sender.Send(sndMsg, Encoding.UTF8);
}
}
}
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
}
}
开发者ID:90xukan,项目名称:ZeroMQ,代码行数:34,代码来源:Program.cs
示例10: Main
static void Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
log = LogManager.GetLogger("UCSF.GrantLoader");
try
{
Options options = new Options();
ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error));
if (!parser.ParseArguments(args, options))
{
Options.ShowUsage();
Environment.Exit(1);
}
ExecTasks(options);
#if DEBUG
Console.ReadKey();
#endif
}
catch(Exception ex)
{
log.Info("Unhandled exception.");
log.Debug("Unhandled exception", ex);
}
}
开发者ID:anirvan,项目名称:gadgets,代码行数:27,代码来源:Program.cs
示例11: Main
static void Main(string[] args)
{
var stopwatch = Stopwatch.StartNew();
var kuduSyncOptions = new KuduSyncOptions();
try
{
ICommandLineParser parser = new CommandLineParser();
if (parser.ParseArguments(args, kuduSyncOptions))
{
SetLogger(kuduSyncOptions);
new KuduSync(kuduSyncOptions).Run();
}
else
{
throw new InvalidOperationException("Failed to parse arguments");
}
}
catch (Exception ex)
{
Console.Error.WriteLine("Error: " + ex.Message);
}
stopwatch.Stop();
if (kuduSyncOptions.Perf)
{
Console.WriteLine("Time " + stopwatch.ElapsedMilliseconds);
}
}
开发者ID:amitapl,项目名称:KuduSync.NET,代码行数:30,代码来源:Program.cs
示例12: Main
static void Main(string[] args)
{
var options = new Options();
var parser = new CommandLineParser(new CommandLineParserSettings(Console.Error));
try
{
if (!parser.ParseArguments(args, options))
{
Console.Read();
Environment.Exit(0);
}
}
catch (Exception ex)
{
errorPrompt("When parsing command line arguments an exception occurred:\n{0}", ex.Message);
}
if (options.writeMode)
{
writeDataMatrix(options);
Console.Read();
Environment.Exit(0);
}
if (options.readMode)
{
readDataMatrix(options);
Console.Read();
Environment.Exit(0);
}
}
开发者ID:kdl00,项目名称:DatamatrixTool,代码行数:31,代码来源:Program.cs
示例13: Main
static void Main(string[] arg)
{
var options = new Options();
var parser = new CommandLineParser(new CommandLineParserSettings(Console.Error));
//if (!parser.ParseArguments(args, options))
// Environment.Exit(1);
//commandAssembly = Assembly.LoadFile(Environment.CurrentDirectory+ "\\CommonFunctions.dll");
string commandArgs = null;
HostFactory.Run(x => //1
{
x.AddCommandLineDefinition("arguments", f => { commandArgs = f; });
x.ApplyCommandLine();
Console.WriteLine(commandArgs);
string[] args = commandArgs.Split(' ');
parser.ParseArguments(args, options);
x.Service<BowService>(s => //2
{
s.ConstructUsing(name => new BowService()); //3
s.WhenStarted(tc => tc.Start(options)); //4
s.WhenStopped(tc => tc.Stop()); //5
});
x.RunAsLocalSystem(); //6
x.SetDescription("Sample Bow Service Host"); //7
x.SetDisplayName("BowService"); //8
x.SetServiceName("BowService"); //9
}); //10
}
开发者ID:deepaksinghmehta,项目名称:bow,代码行数:34,代码来源:BowServiceInstaller.cs
示例14: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
static int Main(string[] args)
{
try
{
var options = new SlaveOptions();
var parser = new CommandLineParser();
var helpWriter = new StringWriter();
if (!parser.ParseArguments(args, options, helpWriter))
{
MessageBox.Show(helpWriter.ToString(), "VMTool Slave");
return 1;
}
var server = new SlaveServer(options);
if (options.Debug)
{
GlobalContext.Properties["LogToConsole"] = "true";
server.Run();
}
else
{
ServiceBase.Run(new SlaveService(server));
}
return 0;
}
catch (Exception ex)
{
log.Fatal("Fatal exception.", ex);
return 1;
}
}
开发者ID:timonela,项目名称:mb-unit,代码行数:34,代码来源:SlaveProgram.cs
示例15: Main
private static int Main(string[] args)
{
Options options = new Options();
ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error) { MutuallyExclusive = true });
if (!parser.ParseArguments(args, options))
{
return 1;
}
List<DateTimeZone> zones = LoadSource(options);
zones = zones.OrderBy(zone => zone.Id, StringComparer.Ordinal).ToList();
if (options.ZoneId != null)
{
var zone = zones.FirstOrDefault(z => z.Id == options.ZoneId);
if (zone == null)
{
throw new Exception($"Unknown zone ID: {options.ZoneId}");
}
DumpZone(zone, options);
}
else
{
foreach (var zone in zones)
{
DumpZone(zone, options);
Console.Write("\r\n");
}
}
return 0;
}
开发者ID:nicklbailey,项目名称:nodatime,代码行数:32,代码来源:Program.cs
示例16: Main
static void Main(string[] args)
{
ServicePointManager.UseNagleAlgorithm = false;
Console.WriteLine(HeadingInfo);
var options = new Options();
var parser = new CommandLineParser(new CommandLineParserSettings(Console.Error));
if (!parser.ParseArguments(args, options))
{
Environment.Exit(1);
}
var client = new RestClient
{
Authenticator = new HttpBasicAuthenticator(options.UserName, options.Password)
};
Root root = client.GetRoot(options.Server);
Organisation org = client.GetOrganisation(root);
Stopwatch watch = Stopwatch.StartNew();
CreateAllRelationships(client, root, options, org);
Console.WriteLine("Completed in {0} - press enter to exit.", watch.Elapsed);
Console.ReadLine();
Environment.Exit(0);
}
开发者ID:bendalton,项目名称:EnterpriseTester-API-Examples,代码行数:34,代码来源:Program.cs
示例17: Parse
public Command Parse(string inputString)
{
if (String.IsNullOrEmpty(inputString))
{
throw new CommandException("Emtpy command");
}
var commandAndParams = (from words in inputString
let split = inputString.Split(' ')
select new { Name = split.First(), Parameters = split.Skip(1) }).FirstOrDefault();
if (commandAndParams == null)
{
throw new CommandException("Invalid Command");
}
var commandOptionsType =
Assembly.GetExecutingAssembly().GetType(string.Format("{0}.{1}.{2}CommandOptions", Assembly.GetExecutingAssembly().GetName().Name, "Commands.CommandOptions", commandAndParams.Name));
if (commandOptionsType == null)
{
throw new CommandException("Invalid Command");
}
var commandParameters = Activator.CreateInstance(commandOptionsType);
ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(false));
if (parser.ParseArguments(commandAndParams.Parameters.ToArray(), commandParameters))
{
return new Command() { Name = commandAndParams.Name, Parameters = commandParameters };
}
throw new CommandException("Invalid Command Parameters");
}
开发者ID:MikeLarah,项目名称:YouTrackSharp,代码行数:34,代码来源:CommandParser.cs
示例18: Main
private static int Main(string[] args)
{
Options options = new Options();
ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error) { MutuallyExclusive = true });
if (!parser.ParseArguments(args, options))
{
return 1;
}
TzdbDateTimeZoneSource source = LoadSource(options.Source);
var dumper = new ZoneDumper(source, options);
try
{
using (var writer = options.OutputFile == null ? Console.Out : File.CreateText(options.OutputFile))
{
dumper.Dump(writer);
}
}
catch (UserErrorException e)
{
Console.Error.WriteLine($"Error: {e.Message}");
return 1;
}
return 0;
}
开发者ID:ivandrofly,项目名称:nodatime,代码行数:25,代码来源:Program.cs
示例19: Main
static void Main(string[] args)
{
try
{
var options = new Options();
var parser = new CommandLineParser(new CommandLineParserSettings(Console.Error));
if (!parser.ParseArguments(args, options))
Environment.Exit(1);
using(var ctx = ZmqContext.Create())
{
using (var socket = ctx.CreateSocket(SocketType.PULL))
{
foreach (var endPoint in options.bindEndPoints)
socket.Bind(endPoint);
while (true)
{
Thread.Sleep(options.delay);
var msg = socket.Receive(Encoding.UTF8);
Console.WriteLine("Received: " + msg);
}
}
}
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
}
}
开发者ID:deepaksinghmehta,项目名称:bow,代码行数:30,代码来源:Program.cs
示例20: Main
/// <summary>
/// Runs the compiler from the command line.
/// </summary>
/// <param name="arguments">The command line arguments. Each compiler defines its own.</param>
/// <returns>0 for success, non-0 for error.</returns>
private static int Main(string[] arguments)
{
CompilerOptions options = new CompilerOptions();
ICommandLineParser parser = new CommandLineParser(new CommandLineParserSettings(Console.Error) { MutuallyExclusive = true });
if (!parser.ParseArguments(arguments, options))
{
return 1;
}
var tzdbCompiler = new TzdbZoneInfoCompiler();
var tzdb = tzdbCompiler.Compile(options.SourceDirectoryName);
tzdb.LogCounts();
if (options.ZoneId != null)
{
tzdb.GenerateDateTimeZone(options.ZoneId);
return 0;
}
var windowsZones = CldrWindowsZonesParser.Parse(options.WindowsMappingFile);
LogWindowsZonesSummary(windowsZones);
var writer = CreateWriter(options);
writer.Write(tzdb, windowsZones);
if (options.OutputFileName != null)
{
Console.WriteLine("Reading generated data and validating...");
var source = Read(options);
source.Validate();
if (options.TextDumpFile != null)
{
CreateTextDump(source, options.TextDumpFile);
}
}
return 0;
}
开发者ID:wondertrap,项目名称:nodatime,代码行数:39,代码来源:Program.cs
注:本文中的CommandLine.CommandLineParser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论