-
-
Notifications
You must be signed in to change notification settings - Fork 392
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
POC Dynamic shell completion for fqbn flag #1431
Conversation
be3f4a5
to
59f1a35
Compare
cli/compile/compile.go
Outdated
@@ -83,6 +84,10 @@ func NewCommand() *cobra.Command { | |||
} | |||
|
|||
command.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno")) | |||
command.MarkFlagRequired("fqbn") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This flag is not required due to the ability to define it in the sketch metadata via arduino-cli board attach
:
$ ./arduino-cli version
arduino-cli.exe alpha Version: 0.19.0 Commit: 56419ecd Date: 2021-09-02T14:47:35Z
$ ./arduino-cli sketch new /tmp/FooSketch
Sketch created in: C:\Users\per\AppData\Local\Temp\FooSketch
$ ./arduino-cli board attach arduino:avr:uno /tmp/FooSketch
Selected fqbn: arduino:avr:uno
$ ./arduino-cli compile /tmp/FooSketch
Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right, I thought about it later... I just wanted to experiment with MarkFlagRequired
function. We can use this somewhere else:
basically if you type completion <tab><tab>
the completion suggest at first only the required flags, so the user is prompted to use them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW I reverted it 😄
2cf6de9
to
e0b6a80
Compare
…sing <tab><tab> for better explanation see https://github.com/spf13/cobra/blob/master/shell_completions.md#mark-flags-as-required
…hen pressing <tab><tab>" This reverts commit cc81265.
e0b6a80
to
53a8a36
Compare
* make fqbn flag required, so that the completion suggests it when pressing <tab><tab> for better explanation see https://github.com/spf13/cobra/blob/master/shell_completions.md#mark-flags-as-required * use newer and supported bashv2 completion in order to have dynamic completion * add dynamic completion for `compile -b` command to list available board * Revert "make fqbn flag required, so that the completion suggests it when pressing <tab><tab>" This reverts commit cc81265. * make Internalization happy
Please check if the PR fulfills these requirements
before creating one)
our contributing guidelines
UPGRADING.md
has been updated with a migration guide (for breaking changes)Dynamic shell completion
Now the shell completion is only static and only works by completing sub-commands and flags hard-coded in the CLI code.
With cobra 1.2.0 they added dynamic shell completion for nouns and for flags (see here and here).
The goal of this Proof Of Concept PR is to implement the dynamic completion for the
arduino-cli compile --fqbn
flag and sub-command, by retrieving the list of the fqbn (similar toboard listall
command).In order to make this happen, I bumped the cobra dependency to the latest version (1.2.1) in #1430
I used the newer
GenBashCompletionV2
command to generate the completion for bash (to support dynamic completion)titled accordingly?
See how to contribute