本文整理汇总了C#中CommandLine.CommandLineParser.ParseArguments方法的典型用法代码示例。如果您正苦于以下问题:C# CommandLineParser.ParseArguments方法的具体用法?C# CommandLineParser.ParseArguments怎么用?C# CommandLineParser.ParseArguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandLine.CommandLineParser
的用法示例。
在下文中一共展示了CommandLineParser.ParseArguments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
public static DefaultOptions Create(string[] args)
{
string target = string.Empty;
int i = 0;
foreach (string str in args)
{
if (str.StartsWith("-t"))
{
if (str.Length > 2)
{
target = str.Substring(2);
if (target.StartsWith("=") || target.StartsWith(":"))
{
target = target.Substring(1);
}
}
else
{
if (args.Length > i)
{
target = args[i + 1];
}
}
}
if (str.StartsWith("--target"))
{
target = str.Substring(9);
}
i++;
}
DefaultOptions options;
CommandLineParser parser = new CommandLineParser();
switch (target)
{
case "mssql":
options = new MSSQL.Options();
if (parser.ParseArguments(args, options))
return options;
throw new Exception("Could not parse arguments.");
case "mysql":
options = new MySQL.Options();
if (parser.ParseArguments(args, options))
return options;
throw new Exception("Could not parse arguments.");
case "postgresql":
options = new PostgreSQL.Options();
if (parser.ParseArguments(args, options))
return options;
throw new Exception("Could not parse arguments.");
default:
throw new Exception(string.Format("Target {0} is not valid.", target));
}
}
示例2: GetCommandLineOptions
private static IMsBuilderificCoreOptions GetCommandLineOptions(string[] args)
{
var options = Injection.Engine.Resolve<IMsBuilderificCoreOptions>();
var visitorOptions = Injection.Engine.ResolveAll<IVisitorOptions>();
var writer = new StringWriter();
if (args != null && args.Length > 0)
{
var parserSettings = new CommandLineParserSettings(false, false, true, System.Console.Out);
var parser = new CommandLineParser(parserSettings);
if (!parser.ParseArguments(args, options, writer))
{
visitorOptions.ForEach(v => parser.ParseArguments(args, v, writer));
System.Console.WriteLine(writer.ToString());
Environment.Exit(1);
}
else
{
visitorOptions.ForEach(v =>
{
if (!parser.ParseArguments(args, v, writer))
Environment.Exit(1);
Injection.Engine.RegisterInstance(v.GetType(), v);
});
}
}
else
{
var commandLineOptionsCore = options as CommandLineOptionsBase;
if (commandLineOptionsCore != null)
{
var help = HelpText.AutoBuild(commandLineOptionsCore, current => HelpText.DefaultParsingErrorsHandler(commandLineOptionsCore, current));
System.Console.WriteLine(help);
visitorOptions.ForEach(v =>
{
var visitorOptionBase = v as CommandLineOptionsBase;
if (visitorOptionBase == null)
return;
help = HelpText.AutoBuild(v, current => HelpText.DefaultParsingErrorsHandler(visitorOptionBase, current));
System.Console.WriteLine(help);
});
}
Environment.Exit(2);
}
return options;
}
示例3: 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);
}
}
示例4: 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();
}
示例5: 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);
}
}
示例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
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;
}
示例8: 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;
}
}
示例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[] 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
}
示例12: 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!");
}
}
示例13: 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);
}
}
示例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
/// <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;
}