Skip to content

Commit 105f529

Browse files
committed
#8 Enable and add autocompletion for use/download cmds
1 parent 85dc9e7 commit 105f529

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

cmd/flora/flora.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func main() {
1515
app.Name = "flora"
1616
app.Usage = "Simple app to upgrade your terraform"
1717
app.Version = "0.1.0"
18+
app.EnableBashCompletion = true
1819
app.Commands = []cli.Command{
1920
{
2021
Name: "upgrade",
@@ -34,9 +35,10 @@ func main() {
3435
},
3536
},
3637
{
37-
Name: "download",
38-
Usage: "Download specific Terraform version",
39-
ArgsUsage: "TERRAFORM_VERSION",
38+
Name: "download",
39+
Usage: "Download specific Terraform version",
40+
ArgsUsage: "TERRAFORM_VERSION",
41+
BashComplete: flora.VersionsCompletion,
4042
Action: func(c *cli.Context) error {
4143
if c.NArg() == 0 {
4244
cli.ShowSubcommandHelp(c)
@@ -60,9 +62,10 @@ func main() {
6062
},
6163
},
6264
{
63-
Name: "use",
64-
Usage: "Download(when it's needed) and use specific terraform version",
65-
ArgsUsage: "TERRAFORM_VERSION",
65+
Name: "use",
66+
Usage: "Download(when it's needed) and use specific terraform version",
67+
ArgsUsage: "TERRAFORM_VERSION",
68+
BashComplete: flora.VersionsCompletion,
6669
Action: func(c *cli.Context) error {
6770
version := c.Args().First()
6871

utils.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package flora
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/urfave/cli"
7+
)
8+
9+
func VersionsCompletion(c *cli.Context) {
10+
if c.NArg() > 0 {
11+
return
12+
}
13+
14+
versions, err := ListRemoteVersions()
15+
16+
if err != nil {
17+
return
18+
}
19+
20+
for _, version := range versions {
21+
fmt.Println(version)
22+
}
23+
}

0 commit comments

Comments
 (0)