コード例 #1
0
        /// <summary>
        /// Returns a command info for a given command name and type, using the specified arguments
        /// to resolve dynamic parameters.
        /// </summary>
        /// <param name="commandName">The command name to search for.</param>
        /// <param name="type">The command type to search for.</param>
        /// <param name="arguments">The command arguments used to resolve dynamic parameters.</param>
        /// <returns>A CommandInfo result that represents the resolved command.</returns>
        public CommandInfo GetCommand(string commandName, CommandTypes type, object[] arguments)
        {
            CommandInfo result = null;

            try
            {
                CommandOrigin commandOrigin = CommandOrigin.Runspace;
                if (_cmdlet != null)
                {
                    commandOrigin = _cmdlet.CommandOrigin;
                }
                else if (_context != null)
                {
                    commandOrigin = _context.EngineSessionState.CurrentScope.ScopeOrigin;
                }

                result = CommandDiscovery.LookupCommandInfo(commandName, type, SearchResolutionOptions.None, commandOrigin, _context);

                if ((result != null) && (arguments != null) && (arguments.Length > 0))
                {
                    // We've been asked to retrieve dynamic parameters
                    if (result.ImplementsDynamicParameters)
                    {
                        result = result.CreateGetCommandCopy(arguments);
                    }
                }
            }
            catch (CommandNotFoundException) { }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Exact match an alias help target.
        /// </summary>
        /// <remarks>
        /// This will
        ///     a. use _commandDiscovery object to retrieve AliasInfo object.
        ///     b. Create AliasHelpInfo object based on AliasInfo object
        /// </remarks>
        /// <param name="helpRequest">Help request object.</param>
        /// <returns>Help info found.</returns>
        internal override IEnumerable <HelpInfo> ExactMatchHelp(HelpRequest helpRequest)
        {
            CommandInfo commandInfo = null;

            try
            {
                commandInfo = _commandDiscovery.LookupCommandInfo(helpRequest.Target);
            }
            catch (CommandNotFoundException)
            {
                // CommandNotFoundException is expected here if target doesn't match any
                // commandlet. Just ignore this exception and bail out.
            }

            if ((commandInfo != null) && (commandInfo.CommandType == CommandTypes.Alias))
            {
                AliasInfo aliasInfo = (AliasInfo)commandInfo;

                HelpInfo helpInfo = AliasHelpInfo.GetHelpInfo(aliasInfo);
                if (helpInfo != null)
                {
                    yield return(helpInfo);
                }
            }
        }
コード例 #3
0
        public CommandInfo GetCommand(string commandName, CommandTypes type)
        {
            CommandInfo info = null;

            try
            {
                CommandOrigin runspace = CommandOrigin.Runspace;
                if (this._cmdlet != null)
                {
                    runspace = this._cmdlet.CommandOrigin;
                }
                info = CommandDiscovery.LookupCommandInfo(commandName, type, SearchResolutionOptions.None, runspace, this._context);
            }
            catch (CommandNotFoundException)
            {
            }
            return(info);
        }