go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cv/cli/app.go (about)

     1  // Copyright 2021 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  // cli is a package implementing command line utilities for CV. These should be
    16  // avaliable to users via the `luci-cv` binary, which can be built from
    17  // luci/cv/cmd/luci-cv.
    18  package cli
    19  
    20  import (
    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/api/gerrit"
    26  	"go.chromium.org/luci/common/cli"
    27  	"go.chromium.org/luci/common/errors"
    28  	"go.chromium.org/luci/common/flag/fixflagpos"
    29  )
    30  
    31  type Params struct {
    32  	Auth auth.Options
    33  }
    34  
    35  func application(p Params) *cli.Application {
    36  	p.Auth.Scopes = []string{
    37  		auth.OAuthScopeEmail,
    38  		gerrit.OAuthScope,
    39  	}
    40  	return &cli.Application{
    41  		Name:  "luci-cv",
    42  		Title: "LUCI CV Command line utilities",
    43  		Commands: []*subcommands.Command{
    44  			cmdMatchConfig(p),
    45  
    46  			{}, // a separator
    47  			authcli.SubcommandLogin(p.Auth, "auth-login", false),
    48  			authcli.SubcommandLogout(p.Auth, "auth-logout", false),
    49  			authcli.SubcommandInfo(p.Auth, "auth-info", false),
    50  
    51  			{}, // a separator
    52  			subcommands.CmdHelp,
    53  		},
    54  	}
    55  }
    56  
    57  // Main is the main function of the luci-cv application.
    58  func Main(p Params, args []string) int {
    59  	return subcommands.Run(application(p), fixflagpos.FixSubcommands(args))
    60  }
    61  
    62  var badArgsTag = errors.BoolTag{Key: errors.NewTagKey("Bad arguments given")}