Skip to content

Commit 67460ce

Browse files
author
Florian Heinze
committed
FEATURE: enabled autocompletion
1 parent cba89f5 commit 67460ce

File tree

8 files changed

+52
-365
lines changed

8 files changed

+52
-365
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ run `brew install sandstorm/tap/dev-script-runner` to install
4242

4343
run `brew upgrade sandstorm/tap/dev-script-runner` to upgrade
4444

45+
run `dev completion zsh > $(brew --prefix)/share/zsh/site-functions/_dev` to enable autocompletion
46+
4547
Go to your project root and run `dev DSR_INIT` to create a `dev.sh` and a `dev_setup.sh` with examples for different types of tasks.
4648
The `$@` at the end of your `dev.sh` dispatches the script arguments to a function (so `dev sometask` calls `sometask`).
4749

cmd/completion.go

Lines changed: 0 additions & 61 deletions
This file was deleted.

cmd/init.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import (
1010
)
1111

1212
func buildInitCommand() *cobra.Command {
13-
return &cobra.Command{
13+
var cmd = &cobra.Command{
1414
// IMPORTANT: never color Use! You will not be able to run the command otherwise.
15-
Use: "DSR_INIT",
16-
Short: color.Gray.Text("creates dev.sh and dev_setup.sh in current folder"),
17-
Long: color.Sprintf(`This creates an example create a dev.sh and dev_setup.sh in your current directory.`),
18-
Args: cobra.NoArgs,
15+
Use: "DSR_INIT",
16+
Short: "creates dev.sh and dev_setup.sh in current folder",
17+
Long: "This creates an example create a dev.sh and dev_setup.sh in your current directory.",
18+
Args: cobra.NoArgs,
19+
GroupID: utils.GROUP_ID_UTILS,
1920

2021
Run: func(cmd *cobra.Command, args []string) {
2122
currentDirectory, err := os.Getwd()
@@ -42,4 +43,5 @@ func buildInitCommand() *cobra.Command {
4243
os.Exit(0)
4344
},
4445
}
46+
return cmd
4547
}

cmd/root.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ func Execute(version, commit string) {
3131
// This was initially needed because we DisableFlagParsing for the tasks.
3232
// Now we still DisableFlagParsing but also evaluate the args. If -h or --help
3333
// is the only arg we show the help of the command
34-
3534
// IMPORTANT: the order of tasks should resemble the order in the dev.sh
3635
cobra.EnableCommandSorting = false
37-
RootCmd.AddCommand(buildSectionCommand("your tasks"))
36+
RootCmd.AddGroup(&cobra.Group{
37+
ID: utils.GROUP_ID_TASKS,
38+
Title: "Your Tasks",
39+
})
40+
RootCmd.AddGroup(&cobra.Group{
41+
ID: utils.GROUP_ID_UTILS,
42+
Title: "Utils",
43+
})
3844
addDevScriptTasksAsCommands(RootCmd)
39-
RootCmd.AddCommand(buildSectionCommand("utils"))
4045
RootCmd.AddCommand(buildInitCommand())
4146
// TODO: fix autocompletion
42-
// RootCmd.AddCommand(buildCompletionCommand())
43-
RootCmd.AddCommand(buildSectionCommand("other"))
4447
if err := RootCmd.Execute(); err != nil {
4548
fmt.Println(err)
4649
os.Exit(1)

cmd/task.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cmd
22

33
import (
4-
"github.com/gookit/color"
54
"github.com/spf13/cobra"
65
"log"
76
"main/utils"
@@ -14,10 +13,11 @@ import (
1413
func buildTaskCommand(task utils.DevScriptTask, devScriptPath string) *cobra.Command {
1514
var cmd = &cobra.Command{
1615
// IMPORTANT: never color Use! You will not be able to run the command otherwise.
17-
Use: task.Usage,
18-
Short: color.Gray.Text(task.Short),
19-
Long: task.Long,
20-
Args: cobra.ArbitraryArgs,
16+
Use: task.Usage,
17+
Short: task.Short,
18+
Long: task.Long,
19+
Args: cobra.ArbitraryArgs,
20+
GroupID: utils.GROUP_ID_TASKS,
2121
// If this is true all flags will be passed to the command as arguments.
2222
DisableFlagParsing: true,
2323
// Will disable the addition of [flags] to the usage

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ module main
33
go 1.19
44

55
require (
6-
github.com/gookit/color v1.3.5
7-
github.com/spf13/cobra v1.1.1
6+
github.com/gookit/color v1.5.2
7+
github.com/spf13/cobra v1.6.1
88
)
99

1010
require (
11-
github.com/inconshreveable/mousetrap v1.0.0 // indirect
11+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
1212
github.com/spf13/pflag v1.0.5 // indirect
13-
github.com/stretchr/testify v1.4.0 // indirect
13+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
14+
golang.org/x/sys v0.4.0 // indirect
1415
)

0 commit comments

Comments
 (0)