Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make it possible to customize completions for specific command and flags #91

Open
bartekpacia opened this issue Mar 20, 2024 · 2 comments
Labels
feature A new feature or request p3 Issues that we currently consider unimportant

Comments

@bartekpacia
Copy link

bartekpacia commented Mar 20, 2024

Description

I would like to have control over the completions that displayed for my command.

Let's say I have a command foo install <version>. This command also has 2 flags --dry-run and --help.

Current state

Only the flags are suggested:

$ foo install <TAB>
--help          -- Print this usage information.
--dry-run       -- Perform prechecks but do not install.

Expected state

$ foo install <TAB>
2.1.0
2.0.0
1.2.0
1.1.0
1.0.1
1.0.0

API idea:

/// Installs Flutter SDK
class InstallCommand extends CompletionCommand<int> {
  @override
  final name = 'install';

  @override
  final description = 'Installs foo version';

  /// Returns the string that will be returned when tab completion
  /// is called for this command.
  ///
  /// This method should return fast for good user experience.
  @override
  Future<String> completions() {
    print(MyFooVersionProvider.listAllVersions());
    // The above line would print:
    // 2.1.0
    // 2.0.0
    // 1.2.0
    // 1.1.0
    // 1.0.1
    // 1.0.0
  }

  @override
  Future<int> run() async { /** code **/ }

Additional Context

A similar CLI package in the Go ecosystem has this feature. See docs.

@bartekpacia
Copy link
Author

Cobra in the Go ecosystem also has this feature (link)

@alestiago
Copy link
Contributor

I don't think this is currently possible, so overall I like your suggestion. Are you interested in working on this? The API seems reasonable although we can adjust the nuts and bolts once we get into the first PR.

Nudging @wolfenrain and @renancaraujo in case they want to drop their two cents on this feature.

@tomarra tomarra added the p3 Issues that we currently consider unimportant label Oct 23, 2024
@tomarra tomarra moved this from Needs Triage to Backlog in VGV Open Source 🦄 🧙🌟 Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature or request p3 Issues that we currently consider unimportant
Projects
Status: Backlog
Development

No branches or pull requests

3 participants