Exemplo n.º 1
0
        /// <summary>
        /// Called when a validation fails on the parameters.
        /// </summary>
        /// <param name="pDesc">The description of the failed parameter.</param>
        /// <param name="pError">The type of error.</param>
        public void Error(Description pDesc, eERROR pError)
        {
            switch (pError)
            {
            case eERROR.REQUIRED:
                _output.Error(OutputFormatter.WriteRequired(pDesc.Role, _options.Prefix, pDesc.Name));
                return;

            case eERROR.DUPLICATE:
                _output.Error(OutputFormatter.WriteDuplicate(pDesc.Role, _options.Prefix, pDesc.Name));
                return;

            case eERROR.MISSING_VALUE:
                _output.Error(OutputFormatter.WriteMissingValue(pDesc.Role, _options.Prefix, pDesc.Name));
                return;
            }

            throw new InvalidArgumentException("Unsupported error type");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Displays command line usage.
        /// </summary>
        public void Show(ICollection <Description> pDescriptions)
        {
            string namedUsage  = getNamedUsage(pDescriptions);
            string passedUsage = getPassedUsage(pDescriptions);

            _output.Standard(string.Format(Properties.Help.Usage, OutputFormatter.ExecutableName(), namedUsage,
                                           passedUsage));

            int maxNameWidth = getMaxNameWidth(pDescriptions);

            if (pDescriptions.FirstOrDefault(pDesc => pDesc.Role == eROLE.NAMED) != null)
            {
                _output.Standard("");
                _output.Standard(Properties.Help.Options);
                _output.Standard("");
                foreach (Description desc in from desc in pDescriptions where desc.Role == eROLE.NAMED select desc)
                {
                    Display(maxNameWidth, desc);
                }
            }

            if (pDescriptions.FirstOrDefault(pDesc => pDesc.Role == eROLE.PASSED) != null)
            {
                _output.Standard("");
                foreach (Description desc in from desc in pDescriptions where desc.Role == eROLE.PASSED select desc)
                {
                    Display(maxNameWidth, desc);
                }
            }

            if (pDescriptions.FirstOrDefault(pDesc => pDesc.Scope == eSCOPE.OPTIONAL) != null)
            {
                _output.Standard("");
                _output.Standard(Properties.Help.Optional);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Called when an argument is not recognized.
 /// </summary>
 /// <param name="pUnknown">The unknown argument.</param>
 public void Unknown(Argument pUnknown)
 {
     _output.Error(OutputFormatter.WriteUnknown(pUnknown.Value));
 }