Skip to content

Commit

Permalink
Merge branch 'CU-1ty8v5h'
Browse files Browse the repository at this point in the history
  • Loading branch information
varrcan committed Dec 12, 2021
2 parents 8ebf955 + d530957 commit d4bdea1
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 5 deletions.
1 change: 1 addition & 0 deletions command/bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var bashCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
bash()
},
ValidArgs: []string{"--root"},
}

var bashRoot bool
Expand Down
56 changes: 56 additions & 0 deletions command/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package command

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

var completionDesc = `To load completions:
Bash:
$ source <(%[1]s completion bash)
# To load completions for each session, execute once:
$ echo "\nsource <(%[1]s completion bash)" >> ~/.bashrc
Zsh:
# If shell completion is not already enabled in your environment,
# you will need to enable it. You can execute the following once:
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
# To load completions for each session, execute once:
$ %[1]s completion zsh > "${fpath[1]}/_%[1]s"
You will need to start a new shell for this setup to take effect.
`

// completionCmd represents the completion command
var completionCmd = &cobra.Command{
Use: "completion [bash|zsh]",
Short: "Generate completion script",
Long: fmt.Sprintf(completionDesc, rootCmd.Root().Name()),
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh"},
Run: func(cmd *cobra.Command, args []string) {
if len(args) > 0 {
switch args[0] {
case "bash":
_ = cmd.Root().GenBashCompletion(os.Stdout)
case "zsh":
_ = cmd.Root().GenZshCompletion(os.Stdout)
}
} else {
fmt.Printf(completionDesc, rootCmd.Root().Name())
}
},
}

func init() {
rootCmd.AddCommand(completionCmd)
}
3 changes: 2 additions & 1 deletion command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Laravel: only the database is downloaded`,
Run: func(cmd *cobra.Command, args []string) {
deploy()
},
Example: "dl deploy\ndl deploy -d\ndl deploy -f -o bitrix,upload",
Example: "dl deploy\ndl deploy -d\ndl deploy -f -o bitrix,upload",
ValidArgs: []string{"--database", "--files", "--override"},
}

var (
Expand Down
2 changes: 1 addition & 1 deletion command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Execute() {

rootCmd.SetUsageTemplate(usageTemplate)
rootCmd.DisableAutoGenTag = true
rootCmd.CompletionOptions.DisableDefaultCmd = true
// rootCmd.CompletionOptions.DisableDefaultCmd = true

cobra.CheckErr(rootCmd.Execute())
}
Expand Down
7 changes: 4 additions & 3 deletions command/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ var source string
var localNetworkName = "dl_default"

var serviceCmd = &cobra.Command{
Use: "service",
Short: "Local services configuration",
Long: `Local services configuration (portainer, mailcatcher, traefik).`,
Use: "service",
Short: "Local services configuration",
Long: `Local services configuration (portainer, mailcatcher, traefik).`,
ValidArgs: []string{"up", "down", "recreate", "restart"},
}

// getServicesContainer local services containers
Expand Down
1 change: 1 addition & 0 deletions command/service_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Valid parameters for the "--service" flag: portainer, mail, traefik`,
Run: func(cmd *cobra.Command, args []string) {
downService()
},
ValidArgs: []string{"--service"},
}

func downService() {
Expand Down
1 change: 1 addition & 0 deletions command/service_recreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ var recreateServiceCmd = &cobra.Command{
downService()
upService()
},
ValidArgs: []string{"--service"},
}
1 change: 1 addition & 0 deletions command/service_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var upServiceCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
upService()
},
ValidArgs: []string{"--service", "--restart"},
}

func upService() {
Expand Down

0 comments on commit d4bdea1

Please sign in to comment.