Skip to content

Commit 29eb98e

Browse files
authored
Merge pull request #13 from bcmi-labs/docs
Docs
2 parents 45e7b52 + 9d73b4c commit 29eb98e

17 files changed

+986
-8
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[email protected]>
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

+28-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,32 @@ import (
3939
)
4040

4141
const (
42-
// ArduinoVersion represents Arduino CLI version number.
43-
ArduinoVersion string = "0.0.1-pre-alpha"
42+
bashAutoCompletionFunction = `
43+
__arduino_autocomplete()
44+
{
45+
case $(last_command) in
46+
arduino_lib)
47+
opts="install uninstall list search version"
48+
;;
49+
arduino_lib_list)
50+
opts="update"
51+
;;
52+
arduino_help)
53+
opts="lib core version"
54+
;;
55+
arduino)
56+
opts="lib help version"
57+
;;
58+
esac
59+
if [[ ${cur} == " *" ]] ; then
60+
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
61+
return 0
62+
fi
63+
return 1
64+
}`,
65+
66+
// ArduinoVersion represents Arduino CLI version number.
67+
ArduinoVersion string = "0.0.1-pre-alpha"
4468
)
4569

4670
// GlobalFlags represents flags available in all the program.
@@ -58,13 +82,14 @@ var RootCmd = &cobra.Command{
5882
Use: "arduino",
5983
Short: "Arduino CLI",
6084
Long: "Arduino Create Command Line Interface (arduino-cli)",
85+
BashCompletionFunction: bashAutoCompletionFunction,
6186
}
6287

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

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[email protected]>
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)