本文整理汇总了C#中OptionSet.Parse方法的典型用法代码示例。如果您正苦于以下问题:C# OptionSet.Parse方法的具体用法?C# OptionSet.Parse怎么用?C# OptionSet.Parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OptionSet
的用法示例。
在下文中一共展示了OptionSet.Parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParsedArguments
public ParsedArguments(string[] args) {
var p = new OptionSet {
{"sum", "If set Sum will be calculated", _ => _SumValues = true},
{"max", "If set show Max value", _ => _MaxValue = true},
{"min", "If set show Min value", _ => _MinValue = true},
{"dir=", "Output directory", dir => _OutputDirectory = GetValidPath(dir)}, {
"count=", "Count of items to be generated. This value is mandatory.", count => {
if (!_CountIsSet && int.TryParse(count, out _Count) && _Count > 0) {
_CountIsSet = true;
}
}
}
};
p.Parse(args);
if (!ArgsAreValid) {
Trace.WriteLine("Parameter args does not contain valid value for count.");
using (var stringWriter = new StringWriter()) {
p.WriteOptionDescriptions(stringWriter);
_ErrorMessage = stringWriter.ToString();
}
}
}
示例2: ParseCommandLineOptions
static bool ParseCommandLineOptions(String[] args, Options options)
{
var set = new OptionSet()
{
{ "o|outdir=", v => options.OutputDir = v },
// Misc. options
{ "v|verbose", v => { options.Verbose = true; } },
{ "h|?|help", v => options.ShowHelpText = v != null },
};
if (args.Length == 0 || options.ShowHelpText)
{
ShowHelp(set);
return false;
}
try
{
options.PackageName = set.Parse(args)[0].Replace("\"", "");
options.PackageDir = set.Parse(args)[1].Replace("\"", "");
}
catch (OptionException)
{
Console.WriteLine("Error parsing the command line.");
ShowHelp(set);
return false;
}
return true;
}
示例3: Main
static void Main(string[] args) {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
try {
// use command-line parameters if provided (used by auto-update functionality)
bool showHelp = false;
bool skipUpdateCheck = false;
_options = new OptionSet {
{"h|help", "Show this short help text", v => showHelp = true},
{"k|killpid=", "Kill calling (old) process (to be used by updater)", KillDanglingProcess },
{"c|cleanupdate=", "Delete (old) executable (to be used by updater)", RemoveOldExecutable },
{"s|skip-update-check", "Skip update check)", v => skipUpdateCheck = true },
};
_options.Parse(args);
if (showHelp) {
ShowHelp();
return;
}
Application.Run(new MainForm(skipUpdateCheck));
}
catch (Exception exc) {
MessageBox.Show("An error ocurred: " + exc.Message + "\r\n\r\nCallstack: " + exc.StackTrace);
}
}
示例4: Main
public static void Main(string[] args)
{
Console.WriteLine(WelcomeText());
THIS_FOLDER = GetThisFolder();
var config = LoadConfig(THIS_FOLDER + "rallybot.conf");
var reportFlags = string.Format("{0}|{1}", "iteration-report=", "report=");
var burnFlags = string.Format("{0}|{1}|{2}", "burndown-hours:", "burndown:", "burndown-on-date:");
var docFlags = string.Format("{0}|{1}", "designdoc=", "design-doc="); //todo: maybe this will just create a data struct that can be consumed by pmDeath
var helpFlags = string.Format("{0}|{1}|{2}", "?", "h", "help");
var todayString = DateTime.Today.ToString("yyyy-MM-dd");
var setBuildIdFlags = string.Format("{0}", "buildid="); //M
OPTIONS = new OptionSet() {
{ reportFlags, "Generate status report email", iter_num => WriteRallyStatusReportForAnIteration(config, iter_num ?? "")},
{ burnFlags, "Automatically 'Burn Down' hours", alternate_date => AutomaticallySetRallyTime_Alpha(config, Convert.ToDateTime(alternate_date ?? todayString))},
{ helpFlags, "Display detailed help.", _ => ShowHelp()},
{ setBuildIdFlags, "Set a new Build Id", buildId => SetBuildId(config, buildId ?? "")}//M
};
var badInput = OPTIONS.Parse(args);
if(badInput.Count > 0) {
Console.WriteLine(GetErrorReport(badInput.ToArray()));
Console.WriteLine(OffensiveGesture());
ShowHelp();
}
Console.WriteLine("done");
Console.ReadLine();
}
示例5: Main
public static int Main (string [] args)
{
bool help = false;
bool unpack = false;
string pattern = @"^.+\.xaml?";
var p = new OptionSet () {
{ "h|?|help", v => help = v != null },
{ "u|unpack", "Extract resources from the supplied assembly.", v => unpack = v != null },
{ "p|pattern=", "Only extract the resources that match supplied pattern. By default only .xaml files will be extracted.", v => pattern = v },
{ "v|verbose", v=> verbose = v != null }
};
List<string> files = null;
try {
files = p.Parse(args);
} catch (OptionException e){
Console.WriteLine ("Try `respack --help' for more information.");
return 1;
}
if (help)
ShowHelp (p);
if (unpack)
return Unpack (files [0], pattern);
if (files == null || files.Count == 0)
ShowHelp (p);
return Pack (files);
}
示例6: InitializeCommandLineOptions
private static void InitializeCommandLineOptions(string[] args)
{
bool showHelp = false;
var p = new OptionSet
{
{ "u|username=", "spotify username", userName => Bootstrapper.UserName = userName },
{ "p|password=", "spotify password", password => Bootstrapper.Password = password },
{ "websiteEnabled=", "host website", (bool enabled) => Bootstrapper.WebsiteEnabled = enabled },
{ "websitePath=", "path for the web site", path => Bootstrapper.WebsitePath = path },
{ "websitePort=", "the port the website will be hosted on", (int port) => Bootstrapper.WebsitePort = port },
{ "wcfHttpPort=", "the port the http wcf services will be hosted on", (int port) => Bootstrapper.WcfHttpPort = port },
{ "wcfTcpPort=", "the port the tcp wcf services will be hosted on", (int port) => Bootstrapper.WcfTcpPort = port },
{ "h|help", "show this message and exit", v => showHelp = v != null }
};
try
{
p.Parse(args);
}
catch (OptionException e)
{
Console.Write("greet: ");
Console.WriteLine(e.Message);
Console.WriteLine("Try `greet --help' for more information.");
}
if (showHelp)
{
p.WriteOptionDescriptions(Console.Out);
Console.ReadLine();
Environment.Exit(0);
}
}
示例7: Parse
public InstanceConfiguration Parse(IList<string> args)
{
var cfg = new InstanceConfiguration
{
AppName = string.Empty,
Help = false,
Verbose = false,
ExtraParams = new List<string>()
};
var p = new OptionSet
{
{"app=", v => cfg.AppName = v},
{"i|install", v => cfg.Install = v != null},
{"v|verbose", v => cfg.Verbose = v != null},
{"h|?|help", v => cfg.Help = v != null},
};
cfg.OptionSet = p;
if (args == null || !args.Any())
{
cfg.Help = true;
return cfg;
}
cfg.ExtraParams = p.Parse(args);
cfg.AppName = cfg.AppName.Trim('"', '\'');
return cfg;
}
示例8: Main
public static void Main(string [] args)
{
// Parse the command line options
bool show_help = false;
OptionSet option_set = new OptionSet () {
{ "v|version", _("Print version information"), v => { PrintVersion (); } },
{ "h|help", _("Show this help text"), v => show_help = v != null }
};
try {
option_set.Parse (args);
} catch (OptionException e) {
Console.Write ("SparkleShare: ");
Console.WriteLine (e.Message);
Console.WriteLine ("Try `sparkleshare --help' for more information.");
}
if (show_help)
ShowHelp (option_set);
// Initialize the controller this way so that
// there aren't any exceptions in the OS specific UI's
Controller = new SparkleController ();
Controller.Initialize ();
if (Controller != null) {
UI = new SparkleUI ();
UI.Run ();
}
}
示例9: Run
public static bool Run(IList<string> args) {
var detail = false;
// parse options
var p = new OptionSet {
{ "d|detail", v => detail = v != null },
};
try {
args = p.Parse(args);
} catch {
return Program.Print(Usage);
}
if (args.Count < 1) {
return Program.Print(Usage);
}
var iArgs = 0;
var rootDir = new DirectoryInfo(args[iArgs++]);
if (!rootDir.Exists) {
return Program.Print(
"Root directory doesn't exist.\nroot:" + rootDir.FullName);
}
var covDataFile = args.Count >= iArgs + 1
? new FileInfo(args[iArgs++]) : null;
covDataFile = FileUtil.GetCoverageRecord(covDataFile, rootDir);
if (!covDataFile.SafeExists()) {
return
Program.Print(
"Coverage data file doesn't exist.\ncoverage:" + covDataFile.FullName);
}
return Analyze(rootDir, covDataFile, detail);
}
示例10: Main
static void Main(string[] args)
{
Console.WriteLine("Welcome to YARP (Yet Another Retriever of Passwords) - by Joakim Skoog");
bool shouldShowHelp = false;
//string loggerOption = "";
string retrievers = "";
var p = new OptionSet()
{
{"h|help", "Shows the valid parameters and how to use them", v => shouldShowHelp = v != null},
//{"o|output=", "Print results to console or file. Valid arguments are 'console' or a filepath", v => loggerOption = v},
{"r|retrievers=", "Which retrievers that should be used for retrieving passwords. Valid arguments: all", v => retrievers = v}
};
try
{
p.Parse(args);
}
catch (OptionException)
{
Console.WriteLine("Could not parse arguments. Please try --help for more information.");
}
if (shouldShowHelp)
{
PrintHelp(p);
return;
}
Console.WriteLine("Retrieving passwords...");
var retrievedPasswords = RetrievePasswords(retrievers);
Logger.Log(retrievedPasswords);
}
示例11: Main
static void Main(string[] args)
{
string reportToRun = string.Empty;
var p = new OptionSet()
.Add("r|report", a => reportToRun = a);
p.Parse(args);
if(String.IsNullOrEmpty(reportToRun))
{
NoParametersPassed();
}
switch(reportToRun)
{
case "r":
Console.WriteLine("Running Monthly GDS Report");
Report report = new Report();
report.MonthlyReport();
break;
default:
break;
}
}
示例12: Main
static void Main(string[] args)
{
XmlConfigurator.Configure();
var options = new OptionSet();
var principal = 0.0d;
var rate = 0.0d;
var payments = 0;
options.Add("p=|principal=", v => principal = double.Parse(v))
.Add("r=|rate=", v => rate = double.Parse(v) / 100.0d)
.Add("n=|payments=", v => payments = int.Parse(v));
options.Parse(args);
var calculator = new AmortizationLibrary.AmortizationCalculator();
var amortizationSchedule = calculator.Calculate(principal, rate, payments);
foreach(var detail in amortizationSchedule)
{
Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}",
detail.PaymentNumber,
detail.Payment.ToString("C"),
detail.InterestPaid.ToString("C"),
detail.PrincipalPaid.ToString("C"),
detail.Balance.ToString("C")
);
}
Console.ReadLine();
}
示例13: Main
public static void Main(string[] args)
{
bool shouldReportBenchview = false;
bool shouldUploadTrace = true;
bool isCiTest = false;
string traceDestination = @"\\mlangfs1\public\basoundr\PerfTraces";
var parameterOptions = new OptionSet()
{
{"report-benchview", "report the performance retults to benview.", _ => shouldReportBenchview = true},
{"ci-test", "mention that we are running in the continuous integration lab", _ => isCiTest = true},
{"no-trace-upload", "disable the uploading of traces", _ => shouldUploadTrace = false},
{"trace-upload_destination", "set the trace uploading destination", loc => { traceDestination = loc; }}
};
parameterOptions.Parse(args);
AsyncMain(isCiTest).GetAwaiter().GetResult();
if (isCiTest)
{
Log("Running under continuous integration");
}
if (shouldReportBenchview)
{
Log("Uploading results to benchview");
UploadBenchviewReport();
}
if (shouldUploadTrace)
{
Log("Uploading traces");
UploadTraces(GetCPCDirectoryPath(), traceDestination);
}
}
示例14: HandleArgs
private static bool HandleArgs(ICollection<string> args, OptionSet set)
{
if (args.Count < 2)
return false;
set.Parse(args);
return true;
}
示例15: Main
public static void Main (string[] args)
{
Debug.AutoFlush = true;
Debug.Listeners.Add (new ConsoleTraceListener ());
bool server = false;
string prefix = "http://localhost:8088/";
var p = new OptionSet ().
Add ("server", v => server = true).Add ("prefix=", v => prefix = v).
Add ("xml", v => xml = true);
p.Parse (args);
var asm = typeof(Simple).Assembly;
if (server) {
Server.Start (asm, prefix).Wait ();
Thread.Sleep (System.Threading.Timeout.Infinite);
return;
}
try {
Run (asm).Wait ();
} catch (Exception ex) {
Console.WriteLine ("ERROR: {0}", ex);
}
}