code.vegaprotocol.io/vega@v0.79.0/cmd/vega/commands/root.go (about) 1 // Copyright (C) 2023 Gobalsky Labs Limited 2 // 3 // This program is free software: you can redistribute it and/or modify 4 // it under the terms of the GNU Affero General Public License as 5 // published by the Free Software Foundation, either version 3 of the 6 // License, or (at your option) any later version. 7 // 8 // This program is distributed in the hope that it will be useful, 9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 // GNU Affero General Public License for more details. 12 // 13 // You should have received a copy of the GNU Affero General Public License 14 // along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 package commands 17 18 import ( 19 "context" 20 "fmt" 21 "os" 22 23 "code.vegaprotocol.io/vega/cmd/vega/commands/faucet" 24 "code.vegaprotocol.io/vega/cmd/vega/commands/genesis" 25 "code.vegaprotocol.io/vega/cmd/vega/commands/nodewallet" 26 "code.vegaprotocol.io/vega/cmd/vega/commands/paths" 27 tools "code.vegaprotocol.io/vega/cmd/vegatools" 28 "code.vegaprotocol.io/vega/core/config" 29 30 "github.com/jessevdk/go-flags" 31 ) 32 33 // Subcommand is the signature of a sub command that can be registered. 34 type Subcommand func(context.Context, *flags.Parser) error 35 36 // Register registers one or more subcommands. 37 func Register(ctx context.Context, parser *flags.Parser, cmds ...Subcommand) error { 38 for _, fn := range cmds { 39 if err := fn(ctx, parser); err != nil { 40 return err 41 } 42 } 43 return nil 44 } 45 46 func Main(ctx context.Context) error { 47 // special case for the tendermint subcommand, so we bypass the command line 48 if len(os.Args) >= 2 { 49 switch os.Args[1] { 50 case "tendermint", "tm", "cometbft": 51 return (&cometbftCmd{}).Execute(nil) 52 case "wallet": 53 return (&walletCmd{}).Execute(nil) 54 case "datanode": 55 return (&datanodeCmd{}).Execute(nil) 56 case "blockexplorer": 57 return (&blockExplorerCmd{}).Execute(nil) 58 } 59 } 60 61 parser := flags.NewParser(&config.Empty{}, flags.Default) 62 63 if err := Register(ctx, parser, 64 faucet.Faucet, 65 genesis.Genesis, 66 Init, 67 nodewallet.NodeWallet, 68 Verify, 69 Version, 70 Wallet, 71 Datanode, 72 tools.VegaTools, 73 Watch, 74 Tm, 75 Tendermint, 76 CometBFT, 77 Query, 78 Bridge, 79 paths.Paths, 80 UnsafeResetAll, 81 AnnounceNode, 82 RotateEthKey, 83 ProposeProtocolUpgrade, 84 Start, 85 Node, 86 BlockExplorer, 87 ); err != nil { 88 _, _ = fmt.Fprintln(os.Stderr, err) 89 return err 90 } 91 92 if _, err := parser.Parse(); err != nil { 93 return err 94 } 95 return nil 96 }