go.fuchsia.dev/infra@v0.0.0-20240507153436-9b593402251b/cmd/autocorrelator/common.go (about)

     1  // Copyright 2021 The Fuchsia Authors.
     2  // Use of this source code is governed by a BSD-style license that can be
     3  // found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  
    10  	"github.com/maruel/subcommands"
    11  
    12  	"go.chromium.org/luci/auth"
    13  	"go.chromium.org/luci/auth/client/authcli"
    14  )
    15  
    16  type commonFlags struct {
    17  	subcommands.CommandRunBase
    18  	bbHost    string
    19  	authFlags authcli.Flags
    20  
    21  	parsedAuthOpts auth.Options
    22  }
    23  
    24  func (c *commonFlags) Init(authOpts auth.Options) {
    25  	c.authFlags = authcli.Flags{}
    26  	c.authFlags.Register(&c.Flags, authOpts)
    27  	c.Flags.StringVar(&c.bbHost, "bb-host", "cr-buildbucket.appspot.com", "Buildbucket host to use.")
    28  }
    29  
    30  func (c *commonFlags) Parse() error {
    31  	var err error
    32  	c.parsedAuthOpts, err = c.authFlags.Options()
    33  	if err != nil {
    34  		return err
    35  	}
    36  	if c.bbHost == "" {
    37  		return fmt.Errorf("-bb-host is required")
    38  	}
    39  	return nil
    40  }