Example #1
0
 public SubCommand(
     long token,
     ISubCommand subCommand
     )
     : base(token)
 {
     this.subCommand = subCommand;
 }
Example #2
0
        /// <summary>
        /// Add a command to the list of commands.
        /// </summary>
        /// <remarks>
        /// This must be called before the first call to Parse().
        /// </remarks>
        /// <param name="command">The command to add.</param>
        public void AddCommand(ISubCommand command)
        {
            if (_initialized)
            {
                throw new InvalidOperationException("Cannot add a command after Parse has been called.");
            }

            _commands.Add(command);
        }
Example #3
0
        private void BuildNuGetEncryptCommand(ISubCommand parent)
        {
            parent.NewSubCommand("keyEncrypt", "Encryps a NuGet Repo Api Key")
            .Build((cmd, arg, opt) =>
            {
                var key = arg.SingleValue("key", "The key to encrypt");

                cmd.OnExecute(() => _controller.Encrypt(key.Value).ToInteger());
            });
        }
Example #4
0
        ///////////////////////////////////////////////////////////////////////

        public virtual ReturnCode AddOrUpdateSubCommand(
            string name,
            ISubCommand subCommand,
            IClientData clientData,
            SubCommandFlags flags,
            ref Result error
            )
        {
            error = "not implemented";
            return(ReturnCode.Error);
        }
Example #5
0
        public void BuildPunditToNuGet(ISubCommand parent)
        {
            parent.NewSubCommand("PunditToNuGet", "Converts a Pundit Package to a NuGet Package")
            .Build((cmd, arg, opt) =>
            {
                var source = arg.SingleValue("sourceFile", "The NuGet Package file to convert");
                var output = opt.SingleValue("o", "output", "directory", "Specifies the output directory for the converted file(s)");

                cmd.OnExecute(() => _controller.PunditToNuGet(source.Value, output.Value).ToInteger());
            });
        }
Example #6
0
        public void BuildNuGetToPundit(ISubCommand parent)
        {
            parent.NewSubCommand("NuGetToPundit", "Converts a NuGet Package to a Pundit Package")
            .Build((cmd, arg, opt) =>
            {
                var source    = arg.SingleValue("sourceFile", "The NuGet Package file to convert");
                var output    = opt.SingleValue("o", "output", "directory", "Specifies the output directory for the converted file(s)");
                var framework = opt.SingleValue("f", "framework", "version", "The framework version to use. Default, convert all");

                cmd.OnExecute(() => _controller.NuGetToPundit(source.Value, output.Value, framework.Value).ToInteger());
            });
        }
Example #7
0
        public void Push(ISubCommand command)
        {
            // WriteDebugInfo();

            var type = command.GetType();

            // TODO - reset all values to their defaults?
            // TODO - initialize collections to empty?

            foreach (var item in _result.CommandValues)
            {
                var prop = type.GetProperty(item.Name);

                if (prop == null)
                {
                    throw new CommandLineParserException("Property mismatch: command does not contain property with name '" + item.Name + "'.");
                }

                TypeConverter typeConverter = TypeDescriptor.GetConverter(prop.PropertyType);
                object propValue = typeConverter.ConvertFromString(item.Value);
                prop.SetValue(command, propValue);
            }

            foreach (var item in _result.CommandListValues)
            {
                var prop = type.GetProperty(item.Name);

                if (prop == null)
                {
                    throw new CommandLineParserException("Property mismatch: command does not contain property with name '" + item.Name + "'.");
                }

                if (prop.PropertyType == typeof (List<string>))
                {
                    var list = ((List<string>)prop.GetValue(command));

                    // TODO - if collections are being initialized, we can skip this check
                    if (list == null)
                    {
                        list = new List<string>();
                        prop.SetValue(command, list);
                    }

                    list.AddRange(item.Values);
                }
                else
                {
                    throw new NotImplementedException("Collections other than List<string> are not yet handled.");
                }
            }
        }
Example #8
0
        ///////////////////////////////////////////////////////////////////////

        public virtual ReturnCode AddOrUpdateSubCommand(
            string name,
            ISubCommand subCommand,
            IClientData clientData,
            SubCommandFlags flags,
            ref Result error
            )
        {
            if (name == null)
            {
                error = "invalid sub-command name";
                return(ReturnCode.Error);
            }

            EnsembleDictionary subCommands = this.SubCommands;

            if (subCommands == null)
            {
                error = "sub-commands not available";
                return(ReturnCode.Error);
            }

            if ((subCommand == null) &&
                FlagOps.HasFlags(flags, SubCommandFlags.Core, true))
            {
                subCommand = GetCoreSubCommand();
            }

            subCommands[name] = subCommand;

            if (subCommand != null)
            {
                EnsembleDictionary subSubCommands = subCommand.SubCommands;

                if (subSubCommands != null)
                {
                    subSubCommands[name] = subCommand;
                }
            }

            return(ReturnCode.Ok);
        }
Example #9
0
 /// <summary>
 /// Tries the get command.
 /// </summary>
 /// <param name="name">The name.</param>
 /// <param name="command">The command.</param>
 /// <returns></returns>
 public abstract bool TryGetCommand(string name, out ISubCommand <TWebSocketSession> command);
 public TMetadata GetSubmenuMetadata <TMetadata>(ISubCommand subCommand) where TMetadata : ISubMainMenuMetadata
 {
     return(subCommand.Metadata.OfType <SubMainMenuOption>().Single().OfType <TMetadata>().SingleOrDefault());
 }
Example #11
0
        private IEnumerable <ICommand> doLoad(string filename)
        {
            if (!System.IO.File.Exists(filename))
            {
                throw new ArgumentException(String.Format("File is missing \"{0}\"", filename));
            }

            List <ICommand> results = new List <ICommand>();

            XmlDocument document = new XmlDocument();

            document.Load(filename);
            XmlNode xmlNodeCommands = document.SelectSingleNode("Commands");

            foreach (XmlNode child in xmlNodeCommands.ChildNodes)
            {
                XmlNode xmlNodeCommand = child.SelectSingleNode("Command");
                if (xmlNodeCommand == null)
                {
                    Trace.TraceInformation(String.Format("Missing \"Command\" node in node {0}, ignoring it", child.Name));
                    continue;
                }

                XmlNode xmlNodeName = xmlNodeCommand.Attributes.GetNamedItem("Name");
                if (xmlNodeName == null)
                {
                    Trace.TraceInformation(
                        String.Format("Missing \"Name\" attribute in \"Command\" node of node {0}, ignoring this command",
                                      child.Name));
                    continue;
                }

                List <ISubCommand> subcommands = new List <ISubCommand>();
                foreach (XmlNode obj in xmlNodeCommand.ChildNodes)
                {
                    if (obj == null)
                    {
                        Trace.TraceInformation(
                            String.Format("No child nodes in \"Command\" node of node {0}, ignoring this command", child.Name));
                        continue;
                    }

                    ISubCommand subcommand = null;
                    if (obj.Name == "SendNote")
                    {
                        subcommand = createSendNoteCommand(obj.Attributes);
                    }
                    else if (obj.Name == "MergeRequestEndPointPOST")
                    {
                        subcommand = createEndPointPOSTCommand(obj.Attributes);
                    }
                    else if (obj.Name == "AddLabelToMergeRequest")
                    {
                        subcommand = createAddLabelToMergeRequestCommand(obj.Attributes);
                    }
                    else
                    {
                        Trace.TraceInformation(
                            String.Format("Unknown action type \"{0}\" in node {1}, ignoring this command", obj.Name, child.Name));
                    }

                    if (subcommand != null)
                    {
                        subcommands.Add(subcommand);
                    }
                }

                if (subcommands.Count > 0)
                {
                    results.Add(createCompositeCommand(subcommands, xmlNodeCommand.Attributes, xmlNodeName.Value));
                }
            }

            return(results);
        }