2022-09-25 22:04:44 +03:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/DataDrake/cli-ng/v2/cmd"
|
|
|
|
)
|
|
|
|
|
|
|
|
var appVersion string = "develop"
|
|
|
|
|
2023-01-21 00:37:26 +02:00
|
|
|
// GlobalFlags contains the flags for commands.
|
2022-09-25 22:04:44 +03:00
|
|
|
type GlobalFlags struct {
|
|
|
|
Config string `short:"c" long:"config" desc:"Specify a custom config path."`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Root is the main command.
|
|
|
|
var Root *cmd.Root
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
Root = &cmd.Root{
|
|
|
|
Name: "hyprspace",
|
|
|
|
Short: "Hyprspace Distributed Network",
|
|
|
|
Version: appVersion,
|
|
|
|
Flags: &GlobalFlags{},
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.Register(&cmd.Help)
|
|
|
|
cmd.Register(&Init)
|
|
|
|
cmd.Register(&Up)
|
|
|
|
cmd.Register(&Down)
|
2023-01-21 00:37:26 +02:00
|
|
|
cmd.Register(&Status)
|
|
|
|
cmd.Register(&Peers)
|
2022-09-25 22:04:44 +03:00
|
|
|
cmd.Register(&cmd.Version)
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkErr(err error) {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Spinner is an array of the progression of the spinner.
|
|
|
|
var Spinner = []string{"|", "/", "-", "\\"}
|
|
|
|
|
|
|
|
// SpinnerWait displays the actual spinner
|
|
|
|
func SpinnerWait(done chan int, message string, wg *sync.WaitGroup) {
|
|
|
|
ticker := time.NewTicker(time.Millisecond * 128)
|
|
|
|
frameCounter := 0
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
wg.Done()
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
<-ticker.C
|
|
|
|
ind := frameCounter % len(Spinner)
|
|
|
|
fmt.Printf("\r[%v] "+message, Spinner[ind])
|
|
|
|
frameCounter++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|