go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/resultdb/cli/app.go (about) 1 // Copyright 2019 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package cli 16 17 import ( 18 "context" 19 "os" 20 21 "github.com/maruel/subcommands" 22 23 "go.chromium.org/luci/auth" 24 "go.chromium.org/luci/auth/client/authcli" 25 "go.chromium.org/luci/common/cli" 26 "go.chromium.org/luci/common/flag/fixflagpos" 27 "go.chromium.org/luci/common/logging/gologger" 28 ) 29 30 // Params is the parameters for the bb application. 31 type Params struct { 32 DefaultResultDBHost string 33 Auth auth.Options 34 } 35 36 var logCfg = gologger.LoggerConfig{ 37 Out: os.Stderr, 38 } 39 40 // application creates the application and configures its subcommands. 41 // Ignores p.Auth.Scopes. 42 func application(p Params) *cli.Application { 43 return &cli.Application{ 44 Name: "rdb", 45 Title: "A CLI client for ResultDB.", 46 Context: func(ctx context.Context) context.Context { 47 return logCfg.Use(ctx) 48 }, 49 Commands: []*subcommands.Command{ 50 cmdRPC(p), 51 cmdQuery(p), 52 cmdStream(p), 53 54 {}, // a separator 55 authcli.SubcommandLogin(p.Auth, "auth-login", false), 56 authcli.SubcommandLogout(p.Auth, "auth-logout", false), 57 authcli.SubcommandInfo(p.Auth, "auth-info", false), 58 59 {}, // a separator 60 subcommands.CmdHelp, 61 }, 62 } 63 } 64 65 // Main is the main function of the rdb application. 66 func Main(p Params, args []string) int { 67 return subcommands.Run(application(p), fixflagpos.FixSubcommands(args)) 68 }