Esempio n. 1
0
        private IList <string> DetermineMissingRequiredCommands(IList <CommandArgument> dispatchedCommands)
        {
            IList <string> missing = new List <string>();

            //
            // figure out which arguments are required
            //
            var required =
                this.arguments.Where(a =>
                                     CommandArgumentFlags.FlagEnabled(a.Flags, CommandArgumentFlags.Required)).ToList();

            if (required.Count > 0)
            {
                //
                // if we actually have some required arguments, then some might
                // not have been dispatched, which means they're missing
                //
                foreach (var requiredCommand in required)
                {
                    if (!dispatchedCommands.Contains(requiredCommand))
                    {
                        missing.Add(requiredCommand.LongName);
                    }
                }
            }

            return(missing);
        }
Esempio n. 2
0
        private string GetUsageString(string appName)
        {
            var sb = new StringBuilder();

            //
            // usage start
            //
            sb.Append("Usage: ");
            sb.Append(appName);
            sb.Append(' ');

            //
            // required arguments
            //
            var required = this.arguments.Where(a =>
                                                CommandArgumentFlags.FlagEnabled(a.Flags, CommandArgumentFlags.Required) &&
                                                CommandArgumentFlags.FlagDisabled(a.Flags, CommandArgumentFlags.HideInUsage)).ToList();

            if (required.Count > 0)
            {
                AppendArgumentsToUsage(sb, required);
            }

            //
            // optional arguments
            //
            var optional = this.arguments.Where(a =>
                                                CommandArgumentFlags.FlagDisabled(a.Flags, CommandArgumentFlags.Required) &&
                                                CommandArgumentFlags.FlagDisabled(a.Flags, CommandArgumentFlags.HideInUsage)).ToList();

            if (optional.Count > 0)
            {
                sb.Append(" [");
                AppendArgumentsToUsage(sb, optional);
                sb.Append("]");
            }

            return(sb.ToString());
        }
Esempio n. 3
0
        private void AppendArgumentsToUsage(StringBuilder sb, IList <CommandArgument> arguments)
        {
            foreach (var opt in arguments)
            {
                sb.Append(GetCommandDisplayName(opt.Name));
                if (CommandArgumentFlags.FlagEnabled(opt.Flags, CommandArgumentFlags.TakesParameter))
                {
                    if (!String.IsNullOrEmpty(opt.ParameterName))
                    {
                        sb.Append(" <");
                        sb.Append(opt.ParameterName);
                        sb.Append(">");
                    }
                    else
                    {
                        sb.Append(" <arg>");
                    }
                }

                sb.Append(' ');
            }

            sb.Remove(sb.Length - 1, 1);
        }