code.vegaprotocol.io/vega@v0.79.0/cmd/visor/init.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 main
    17  
    18  import (
    19  	"code.vegaprotocol.io/vega/logging"
    20  	"code.vegaprotocol.io/vega/visor"
    21  
    22  	"github.com/spf13/cobra"
    23  )
    24  
    25  const withDataNodeFlagName = "with-data-node"
    26  
    27  func init() {
    28  	rootCmd.AddCommand(initCmd)
    29  
    30  	initCmd.Flags().String(homeFlagName, "", "Path to visor home folder to be generated")
    31  	initCmd.MarkFlagRequired(homeFlagName)
    32  
    33  	initCmd.Flags().Bool(withDataNodeFlagName, false, "Determines whether or not data node config should be also generated")
    34  }
    35  
    36  var initCmd = &cobra.Command{
    37  	Use:          "init",
    38  	Short:        "Initiates home folder for visor",
    39  	SilenceUsage: false,
    40  	RunE: func(cmd *cobra.Command, args []string) error {
    41  		homePath, err := cmd.Flags().GetString(homeFlagName)
    42  		if err != nil {
    43  			return err
    44  		}
    45  
    46  		withDataNode, err := cmd.Flags().GetBool(withDataNodeFlagName)
    47  		if err != nil {
    48  			return err
    49  		}
    50  
    51  		log := logging.NewDevLogger()
    52  
    53  		return visor.Init(log, homePath, withDataNode)
    54  	},
    55  }