code.vegaprotocol.io/vega@v0.79.0/cmd/vega/commands/subcmd_example.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 //go:build nobuild 17 // +build nobuild 18 19 package commands 20 21 import ( 22 "context" 23 24 "code.vegaprotocol.io/vega/core/config" 25 "github.com/jessevdk/go-flags" 26 ) 27 28 // ExampleCmd describes a command (in this case `vega example`) 29 // It holds global variables that its sub-commands will use and the 30 // sub-commands itself. 31 type ExampleCmd struct { 32 // Global variables 33 config.VegaHomeFlag 34 35 // Subcommands. 36 Foo exampleFoo `command:"foo"` 37 } 38 39 var exampleCmd ExampleCmd 40 41 // Example is the registration function, the name of this function should 42 // follow the command name. 43 // This function is invoked from `Register` in main.go 44 func Example(ctx context.Context, parser *flags.Parser) error { 45 // here we initialize the global exampleCmd with needed default values. 46 exampleCmd = ExampleCmd{} 47 _, err := parser.AddCommand("example", "short desc", "long desc", &exampleCmd) 48 return err 49 } 50 51 // exampleFoo is an `example` sub-command. 52 type exampleFoo struct{} 53 54 func (opts *exampleFoo) Execute(args []string) error { 55 return nil 56 }