-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnect.go
53 lines (45 loc) · 1.32 KB
/
connect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package cmd
import (
"io"
"time"
"github.com/esdandreu/tapioca"
"github.com/esdandreu/tapioca/spinner"
"github.com/spf13/cobra"
)
var verbose bool
// connectCmd represents the progress command
var connectCmd = &cobra.Command{
Use: "connect",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
// Create and run a spinner in the background
program := tapioca.NewProgram(spinner.New().Title("Connecting")).GoRun()
defer program.QuitAndWait() // Quit when command ends
// Set the command output to the program
defer func(w io.Writer) { cmd.SetOut(w) }(cmd.OutOrStdout())
cmd.SetOut(program)
N := 10
for i := 0; i <= N; i++ {
if verbose {
if i == 0 {
cmd.Println("First connection attempt")
} else {
cmd.Println("Retry connection:", i)
}
}
time.Sleep(500 * time.Millisecond)
}
cmd.Println("Connection successful!")
},
}
func init() {
rootCmd.AddCommand(connectCmd)
connectCmd.Flags().BoolVarP(
&verbose, "verbose", "v", false, "Displays debug logs",
)
}