예제 #1
0
 private static string getError(OutputMessages pMessages, Description pDescription, eERROR pError)
 {
     using (StringWriter sw = new StringWriter())
     {
         Console.SetError(sw);
         pMessages.Error(pDescription, pError);
         return sw.ToString().Trim();
     }
 }
예제 #2
0
        public void Request_0()
        {
            Description desc = new Description("filename", "the filename", eROLE.PASSED, new ParamString(), eSCOPE.REQUIRED, eMULTIPLICITY.ONCE);
            ArgumentPassed passed = new ArgumentPassed(0,"document.txt");

            Request r = new Request(new[]{passed},new[]{desc});

            // ensure description is attached to argument
            Assert.IsNotNull(passed.Desc);
        }
예제 #3
0
        public void Error_1()
        {
            MockOutput mock = new MockOutput();
            OutputMessages output = new OutputMessages(CliOptions.WindowsStyle, mock);

            Description desc = new Description("width", "The rectangle width", eROLE.NAMED, new ParamString(),
                eSCOPE.REQUIRED,
                eMULTIPLICITY.ONCE);

            const eERROR unsupported = (eERROR)(-1);
            output.Error(desc, unsupported);
        }
예제 #4
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");
        }
예제 #5
0
        public void Error_0()
        {
            Description desc = new Description("width", "The rectangle width", eROLE.NAMED, new ParamString(),
                eSCOPE.REQUIRED,
                eMULTIPLICITY.ONCE);

            MockOutput mock = new MockOutput();
            OutputMessages messages = new OutputMessages(CliOptions.WindowsStyle, mock);

            mock.Clear();
            messages.Error(desc, eERROR.REQUIRED);
            CollectionAssert.AreEqual(new[]{"GemsCLI: option '/width' is required."}, mock.getLines());

            mock.Clear();
            messages.Error(desc, eERROR.DUPLICATE);
            CollectionAssert.AreEqual(new[]{"GemsCLI: option '/width' can only be used once."}, mock.getLines());

            mock.Clear();
            messages.Error(desc, eERROR.MISSING_VALUE);
            CollectionAssert.AreEqual(new[]{"GemsCLI: option '/width' is missing value."}, mock.getLines());
        }
예제 #6
0
        /// <summary>
        /// Displays a parameter description.
        /// </summary>
        /// <param name="pMaxNameWidth">Width of the name column.</param>
        /// <param name="pDesc">The parameter description to display.</param>
        private void Display(int pMaxNameWidth, Description pDesc)
        {
            int max = pMaxNameWidth + _options.Prefix.Length;

            string padding = new String(' ', max);
            const int chunkSize = 80;

            string[] lines = SplitByLength(pDesc.Help, chunkSize).ToArray();

            for (int i = 0; i < lines.Length; i++)
            {
                string format = i == 0 ? @"  {0} {1}" : "  {2} {1}";

                string name = (pDesc.Role == eROLE.NAMED ? _options.Prefix : "") +
                              pDesc.Name +
                              (pDesc.Scope == eSCOPE.OPTIONAL ? "*" : "");

                _output.Standard(string.Format(format,
                    name.PadRight(max),
                    lines[i],
                    padding));
            }
        }