blob: 18e9409de67f63e39758918f12ad6baecd8acaa7 [file] [log] [blame]
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package main
import (
"log"
"os"
"cloud.google.com/go/bigquery"
"github.com/maruel/subcommands"
"go.chromium.org/luci/auth"
"go.chromium.org/luci/auth/client/authcli"
"go.chromium.org/luci/common/api/gitiles"
"go.chromium.org/luci/hardcoded/chromeinfra"
)
type commonFlags struct {
subcommands.CommandRunBase
authFlags authcli.Flags
project string
parsedAuthOpts auth.Options
}
func (c *commonFlags) Init(authOpts auth.Options) {
c.authFlags = authcli.Flags{}
c.authFlags.Register(&c.Flags, authOpts)
}
func (c *commonFlags) Parse() error {
var err error
c.parsedAuthOpts, err = c.authFlags.Options()
if err != nil {
return err
}
return nil
}
func getApplication(defaultAuthOpts auth.Options) *subcommands.DefaultApplication {
defaultAuthOpts.Scopes = []string{
auth.OAuthScopeEmail,
bigquery.Scope,
gitiles.OAuthScope,
}
return &subcommands.DefaultApplication{
Name: "update_test_durations",
Title: "Tool for updating test duration data from CIPD.",
Commands: []*subcommands.Command{
cmdRun(defaultAuthOpts),
authcli.SubcommandInfo(defaultAuthOpts, "whoami", false),
authcli.SubcommandLogin(defaultAuthOpts, "login", false),
authcli.SubcommandLogout(defaultAuthOpts, "logout", false),
subcommands.CmdHelp,
},
}
}
func main() {
log.SetFlags(log.Lmicroseconds)
app := getApplication(chromeinfra.DefaultAuthOptions())
os.Exit(subcommands.Run(app, nil))
}