/// <summary> /// Gets a <see cref="IDictionary{K, V}" /> of the name/value pairs to be POSTed to the analytics service. /// </summary> /// <returns> /// The <see cref="IDictionary{K, V}" /> of the name/value pairs to be POSTed to the analytics service. /// </returns> public IDictionary <string, object> GetFormValues() { var formValues = new Dictionary <string, object> { { "statement", OriginalStatement } }; foreach (var parameter in NamedParameters) { formValues.Add(parameter.Key, parameter.Value); } if (PositionalArguments.Any()) { formValues.Add("args", PositionalArguments.ToArray()); } formValues.Add("timeout", $"{_timeout.TotalMilliseconds}ms"); formValues.Add("client_context_id", ClientContextId ?? Guid.NewGuid().ToString()); if (!string.IsNullOrWhiteSpace(QueryContext)) { formValues.Add("query_context", QueryContext); } return(formValues); }
/// <summary> /// Add subparsers for the parent parser. Subparsers is an /// object that resembles a branch split in a tree. That means you can /// branch into different parsers from a parent parser. This can be used /// for a tool that does more than one job and requires keyword commands /// to do them. .NET CLI can be an example since it contains a lot of /// different commands (subparsers) for different actions. /// </summary> /// <param name="help">Help string to be printed in the help message for the subparsers object. It is empty by default.</param> /// <param name="title">Shows the subparsers help message in a different section with the given name.</param> /// <param name="dest">Adds a key to the namespace for the parser with the supplied string as value.</param> /// <returns>The added subparser object.</returns> public Subparsers AddSubparsers(string help = "", string title = "", string dest = "") { var subparsers = new Subparsers(Prog, help, title, dest); arguments.Add(subparsers); if (!string.IsNullOrEmpty(subparsers.Title)) { if (Categories.ContainsKey(subparsers.Title)) { Categories[subparsers.Title].Add(subparsers); } else { Categories[subparsers.Title] = new List <Argument>() { subparsers } }; } else { Categories[positionalArgsTitle].Add(subparsers); } PositionalArguments.Add(subparsers); return(subparsers); }
private void InitializePositionalArguments() { PositionalArguments.AddRange(typeof(T).GetTypeInfo().GetProperties() .Where(p => p.GetCustomAttribute <PositionalArgumentAttribute>() != null) .OrderBy(p => p.GetCustomAttribute <PositionalArgumentAttribute>().Index) .Select(p => p.ToPositionalArgument())); }
protected override void Run() { // ensure Mono.Cecil.dll will be in the directory where this is built typeof(Mono.Cecil.AssemblyDefinition).ToString(); base.Run(); var pch = PositionalArguments.DequeueOrDefault(); if (pch == null || !File.Exists(pch)) { throw new ExitException("Precompiled header file (pch) must be specified"); } var assemblies = new List <string> (); while (PositionalArguments.Count > 0) { var dll = PositionalArguments.DequeueOrDefault(); if (dll == null || !File.Exists(dll)) { throw new ExitException("Assembly file (dll) must be specified"); } assemblies.Add(dll); } new Runner().Execute(pch, assemblies); }
protected override void Run() { base.Run(); var pchFile = PositionalArguments.DequeueOrDefault(); string xmPath = PositionalArguments.DequeueOrDefault(); if (pchFile == null || !File.Exists(pchFile)) { throw new ExitException("PCH file must be specified"); } if (xmPath == null || !File.Exists(xmPath)) { throw new ExitException("Xamarin.Mac Assembly must be specified"); } XamarinMacAssembly = Assembly.LoadFrom(xmPath); if (XamarinMacAssembly == null) { throw new ExitException("Unable to load Xamarin.Mac Assembly"); } var reader = new AstReader(); reader.TranslationUnitParsed += tu => tu.Accept(new PropertyGetSetMismatchVisitor()); reader.TranslationUnitParsed += tu => tu.Accept(new PropertyArgumentSemanticVisitor()); if (!reader.Load(pchFile)) { throw new ExitException("PCH file failed to load"); } }
public ArgParser(string[] arguments) { foreach (var arg in arguments) { if (arg.StartsWith("-")) { Flags.Add(arg); } else { PositionalArguments.Add(arg); } } }
public ParsedCommandLine Merge ( [NotNull] ParsedCommandLine other ) { Code.NotNull(other, "other"); PositionalArguments.AddRange(other.PositionalArguments); foreach (CommandLineSwitch otherSwitch in other.Switches) { AddSwitch(otherSwitch); } return(this); }
/// <summary> /// Add an argument with the specified properties to the argument parser. /// </summary> /// <param name="name">Name of the argument. If this name starts with the "-" prefix then it will be an optional argument, else it will be a positional argument.</param> /// <param name="longName">Longer (not necessarily) name of an optional argument, an alias. It can be used for positional arguments, it would only change the key value in the namespace.</param> /// <param name="action">Action of an optional argument.</param> /// <param name="defaultValue">Default value of an optional argument if it is not supplied. Default value is `null` by default.</param> /// <param name="choices">A list of strings indicating the only selectable options for an argument. An error will be thrown if the provided values is not in the list of choices.</param> /// <param name="required">Determines is an optional argument is required to be supplied. Can be used for positional arguments too but it won't effect anything.</param> /// <param name="help">Help string to be printed in the help message for the argument. It is empty by default.</param> /// <param name="constant">Constant value for the argument. This parameter only works for arguments with `StoreConst` and `AppendConst` actions.</param> public void AddArgument(string name, string longName = null, ArgumentAction action = ArgumentAction.Store, object defaultValue = null, List <string> choices = null, bool required = false, string help = "", object constant = null) { if (name.Contains(" ")) { throw new InvalidArgumentNameException("An argument name can't contain spaces."); } Argument arg = new Argument(name, longName: longName, action: action, defaultValue: defaultValue, choices: choices, required: required, help: help, constant: constant); arguments.Add(arg); if (arg.Name.IsOptionalArgument()) { Categories[optionalArgsTitle].Add(arg); OptionalArguments.Add(arg); } else { Categories[positionalArgsTitle].Add(arg); PositionalArguments.Add(arg); } }
public void Add <TPositional, TArg>(PositionalBase <TConfig, TPositional, TArg> positional) where TPositional : PositionalBase <TConfig, TPositional, TArg> { PositionalArguments.Add(positional.Arg); }