withfig / autocomplete

IDE-style autocomplete for your existing terminal & shell

Home Page:https://fig.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support SFDX Plugin Autocompletes with Fig Tooling

crazynammer opened this issue Β· comments

Sanity checks

Feature Details

Description:

Please include a detailed description of the feature (and an image or screen recording, if applicable)

For the following CLI tool from Salesforce, it would be nice to add support for autocomplete for the plugins as well that get installed instead of just the main SFDX CLI.

image

image

image

Main CLI - sfdx -h


Salesforce CLI

VERSION
  sfdx-cli/7.165.0 darwin-arm64 node-v18.8.0

USAGE
  $ sfdx [COMMAND]

TOPICS
  alias           manage username aliases
  auth            authorize an org for use with the Salesforce CLI
  config          configure the Salesforce CLI
  force           tools for the Salesforce developer
  info            access cli info from the command line
  org             guided workflows to help with developer orgs
  package         helpers to deal with packages in your project
  plugins         add/remove/create CLI plug-ins
  sfdmu           The Salesforce DX data migration tool.
  sfpowerkit      Salesforce DevOps Helper Extensions to use in CI/CD Pipelines
  sfpowerscripts  An opinionated salesforce build system (statsd metrics enabled) as a sfdx plugin that can be
                  implemented in any CI/CD system of choice
  version

COMMANDS
  autocomplete  display autocomplete installation instructions
  commands      list all the commands
  help          Display help for sfdx.
  init          intializes the project with various defaults
  org           guided workflows to help with developer orgs
  package       helpers to deal with packages in your project
  plugins       List installed plugins.
  sync          sync changes effortlessly either with repository or development environment
  update        update the sfdx CLI
  version
  whatsnew      Display Salesforce CLI release notes on the command line.
  which         Show which plugin a command is in.
  work          create/switch/submit a workitem

Plugins - Example - sfpowerscripts

sfdx sfpowerscripts -h
An opinionated salesforce build system (statsd metrics enabled) as a sfdx plugin that can be implemented in any CI/CD system of choice

USAGE
  $ sfdx sfpowerscripts:COMMAND

TOPICS
  sfpowerscripts:analyze            Analyze your projects using static analysis tools such as PMD
  sfpowerscripts:apextests          Trigger Apex Tests and validate apex tests in a package
  sfpowerscripts:artifacts          Fetch artifacts from an artifact registry that is either NPM compatible or supports universal
                                    artifacts
  sfpowerscripts:changelog          Track your artifacts & user stories as they progress through different environments, with
                                    release changelogs
  sfpowerscripts:orchestrator       Orchestrate packages from a monorepo through its lifecycle, driven by descriptors in your
                                    sfdx-project.json
  sfpowerscripts:package            Work with various types of packages such as unlocked/source/data/delta individually
  sfpowerscripts:pool               Manage the pooled orgs created by the sfpowerscripts orchestrator in prepare stage
  sfpowerscripts:releasedefinition  Commands around release definition

@separaterecords - Hi Robert, just checking to see if you were able to look into this feature request and if it would be available anytime soon as an update?

Was able to look into it, turns out it's a lot more complicated than I thought it would be! Still thinking of the best way to go about it.

  • Twilio doesn't support plugins at all at the moment
  • Git supports some plugins (git open, git flow) but the completions are hard-coded
  • Cargo supports some plugins, but like git, support is hardcoded

Ideally the completions would be generated at runtime, because there's no possible way we could know all the plugins available ahead of time.


Although, in writing this, I just realized: we could make a fig plugin for SFDX that generates the spec! This is probably the way we'll do it, because it allows the spec to be generated at runtime with total knowledge of all available topics/commands/args

# something like
sfdx plugins:install @fig/sfdx

That would be great if there were an additional @fig/sfdx to list and generated all the users local installed plugins to enable autocomplete. Let me know if you have any specific questions around SFDX as I use it daily and have a network of colleagues to help answer some questions as needed.

@separaterecords Any chance to prioritize this feature request in upcoming releases yet?

Will do my best to! Still on my radar but lots more stuff to get on top of first (we're a startup, always a million tasks πŸ˜„)

I've done some thinking about it and here's what I've landed on.

  • We'll create an sfdx plugin to generate a fig spec
    • as far as I know we already have most of the logic for this in place, it's mostly just hooking it up as a plugin
  • It will automagically save it to your fig account using our "private autocomplete" feature, allowing you to override official specs

Very time constrained this week, will aim to get it done next week.

Would this be an alright style of command? Not sure of the norms for how you'd structure it with sfdx

sfdx fig:generate --publish

Sounds good. After running the command sfdx fig:generate --publish, is the assumption it would loop through existing other plugins to populate the autocomplete or would I have to provide that list of commands and modify my own account settings to get it working and update as the other sfdx plugins update? I could see the latter as less preferred as plugins typically evolve quickly in the sfdx ecospace.

My general plan is that it would use some introspection to find what subcommands, options, and args are available. The --publish flag would make it essentially the equivalent of npx @fig/publish-spec --spec-path <(sfdx fig:generate). Can be re-run whenever to update your local completions.

We can also totally do it differently and make it possible to select the plugins to generate for! I would lean towards "run the command whenever plugins change" but I'm not an sfdx user myself so I'll trust your judgement

Yes, most of the time, users will run sfdx plugins:update once in awhile if there are known updates for the plugins and then my expectation is if they are fig users, they would run the sfdx fig:generate --publish command right after to refresh to ensure all their autocomplete shortcuts are updated.

Let me know when the item is ready to test and I can go ahead and test on my commands. Thanks!

Here is some documentation related to the existing built in autocomplete feature for sfdx. They don't support windows so this type of tooling would be welcomed if worked on both Mac and Windows for Fig.

Fantastic, thank you so much for all the resources! πŸ˜„

Proof of concept: βœ…

CleanShot 2022-10-10 at 11 57 04@2x

Alright, you should now be able to run sfdx plugins:install @fig/sfdx, then run sfdx fig:generate -p (or --publish for long option), then restart fig πŸ™‚

Also, you can manage your published completions through the fig interface. Publish isn't really the right word, since they're private and exclusive to you.

CleanShot 2022-10-10 at 14 19 57@2x

Sounds good I'll try and provide some feedback. Thanks for getting this done so quickly.

Going to close this issue now but happy to work on this more if you have any feedback πŸ™‚