本文整理汇总了C#中CommandLine.CommandLineParser类的典型用法代码示例。如果您正苦于以下问题:C# CommandLineParser类的具体用法?C# CommandLineParser怎么用?C# CommandLineParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandLineParser类属于CommandLine命名空间,在下文中一共展示了CommandLineParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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();
}
示例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);
}
}
示例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;
}
示例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;
}
}
示例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.");
}
}
}
示例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;
}
示例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!");
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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
}
示例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;
}
}
示例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;
}