forked from protolambda/eth2-testnet-genesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
62 lines (55 loc) · 1.39 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 (
"context"
"fmt"
"os"
"github.com/protolambda/ask"
)
type GenesisCmd struct{}
func (c *GenesisCmd) Help() string {
return "Create genesis state. See sub-commands for different fork versions."
}
func (c *GenesisCmd) Cmd(route string) (cmd interface{}, err error) {
switch route {
case "phase0":
cmd = &Phase0GenesisCmd{}
case "altair":
cmd = &AltairGenesisCmd{}
case "merge", "bellatrix":
cmd = &BellatrixGenesisCmd{}
case "capella":
cmd = &CapellaGenesisCmd{}
case "deneb":
cmd = &DenebGenesisCmd{}
case "version":
cmd = &VersionCmd{}
default:
return nil, fmt.Errorf("unrecognized cmd route: %s", route)
}
return
}
func (c *GenesisCmd) Routes() []string {
return []string{"phase0", "altair", "bellatrix", "capella", "deneb", "version"}
}
func main() {
cmd := &GenesisCmd{}
descr, err := ask.Load(cmd)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "failed to load main command: %v", err.Error())
os.Exit(1)
}
if cmd, err := descr.Execute(context.Background(), nil, os.Args[1:]...); err == ask.UnrecognizedErr {
_, _ = fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
} else if err == ask.HelpErr {
_, _ = fmt.Fprintln(os.Stderr, cmd.Usage(false))
os.Exit(0)
} else if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
} else if cmd == nil {
_, _ = fmt.Fprintln(os.Stderr, "failed to load command")
os.Exit(1)
}
os.Exit(0)
}