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

     1  // Copyright 2022 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  	"log"
     9  	"os"
    10  
    11  	"cloud.google.com/go/bigquery"
    12  	"github.com/maruel/subcommands"
    13  	"go.chromium.org/luci/auth"
    14  	"go.chromium.org/luci/auth/client/authcli"
    15  	"go.chromium.org/luci/common/api/gitiles"
    16  	"go.chromium.org/luci/hardcoded/chromeinfra"
    17  )
    18  
    19  type commonFlags struct {
    20  	subcommands.CommandRunBase
    21  	authFlags authcli.Flags
    22  	project   string
    23  
    24  	parsedAuthOpts auth.Options
    25  }
    26  
    27  func (c *commonFlags) Init(authOpts auth.Options) {
    28  	c.authFlags = authcli.Flags{}
    29  	c.authFlags.Register(&c.Flags, authOpts)
    30  }
    31  
    32  func (c *commonFlags) Parse() error {
    33  	var err error
    34  	c.parsedAuthOpts, err = c.authFlags.Options()
    35  	if err != nil {
    36  		return err
    37  	}
    38  	return nil
    39  }
    40  
    41  func getApplication(defaultAuthOpts auth.Options) *subcommands.DefaultApplication {
    42  	defaultAuthOpts.Scopes = []string{
    43  		auth.OAuthScopeEmail,
    44  		bigquery.Scope,
    45  		gitiles.OAuthScope,
    46  	}
    47  	return &subcommands.DefaultApplication{
    48  		Name:  "update_test_durations",
    49  		Title: "Tool for updating test duration data from CIPD.",
    50  		Commands: []*subcommands.Command{
    51  			cmdRun(defaultAuthOpts),
    52  			authcli.SubcommandInfo(defaultAuthOpts, "whoami", false),
    53  			authcli.SubcommandLogin(defaultAuthOpts, "login", false),
    54  			authcli.SubcommandLogout(defaultAuthOpts, "logout", false),
    55  			subcommands.CmdHelp,
    56  		},
    57  	}
    58  }
    59  
    60  func main() {
    61  	log.SetFlags(log.Lmicroseconds)
    62  	app := getApplication(chromeinfra.DefaultAuthOptions())
    63  	os.Exit(subcommands.Run(app, nil))
    64  }