void AddCommandSyntax(Suggestion suggestion, CommandLineParser parser, string commandName) { suggestion.Add(commandName + " " + string.Join(" ", parser.RequiredUsageHelp.Select(o => "<" + o.Name + ">" + (o.IsList?"[...]":""))) + " " + string.Join("", parser.OptionalUsageHelp.Select(o => "[/" + o.Value.Name + "]")) ); }
void DetailedCommandHelp(Suggestion suggestion, CommandLineParser parser, string commandName) { suggestion.Add(commandName); suggestion.Add(""); suggestion.Add("required : "); foreach (var option in parser.RequiredUsageHelp) { suggestion.Add(string.Format(" {0,-20} {1}", "<" + option.Name + ">", option.Description)); } suggestion.Add(""); suggestion.Add("options : "); foreach (var option in parser.OptionalUsageHelp.Select(p => p.Value).OrderBy(n => n.Name)) { suggestion.Add(string.Format(" /{0,-20} {1}", option.Name, option.Description)); } }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <param name="candidates"></param> /// <param name="suggestions">Null if no suggestions</param> /// <returns></returns> public Suggestion AutoComplete ( string input ) { if (string.IsNullOrWhiteSpace(input)) { return new Suggestion(""); } var suggestion = new Suggestion(input); var args = CommandLineParser.SplitCommandLine( input ).ToArray(); var cmd = args[0]; var cmdList = CommandList .ToList(); var varList = variables.Select( a => a.Value ) .OrderBy( b => b.FullName ) .ToList(); string longestCommon = null; int count = 0; // // search commands : // foreach ( var name in cmdList ) { if (cmd.ToLower()==name.ToLower()) { return AutoCompleteCommand(input, args, name); } if (name.StartsWith(cmd, StringComparison.OrdinalIgnoreCase)) { longestCommon = LongestCommon( longestCommon, name ); suggestion.Set( longestCommon ); suggestion.Add( name ); count++; } } // // search variables : // foreach ( var variable in varList ) { if (cmd.ToLower()==variable.FullName.ToLower()) { return AutoCompleteVariable( input, args, variable ); } if (variable.FullName.StartsWith(cmd, StringComparison.OrdinalIgnoreCase)) { longestCommon = LongestCommon( longestCommon, variable.FullName ); suggestion.Set( longestCommon ); suggestion.Add( string.Format("{0,-30} = {1}", variable.FullName, variable.Get() ) ); count++; } } if (count==1) { suggestion.Set( suggestion.CommandLine + " "); } return suggestion; }