File tree Expand file tree Collapse file tree 8 files changed +52
-365
lines changed Expand file tree Collapse file tree 8 files changed +52
-365
lines changed Original file line number Diff line number Diff line change @@ -42,6 +42,8 @@ run `brew install sandstorm/tap/dev-script-runner` to install
42
42
43
43
run ` brew upgrade sandstorm/tap/dev-script-runner ` to upgrade
44
44
45
+ run ` dev completion zsh > $(brew --prefix)/share/zsh/site-functions/_dev ` to enable autocompletion
46
+
45
47
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.
46
48
The ` $@ ` at the end of your ` dev.sh ` dispatches the script arguments to a function (so ` dev sometask ` calls ` sometask ` ).
47
49
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -10,12 +10,13 @@ import (
10
10
)
11
11
12
12
func buildInitCommand () * cobra.Command {
13
- return & cobra.Command {
13
+ var cmd = & cobra.Command {
14
14
// 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 ,
19
20
20
21
Run : func (cmd * cobra.Command , args []string ) {
21
22
currentDirectory , err := os .Getwd ()
@@ -42,4 +43,5 @@ func buildInitCommand() *cobra.Command {
42
43
os .Exit (0 )
43
44
},
44
45
}
46
+ return cmd
45
47
}
Original file line number Diff line number Diff line change @@ -31,16 +31,19 @@ func Execute(version, commit string) {
31
31
// This was initially needed because we DisableFlagParsing for the tasks.
32
32
// Now we still DisableFlagParsing but also evaluate the args. If -h or --help
33
33
// is the only arg we show the help of the command
34
-
35
34
// IMPORTANT: the order of tasks should resemble the order in the dev.sh
36
35
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
+ })
38
44
addDevScriptTasksAsCommands (RootCmd )
39
- RootCmd .AddCommand (buildSectionCommand ("utils" ))
40
45
RootCmd .AddCommand (buildInitCommand ())
41
46
// TODO: fix autocompletion
42
- // RootCmd.AddCommand(buildCompletionCommand())
43
- RootCmd .AddCommand (buildSectionCommand ("other" ))
44
47
if err := RootCmd .Execute (); err != nil {
45
48
fmt .Println (err )
46
49
os .Exit (1 )
Original file line number Diff line number Diff line change 1
1
package cmd
2
2
3
3
import (
4
- "github.com/gookit/color"
5
4
"github.com/spf13/cobra"
6
5
"log"
7
6
"main/utils"
@@ -14,10 +13,11 @@ import (
14
13
func buildTaskCommand (task utils.DevScriptTask , devScriptPath string ) * cobra.Command {
15
14
var cmd = & cobra.Command {
16
15
// 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 ,
21
21
// If this is true all flags will be passed to the command as arguments.
22
22
DisableFlagParsing : true ,
23
23
// Will disable the addition of [flags] to the usage
Original file line number Diff line number Diff line change @@ -3,12 +3,13 @@ module main
3
3
go 1.19
4
4
5
5
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
8
8
)
9
9
10
10
require (
11
- github.com/inconshreveable/mousetrap v1.0 .0 // indirect
11
+ github.com/inconshreveable/mousetrap v1.1 .0 // indirect
12
12
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
14
15
)
You can’t perform that action at this time.
0 commit comments