2019-10-23 15:58:18 +00:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2020-09-30 05:11:33 +00:00
|
|
|
package flags
|
2019-10-23 15:58:18 +00:00
|
|
|
|
|
|
|
import (
|
2020-09-30 05:11:33 +00:00
|
|
|
"code.gitea.io/sdk/gitea"
|
2020-01-04 17:44:25 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-10-23 15:58:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// create global variables for global Flags to simplify
|
|
|
|
// access to the options without requiring cli.Context
|
|
|
|
var (
|
2020-09-30 05:11:33 +00:00
|
|
|
// GlobalLoginValue contain value of --login|-l arg
|
|
|
|
GlobalLoginValue string
|
|
|
|
// GlobalRepoValue contain value of --repo|-r arg
|
|
|
|
GlobalRepoValue string
|
|
|
|
// GlobalOutputValue contain value of --output|-o arg
|
|
|
|
GlobalOutputValue string
|
|
|
|
// GlobalRemoteValue contain value of --remote|-R arg
|
|
|
|
GlobalRemoteValue string
|
2019-10-23 15:58:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// LoginFlag provides flag to specify tea login profile
|
|
|
|
var LoginFlag = cli.StringFlag{
|
2020-03-06 03:43:28 +00:00
|
|
|
Name: "login",
|
|
|
|
Aliases: []string{"l"},
|
2019-11-03 20:34:41 +00:00
|
|
|
Usage: "Use a different Gitea login. Optional",
|
2020-09-30 05:11:33 +00:00
|
|
|
Destination: &GlobalLoginValue,
|
2019-10-23 15:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RepoFlag provides flag to specify repository
|
|
|
|
var RepoFlag = cli.StringFlag{
|
2020-03-06 03:43:28 +00:00
|
|
|
Name: "repo",
|
|
|
|
Aliases: []string{"r"},
|
2020-12-11 09:07:29 +00:00
|
|
|
Usage: "Override local repository path or gitea repository slug to interact with. Optional",
|
2020-09-30 05:11:33 +00:00
|
|
|
Destination: &GlobalRepoValue,
|
2019-10-23 15:58:18 +00:00
|
|
|
}
|
|
|
|
|
2019-10-26 21:29:37 +00:00
|
|
|
// RemoteFlag provides flag to specify remote repository
|
|
|
|
var RemoteFlag = cli.StringFlag{
|
2020-03-06 03:43:28 +00:00
|
|
|
Name: "remote",
|
|
|
|
Aliases: []string{"R"},
|
2019-11-03 20:34:41 +00:00
|
|
|
Usage: "Discover Gitea login from remote. Optional",
|
2020-09-30 05:11:33 +00:00
|
|
|
Destination: &GlobalRemoteValue,
|
2019-10-26 21:29:37 +00:00
|
|
|
}
|
|
|
|
|
2019-10-23 15:58:18 +00:00
|
|
|
// OutputFlag provides flag to specify output type
|
|
|
|
var OutputFlag = cli.StringFlag{
|
2020-03-06 03:43:28 +00:00
|
|
|
Name: "output",
|
|
|
|
Aliases: []string{"o"},
|
2019-11-03 20:34:41 +00:00
|
|
|
Usage: "Output format. (csv, simple, table, tsv, yaml)",
|
2020-09-30 05:11:33 +00:00
|
|
|
Destination: &GlobalOutputValue,
|
2019-10-23 15:58:18 +00:00
|
|
|
}
|
|
|
|
|
2020-09-21 05:03:20 +00:00
|
|
|
// StateFlag provides flag to specify issue/pr state, defaulting to "open"
|
|
|
|
var StateFlag = cli.StringFlag{
|
|
|
|
Name: "state",
|
|
|
|
Usage: "Filter by state (all|open|closed)",
|
|
|
|
DefaultText: "open",
|
|
|
|
}
|
|
|
|
|
2020-09-27 12:07:46 +00:00
|
|
|
// PaginationPageFlag provides flag for pagination options
|
|
|
|
var PaginationPageFlag = cli.StringFlag{
|
|
|
|
Name: "page",
|
|
|
|
Aliases: []string{"p"},
|
|
|
|
Usage: "specify page, default is 1",
|
|
|
|
}
|
|
|
|
|
|
|
|
// PaginationLimitFlag provides flag for pagination options
|
|
|
|
var PaginationLimitFlag = cli.StringFlag{
|
|
|
|
Name: "limit",
|
|
|
|
Aliases: []string{"lm"},
|
|
|
|
Usage: "specify limit of items per page",
|
|
|
|
}
|
|
|
|
|
2019-10-23 15:58:18 +00:00
|
|
|
// LoginOutputFlags defines login and output flags that should
|
|
|
|
// added to all subcommands and appended to the flags of the
|
|
|
|
// subcommand to work around issue and provide --login and --output:
|
|
|
|
// https://github.com/urfave/cli/issues/585
|
|
|
|
var LoginOutputFlags = []cli.Flag{
|
2020-01-04 17:44:25 +00:00
|
|
|
&LoginFlag,
|
|
|
|
&OutputFlag,
|
2019-10-23 15:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// LoginRepoFlags defines login and repo flags that should
|
|
|
|
// be used for all subcommands and appended to the flags of
|
|
|
|
// the subcommand to work around issue and provide --login and --repo:
|
|
|
|
// https://github.com/urfave/cli/issues/585
|
|
|
|
var LoginRepoFlags = []cli.Flag{
|
2020-01-04 17:44:25 +00:00
|
|
|
&LoginFlag,
|
|
|
|
&RepoFlag,
|
|
|
|
&RemoteFlag,
|
2019-10-23 15:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AllDefaultFlags defines flags that should be available
|
|
|
|
// for all subcommands working with dedicated repositories
|
|
|
|
// to work around issue and provide --login, --repo and --output:
|
|
|
|
// https://github.com/urfave/cli/issues/585
|
|
|
|
var AllDefaultFlags = append([]cli.Flag{
|
2020-01-04 17:44:25 +00:00
|
|
|
&RepoFlag,
|
|
|
|
&RemoteFlag,
|
2019-10-23 15:58:18 +00:00
|
|
|
}, LoginOutputFlags...)
|
|
|
|
|
2020-09-21 05:03:20 +00:00
|
|
|
// IssuePRFlags defines flags that should be available on issue & pr listing flags.
|
|
|
|
var IssuePRFlags = append([]cli.Flag{
|
|
|
|
&StateFlag,
|
2020-09-27 12:07:46 +00:00
|
|
|
&PaginationPageFlag,
|
|
|
|
&PaginationLimitFlag,
|
2020-09-21 05:03:20 +00:00
|
|
|
}, AllDefaultFlags...)
|
|
|
|
|
2020-09-30 05:11:33 +00:00
|
|
|
// GetListOptions return ListOptions based on PaginationFlags
|
|
|
|
func GetListOptions(ctx *cli.Context) gitea.ListOptions {
|
|
|
|
page := ctx.Int("page")
|
|
|
|
limit := ctx.Int("limit")
|
|
|
|
if limit != 0 && page == 0 {
|
|
|
|
page = 1
|
2020-07-18 10:43:56 +00:00
|
|
|
}
|
2020-09-30 05:11:33 +00:00
|
|
|
return gitea.ListOptions{
|
|
|
|
Page: page,
|
|
|
|
PageSize: limit,
|
2020-09-16 13:47:52 +00:00
|
|
|
}
|
2019-11-08 01:33:46 +00:00
|
|
|
}
|