Exemple #1
0
        // PARAMETER AUTOCOMPLETE
        private void AutoCompleteParameter()
        {
            int             index     = _cmdComponentsIndex;
            string          paramSeed = _cmdComponents[index].Contents.Replace(" -", "");
            CommandItemType result    = CommandItemType.Undefined;

            while (CommandItemType.Command != result)
            {
                result = _cmdComponents[--index].Type;
            }
            _processor.ExecutePSCommand("(Get-Command " +
                                        _cmdComponents[index].Contents + ").Parameters.Keys | Where{$_ -like '" + paramSeed + "*'}");
            return;
        }
Exemple #2
0
        internal void Process(ConsoleKeyInfo keyInfo, ref CommandItemType loopType)
        {
            if (CommandItemType.Undefined == loopType)
            {
                _cmdComponents = CaptureCommandComponents();
                // route to appropriate autcomplete handler
                switch (loopType = CurrentComponent.Type)
                {
                case CommandItemType.Parameter:
                    AutoCompleteParameter();
                    break;

                case CommandItemType.Variable:
                    AutoCompleteVariable();
                    break;

                case CommandItemType.Path:
                    AutoCompletePath();
                    break;

                default:
                    AutoCompleteCommand();
                    break;
                }
            }
            // If we're already in an autocomplete loop, increment loopPos appropriately
            else
            {
                _processor.MoveCurrentHistoryPosition(ConsoleModifiers.Shift == keyInfo.Modifiers);
            }

            // if we have results, format them and return them
            if (_processor.HasResults)
            {
                string   separator = " ";
                string   result;
                PSObject currentObject = _processor.CurrentResult;
                switch (loopType)
                {
                case CommandItemType.Parameter:
                    separator = " -";
                    result    = currentObject.ToString();
                    break;

                case CommandItemType.Variable:
                    separator = " $";
                    result    = currentObject.Members["Name"].Value.ToString();
                    break;

                case CommandItemType.Path:
                    separator = " ";
                    result    = "\"" + currentObject.Members["FullName"].Value.ToString() + "\"";
                    break;

                default:
                    result = currentObject.BaseObject.ToString();
                    break;
                }
                // reconstruct display cmd from components
                string completedCmd = string.Empty;
                int    cursorPos    = _display.Prompt.Length;
                for (int i = 0; i < _cmdComponents.Count(); i++)
                {
                    if (i == _cmdComponentsIndex)
                    {
                        completedCmd += separator + result;
                        cursorPos    += completedCmd.TrimStart().Length;
                    }
                    else
                    {
                        completedCmd += _cmdComponents[i].Contents;
                    }
                }
                _display.SetDisplayedCommand(completedCmd.TrimStart());
            }
            return;
        }
 public static bool LoadFromFile(string fileName, out CommandItemType obj) {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
 /// <summary>
 /// Deserializes xml markup from file into an CommandItemType object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output CommandItemType object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out CommandItemType obj, out System.Exception exception) {
     exception = null;
     obj = default(CommandItemType);
     try {
         obj = LoadFromFile(fileName);
         return true;
     }
     catch (System.Exception ex) {
         exception = ex;
         return false;
     }
 }
 public static bool Deserialize(string xml, out CommandItemType obj) {
     System.Exception exception = null;
     return Deserialize(xml, out obj, out exception);
 }
 /// <summary>
 /// Deserializes workflow markup into an CommandItemType object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output CommandItemType object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out CommandItemType obj, out System.Exception exception) {
     exception = null;
     obj = default(CommandItemType);
     try {
         obj = Deserialize(xml);
         return true;
     }
     catch (System.Exception ex) {
         exception = ex;
         return false;
     }
 }