go.fuchsia.dev/infra@v0.0.0-20240507153436-9b593402251b/cmd/bigquery/common.go (about) 1 // Copyright 2021 The Fuchsia Authors. All rights reserved. 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 authFlags authcli.Flags 19 project string 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.project, "project", "", "Name of Google Cloud project.") 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.project == "" { 37 return fmt.Errorf("-project is required") 38 } 39 return nil 40 }