public BashCoconaShellCompletionCodeGenerator( ICoconaApplicationMetadataProvider applicationMetadataProvider, ICoconaCompletionCandidates completionCandidates ) { _appName = Regex.Replace(applicationMetadataProvider.GetProductName(), "[^a-zA-Z0-9_]", "__"); _appCommandName = applicationMetadataProvider.GetExecutableName(); _completionCandidates = completionCandidates; }
// --completion-candidates <shell>:<paramName> -- <incompleted command line...> // WARN: The option must be processed before '--help' or '--version' options. // If '--completion-candidates' option is provided, '--help' and '--version' options are also always provided. // And these options prevent to perform unintended **destructive** action if the command doesn't support on-the-fly candidates feature. // Fortunately, Cocona rejects unknown options by default. This options guard is fail-safe. public ValueTask <int> GetCompletionCandidates( [FromService] ICoconaConsoleProvider console, [FromService] ICoconaShellCompletionCodeProvider shellCompletionCodeGenerator, [FromService] ICoconaCompletionCandidates completionCandidates, [Argument] string target, [Argument] string[] arguments ) { var parts = target.Split(new[] { ':' }, 2); var(shellTarget, paramName) = (parts[0], parts[1]); var candidates = completionCandidates.GetOnTheFlyCandidates(paramName, arguments, 0, null); shellCompletionCodeGenerator.GenerateOnTheFlyCandidates(shellTarget, console.Output, candidates); return(new ValueTask <int>(0)); }