yarnpkg / yarnpkg/berry

[Feature] CLI autocomplete

Open
#512 14 comments 22 reactions 1 assignee View on GitHub

@paul-soporan is already working on this.

Since May 25, 2021.

enhancement help wanted
Dominant language
TypeScript
Stars
8.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Describe the user story

I'm a user and I'd like to type my commands faster by using my shell's auto-complete features.

Describe the solution you'd like

This is half a feature request for Clipanion, the CLI framework that we use (and that I wrote) to power Yarn's CLI.

I think the best would be to extend Clipanion in order to support a new function called omelette, which would generate a tree similar to the one that Omelette consumes:

omelette('hello').tree({
  how: {
    much: {
      is: {
        this: ['car'],
        that: ['house'],
      }
    }
    are: ['you'],
    many: ['cars', 'houses'],
  },
  where: {
    are: {
      you: ['from'],
      the: ['houses', 'cars'],
    },
    is: {
      // You can also add some logic with defining functions:
      your() {
        return ['house', 'car'];
      },
    }
  },
}).init()

Since Clipanion already operates with a kind of tree (which is then turned into a state machine), it should be fairly easy. The hardest part would likely be to find a way to power dynamic segments, such as package names. This is likely to be a followup task, though - having command names and options would already be a decent improvement.

Describe the drawbacks of your solution

It might prove more complex from an architectural standpoint than I expect.

Describe alternatives you've considered

We could let third-party write autocompletion scripts (which is what we've been doing for the duration of the v1), but now that we have a decent CLI framework that we control I think there's a lot we could do to improve the program UX. For example, typing yarn add typescript@<tab> and get offered the versions that yarn add -i would suggest.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.