github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/cmd/tools/dtest/config/opts.go (about)

     1  // Copyright (c) 2018 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package config
    22  
    23  import (
    24  	"fmt"
    25  
    26  	xerrors "github.com/m3db/m3/src/x/errors"
    27  
    28  	"github.com/spf13/cobra"
    29  )
    30  
    31  // Args represents the CLI arguments to be set during a dtest
    32  type Args struct {
    33  	// NodeBuildPath specifies the local fs path to the m3db binary
    34  	NodeBuildPath string
    35  
    36  	// NodeConfigPath specifies the local fs path to the m3db configuration
    37  	NodeConfigPath string
    38  
    39  	// DTestConfigPath specifies the local fs path to the m3em configuration
    40  	DTestConfigPath string
    41  
    42  	// NumNodes specifies the number of nodes to use from the m3em configuration
    43  	NumNodes int
    44  
    45  	// SessionToken specifies the token used during remote operations
    46  	SessionToken string
    47  
    48  	// SessionOverride specifies if exisiting dtests maybe overridden on remote
    49  	// agents
    50  	SessionOverride bool
    51  
    52  	// InitialReset specifies if a Teardown() call should be made to remote
    53  	// agents before running a test. It's useful to reset a running agent
    54  	// in the event of an earlier run crashing.
    55  	InitialReset bool
    56  }
    57  
    58  // RegisterFlags registers all the common flags
    59  func (a *Args) RegisterFlags(cmd *cobra.Command) {
    60  	pf := cmd.PersistentFlags()
    61  	pf.StringVarP(&a.NodeBuildPath, "m3db-build", "b", "", "M3DB Binary")
    62  	pf.StringVarP(&a.NodeConfigPath, "m3db-config", "f", "", "M3DB Configuration File")
    63  	pf.StringVarP(&a.DTestConfigPath, "dtest-config", "d", "", "DTest Configuration File")
    64  	pf.BoolVarP(&a.SessionOverride, "session-override", "o", false, "Session Override")
    65  	pf.StringVarP(&a.SessionToken, "session-token", "t", "dtest", "Session Token")
    66  	pf.IntVarP(&a.NumNodes, "num-nodes", "n", 0, "Num Nodes to use in DTest")
    67  	pf.BoolVarP(&a.InitialReset, "initial-reset", "r", false, "Initial Reset")
    68  }
    69  
    70  // Validate validates the set options
    71  func (a *Args) Validate() error {
    72  	var me xerrors.MultiError
    73  	if a.NodeBuildPath == "" {
    74  		me = me.Add(fmt.Errorf("m3db-build not specified"))
    75  	}
    76  	if a.NodeConfigPath == "" {
    77  		me = me.Add(fmt.Errorf("m3db-config not specified"))
    78  	}
    79  	if a.DTestConfigPath == "" {
    80  		me = me.Add(fmt.Errorf("dtest-config not specified"))
    81  	}
    82  	if a.SessionToken == "" {
    83  		me = me.Add(fmt.Errorf("session-token not specified"))
    84  	}
    85  	return me.FinalError()
    86  }