/
main.go
62 lines (57 loc) · 1.3 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"log/slog"
"os"
"github.com/pkg/errors"
cli "github.com/urfave/cli/v2"
)
func main() {
flags := []cli.Flag{
&cli.StringFlag{
Name: "user",
Aliases: []string{"u"},
Usage: "the username or account identifier",
Value: "kurtis",
},
&cli.Float64Flag{
Name: "amount",
Aliases: []string{"a"},
Usage: "specify how much money you want to deposit into a specific account",
Value: 0.1,
},
&cli.IntFlag{
Name: "executions",
Aliases: []string{"e"},
Usage: "the number of executions or operations to be performed",
Value: 10,
},
}
app := &cli.App{
Commands: []*cli.Command{
{
Name: "pix",
Action: defaultAction,
Subcommands: []*cli.Command{
{Name: "optimistic", Action: optimisticAction, Flags: flags},
{Name: "pessimistic", Action: pessimisticAction, Flags: flags},
{Name: "distributed", Action: distributedAction, Flags: flags},
},
Flags: flags,
},
},
Flags: flags,
Action: defaultAction,
}
if err := app.Run(os.Args); err != nil {
if sterr, ok := err.(stackTracer); ok {
st := sterr.StackTrace()
slog.Error(fmt.Sprintf("%s%+v\n", err.Error(), st[:len(st)-2]))
} else {
slog.Error(err.Error())
}
}
}
type stackTracer interface {
StackTrace() errors.StackTrace
}