Skip to content

Commit e4bbaa5

Browse files
committed
Added autocompletion and documention about bash_autocompletion and manpages
1 parent 03d7ef7 commit e4bbaa5

File tree

6 files changed

+556
-4
lines changed

6 files changed

+556
-4
lines changed

README.adoc

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
= arduino-cli
2+
Alessandro Sanino <a.sanino@bcmi-labs.cc>
23

34
Arduino CLI is a tool to access all Arduino Create API from Command Line.
45
It implements all functions provided by web version of Arduino Create.
@@ -9,10 +10,10 @@ It implements all functions provided by web version of Arduino Create.
910
. Reload shell configuration or reboot
1011
And you're done, now let's see how to use the CLI.
1112

12-
== Usage
13+
== Usage : An example
1314

1415
A general call is `arduino [COMMAND] [options]`
15-
To see the full list of commands, call `arduino -h` or `arduino --help`
16+
To see the full list of commands, call `arduino help [COMMAND]`, arduino [COMMAND] -h` or `arduino [COMMAND] --help`
1617

1718
== Contribution
1819

cmd/root.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,30 @@ import (
3838
"github.com/spf13/viper"
3939
)
4040

41+
const bashAutoCompletionFunction = `
42+
__arduino_autocomplete()
43+
{
44+
case $(last_command) in
45+
arduino_lib)
46+
opts="install uninstall list search version"
47+
;;
48+
arduino_lib_list)
49+
opts="update"
50+
;;
51+
arduino_help)
52+
opts="lib core version"
53+
;;
54+
arduino)
55+
opts="lib help version"
56+
;;
57+
esac
58+
if [[ ${cur} == " *" ]] ; then
59+
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
60+
return 0
61+
fi
62+
return 1
63+
}`
64+
4165
// GlobalFlags represents flags available in all the program.
4266
var GlobalFlags struct {
4367
Verbose int
@@ -53,13 +77,14 @@ var RootCmd = &cobra.Command{
5377
Use: "arduino",
5478
Short: "Arduino CLI",
5579
Long: "Arduino Create Command Line Interface (arduino-cli)",
80+
BashCompletionFunction: bashAutoCompletionFunction,
5681
}
5782

5883
// Execute adds all child commands to the root command sets flags appropriately.
5984
// This is called by main.main(). It only needs to happen once to the rootCmd.
6085
func Execute() {
6186
if err := RootCmd.Execute(); err != nil {
62-
fmt.Println(err)
87+
//fmt.Println(err)
6388
os.Exit(1)
6489
}
6590
}

docs/bash_completions/README.adoc

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
= Bash Autocompletion
2+
Alessandro Sanino <a.sanino@bcmi-labs.cc>
3+
4+
File contained in this directory is the file to allow autocompletion of the arduino CLI commands
5+
6+
== Installation
7+
. Move the file (using `sudo`) to directory `/etc/bash_completion.d`
8+
[source, bash]
9+
----
10+
sudo mv $PROJECT_DIR/docs/bash_completion/arduino /etc/bash_completion.d/
11+
----
12+
13+
. Reload bash completion configuration :
14+
[source, bash]
15+
----
16+
source /etc/bash_completion
17+
. /etc/bash_completion.d/arduino
18+
----
19+
20+
. Requires `$PROJECT_DIR` in `PATH` environment variable
21+
[source, bash]
22+
----
23+
export PATH=$PATH:$PROJECT_DIR
24+
----
25+
26+
== How has been autocompletion obtained?
27+
It has been obtained by setting up the BashAutocompletionFunction field of Root Command
28+
29+
```
30+
31+
```

0 commit comments

Comments
 (0)