예제 #1
0
        public void VerifyGetCommandAst(string input, string expected)
        {
            if (expected == null)
            {
                expected = input;
            }

            var commandAst = CommandLineUtilities.GetCommandAst(input);

            Assert.Equal(expected, commandAst.ToString());
        }
예제 #2
0
        private ParsedCommandLineHistory GetAstAndMaskedCommandLine(string commandLine)
        {
            var commandAst = CommandLineUtilities.GetCommandAst(commandLine);

            var    commandName       = commandAst?.CommandElements?.FirstOrDefault().ToString();
            bool   isSupported       = _service.IsSupportedCommand(commandName);
            string maskedCommandLine = CommandLineUtilities.MaskCommandLine(commandAst);

            return(new ParsedCommandLineHistory
            {
                Ast = commandAst,
                MaskedCommandLine = maskedCommandLine,
                IsSupported = isSupported
            });
        }
예제 #3
0
        /// <summary>
        /// Create a new instance of <see cref="CommandLine"/> from <see cref="PredictiveCommand" />.
        /// </summary>
        /// <param name="predictiveCommand">The command information.</param>
        /// <param name="azContext">The current PowerShell conext.</param>
        public CommandLine(PredictiveCommand predictiveCommand, IAzContext azContext = null)
        {
            Validation.CheckArgument(predictiveCommand, $"{nameof(predictiveCommand)} cannot be null.");

            var predictionText = CommandLineUtilities.EscapePredictionText(predictiveCommand.Command);
            var commandAst     = CommandLineUtilities.GetCommandAst(predictionText);
            var commandName    = commandAst?.GetCommandName();

            Validation.CheckInvariant <CommandLineException>(!string.IsNullOrWhiteSpace(commandName), $"Cannot get the command name from the model {predictiveCommand.Command}");

            var parameterSet = new ParameterSet(commandAst, azContext);

            Name         = commandName;
            Description  = predictiveCommand.Description;
            ParameterSet = parameterSet;
            SourceText   = predictiveCommand.Command;
        }