private void WriteCommandDefineOptionAndArguments(TextWriter writer, CommandDescriptor command) { foreach (var option in command.Options.OfType <ICommandOptionDescriptor>().Concat(command.OptionLikeCommands).Where(x => !x.Flags.HasFlag(CommandOptionFlags.Hidden))) { writer.WriteLine($" __cocona_{_appName}_completion_define_option \"--{option.Name}\" \"{FromOptionToCandidatesType(option)}\""); } foreach (var arg in command.Arguments) { writer.WriteLine($" __cocona_{_appName}_completion_define_argument \"{arg.Name}\" \"{FromArgumentToCandidatesType(arg)}\""); } string FromOptionToCandidatesType(ICommandOptionDescriptor option) { if (option is CommandOptionDescriptor commandOption) { if (commandOption.OptionType == typeof(bool)) { return("bool"); } else { var candidates = _completionCandidates.GetStaticCandidatesFromOption(commandOption); if (candidates.IsOnTheFly) { return($"onthefly:{option.Name}"); } else { return(candidates.Result !.ResultType switch { CompletionCandidateResultType.Default => "default", CompletionCandidateResultType.File => "file", CompletionCandidateResultType.Directory => "directory", CompletionCandidateResultType.Keywords => $"keywords:{string.Join(":", candidates.Result!.Values.Select(x => x.Value))}", _ => "default", }); }
private string GetArgumentValues(CommandOptionDescriptor option) { return(GetArgumentValuesCore(_completionCandidates.GetStaticCandidatesFromOption(option), option.Name)); }