-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
46 lines (38 loc) · 970 Bytes
/
main.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
package main
import (
"flag"
"time"
"github.com/charmbracelet/log"
"github.com/esdandreu/tapioca"
"github.com/esdandreu/tapioca/spinner"
)
var logger *log.Logger = log.Default()
func main() {
var notapioca bool
flag.BoolVar(¬apioca, "no-tapioca", false, "Do not use tapioca")
var verbose bool
flag.BoolVar(&verbose, "verbose", false, "Print debug logs")
flag.Parse()
// Create and run a spinner in the background
program := tapioca.NewProgram(spinner.New().
Title("Work in progress"),
).GoRun()
defer program.QuitAndWait() // Quit when command ends
if !notapioca {
// Use a logger that works together with bubbletea
defer func(l *log.Logger) { logger = l }(logger)
logger = log.New(program)
}
if verbose {
logger.SetLevel(log.DebugLevel)
}
logger.SetReportTimestamp(false)
N := 5
for i := 0; i <= N; i++ {
if i > 0 {
logger.Debugf("Task: %d", i)
}
time.Sleep(500 * time.Millisecond)
}
logger.Info("Work finished!")
}