code.vegaprotocol.io/vega@v0.79.0/cmd/visor/run.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  	"fmt"
    20  
    21  	"code.vegaprotocol.io/vega/logging"
    22  	"code.vegaprotocol.io/vega/visor"
    23  	"code.vegaprotocol.io/vega/visor/client"
    24  
    25  	"github.com/spf13/cobra"
    26  )
    27  
    28  const homeFlagName = "home"
    29  
    30  func init() {
    31  	rootCmd.AddCommand(runCmd)
    32  
    33  	runCmd.Flags().String(homeFlagName, "", "Path to visor home folder")
    34  	runCmd.MarkFlagRequired(homeFlagName)
    35  }
    36  
    37  var runCmd = &cobra.Command{
    38  	Use:          "run",
    39  	Short:        "Runs visor",
    40  	SilenceUsage: false,
    41  	RunE: func(cmd *cobra.Command, args []string) error {
    42  		homePath, err := cmd.Flags().GetString(homeFlagName)
    43  		if err != nil {
    44  			return err
    45  		}
    46  
    47  		log := logging.NewDevLogger()
    48  
    49  		runner, err := visor.NewVisor(cmd.Context(), log, client.NewClientFactory(), homePath)
    50  		if err != nil {
    51  			return fmt.Errorf("failed to create new runner: %w", err)
    52  		}
    53  
    54  		return runner.Run(cmd.Context())
    55  	},
    56  }