private static void CheckSchema( OptionSchema schema, Action preAction, Action postAction, params string[] args) { preAction(); var setting = schema.Parse(args); var arguments = setting.Arguments.ToArray(); var options = setting.Options.ToArray(); Assert.AreEqual(1, arguments.Length); Assert.AreEqual("foo", arguments[0]); Assert.AreEqual(1, options.Length); var o = options[0]; if (o is RequiredArgumentOption v) { CheckArg(v); CheckValue(v); } else { Assert.Fail(); } Assert.AreSame(schema, o.Schema); Assert.AreSame(schema, setting.Schema); postAction(); }
/// <summary> /// Initializes a new instance of the <see cref="OptionImpl"/> class. /// </summary> /// <param name="supplier"> /// The function returns the string representing this option, which is /// actually specified with the command line. /// </param> /// <param name="spec"> /// The specification of the option. /// </param> /// <param name="schema"> /// The schema of the option. /// </param> /// <seealso cref="OptionSchema.Add(string, char?, string, /// Action{Option})"/> public OptionImpl( Func <string> supplier, OptionSpec spec, OptionSchema schema) : base(supplier) { Spec = spec; Schema = schema; }
/// <summary> /// Initializes a new instance of the <see cref="SettingImpl"/> class. /// </summary> /// <param name="schema"> /// The instance that creates this object. /// </param> /// <param name="args"> /// The remaining non-option arguments. /// </param> /// <param name="options"> /// The options in order of appearance. /// </param> public SettingImpl( OptionSchema schema, IEnumerable <string> args, IEnumerable <Option> options) { Schema = schema; Arguments = args.ToArray(); Options = options.ToArray(); }
/// <summary> /// Initializes a new instance of the <see /// cref="RequiredArgumentOptionImpl"/> class. /// </summary> /// <param name="supplier"> /// The function returns the string representing this option, which is /// actually specified with the command line. /// </param> /// <param name="spec"> /// The specification of the option. /// </param> /// <param name="schema"> /// The schema of the option. /// </param> /// <param name="values"> /// The argument values of the option. /// </param> /// <seealso cref="OptionSchema.Add(string, char?, string, string, /// Action{RequiredArgumentOption})"/> public RequiredArgumentOptionImpl( Func <string> supplier, RequiredArgumentOptionSpec spec, OptionSchema schema, IEnumerable <string> values) : base(supplier) { Spec = spec; Schema = schema; ArgumentValues = values.ToImmutableArray(); }
private static void CheckHelpMessage(OptionSchema schema) { var helpLines = schema.GetHelpMessage().ToArray(); Assert.AreEqual(1, helpLines.Length); var help = helpLines[0]; Assert.AreEqual( "-f, --file FILE Specify input file", help); }
private static void CheckHelpMessage(OptionSchema schema) { var helpLines = schema.GetHelpMessage().ToArray(); Assert.AreEqual(1, helpLines.Length); var help = helpLines[0]; Assert.AreEqual( "-h, --help Show help message", help); }
private static void CheckSchema( OptionSchema schema, Action preAction, Action postAction, params string[] args) { preAction(); var setting = schema.Parse(args); var arguments = setting.Arguments.ToArray(); var options = setting.Options.ToArray(); Assert.AreEqual(1, arguments.Length); Assert.AreEqual("foo", arguments[0]); Assert.AreEqual(1, options.Length); var o = options[0]; Assert.AreEqual("help", o.Name); Assert.IsTrue(o.ShortName.HasValue); Assert.AreEqual('h', o.ShortName.GetValueOrDefault()); Assert.AreEqual("Show help message", o.Description); Assert.AreSame(schema, o.Schema); Assert.AreSame(schema, setting.Schema); postAction(); }
/// <summary> /// Initializes a new instance of the <see /// cref="OptionParsingException"/> class. /// </summary> /// <param name="schema"> /// The schema. /// </param> /// <param name="message"> /// The message that describes the error. /// </param> public OptionParsingException(OptionSchema schema, string message) : base(message) { Schema = schema; }
/// <summary> /// Initializes a new instance of the <see cref="ParseKit"/> class. /// </summary> /// <param name="schema"> /// The option schema. /// </param> /// <param name="option"> /// The short name of the option. /// </param> public ParseKit(OptionSchema schema, char option) { this.schema = schema; this.option = () => $"-{option}"; }
/// <summary> /// Initializes a new instance of the <see cref="ParseKit"/> class. /// </summary> /// <param name="schema"> /// The option schema. /// </param> /// <param name="option"> /// The long name of the option. It can be followed by <c>=value</c>. /// </param> public ParseKit(OptionSchema schema, string option) { this.schema = schema; this.option = () => option; }