File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,13 @@ and other nifty feature ;)
2525// Execute adds all child commands to the root command and sets flags appropriately.
2626// This is called by main.main(). It only needs to happen once to the rootCmd.
2727func Execute (version , commit string ) {
28+ // The following lines remove -h and --help flags form the usages
29+ // RootCmd.InitDefaultHelpFlag()
30+ // RootCmd.Flags().MarkHidden("help")
31+ // This was initially needed because we DisableFlagParsing for the tasks.
32+ // Now we still DisableFlagParsing but also evaluate the args. If -h or --help
33+ // is the only arg we show the help of the command
34+
2835 // IMPORTANT: the order of tasks should resemble the order in the dev.sh
2936 cobra .EnableCommandSorting = false
3037 RootCmd .AddCommand (buildSectionCommand ("your tasks" ))
Original file line number Diff line number Diff line change 77 "main/utils"
88 "os"
99 "path/filepath"
10+ "strings"
1011 "syscall"
1112)
1213
@@ -17,8 +18,23 @@ func buildTaskCommand(task utils.DevScriptTask, devScriptPath string) *cobra.Com
1718 Short : color .Gray .Text (task .Short ),
1819 Long : task .Long ,
1920 Args : cobra .ArbitraryArgs ,
21+ // If this is true all flags will be passed to the command as arguments.
22+ DisableFlagParsing : true ,
23+ // Will disable the addition of [flags] to the usage
24+ // As we currently do not parse comments with a specific syntax to provide
25+ // useful information. The only flags we support are -h and --help they
26+ // are always part of the usage template.
27+ DisableFlagsInUseLine : true ,
2028 Run : func (cmd * cobra.Command , args []string ) {
21- execDevScriptWithArguments (devScriptPath , append ([]string {task .Usage }, args ... ))
29+ // We DisableFlagParsing but we still want to use the -h and --help flag.
30+ // This is why we evaluate the args manually and show the help of the
31+ // command if needed.
32+ argsAsString := strings .Join (args , " " )
33+ if argsAsString == "--help" || argsAsString == "-h" {
34+ cmd .Help ()
35+ } else {
36+ execDevScriptWithArguments (devScriptPath , append ([]string {task .Usage }, args ... ))
37+ }
2238 },
2339 }
2440 return cmd
Original file line number Diff line number Diff line change @@ -11,12 +11,7 @@ set -e
1111
1212# ######## TASKS #########
1313
14- # runs foo
15- function foo() {
16- echo " test"
17- }
18-
19- # use main aus binary
14+ # exposes ./main binary globally
2015function switch-dev-binary() {
2116 echo " -----------> creating build"
2217 build
@@ -40,11 +35,12 @@ function restore-dev-binary() {
4035 echo " no /usr/local/bin/dev_back found. Nothing to restore!"
4136 fi
4237}
43-
38+ # build
4439function build() {
4540 go build main
4641}
4742
43+ # install dev dependencies
4844function setup() {
4945 # As the setup typically is more complex we recommend using a separate
5046 # file `dev_setup.sh`
You can’t perform that action at this time.
0 commit comments