134 lines
2.6 KiB
Go
134 lines
2.6 KiB
Go
package flag
|
||
|
||
import (
|
||
"github.com/urfave/cli/v2"
|
||
"github.com/xuxiaowei-com-cn/gitlab-go/constant"
|
||
)
|
||
|
||
func Common() []cli.Flag {
|
||
return []cli.Flag{
|
||
BaseUrl(),
|
||
Token(false),
|
||
}
|
||
}
|
||
|
||
func CommonTokenRequired() []cli.Flag {
|
||
return []cli.Flag{
|
||
BaseUrl(),
|
||
Token(true),
|
||
}
|
||
}
|
||
|
||
func PrintJson() cli.Flag {
|
||
return &cli.BoolFlag{
|
||
Name: constant.PrintJson,
|
||
Value: constant.PrintJsonDefault,
|
||
Usage: "打印 JSON",
|
||
}
|
||
}
|
||
|
||
func PrintTime() cli.Flag {
|
||
return &cli.BoolFlag{
|
||
Name: constant.PrintTime,
|
||
Value: constant.PrintTimeDefault,
|
||
Usage: "打印时间",
|
||
}
|
||
}
|
||
|
||
func BaseUrl() cli.Flag {
|
||
return &cli.StringFlag{
|
||
Name: constant.BaseUrl,
|
||
Value: constant.BaseUrlDefault,
|
||
EnvVars: []string{"CI_API_V4_URL"},
|
||
Usage: "实例地址,例如:https://gitlab.xuxiaowei.com.cn/api/v4",
|
||
}
|
||
}
|
||
|
||
func Token(required bool) cli.Flag {
|
||
return &cli.StringFlag{
|
||
Name: constant.Token,
|
||
Usage: "your_access_token",
|
||
Required: required,
|
||
}
|
||
}
|
||
|
||
func Sort() cli.Flag {
|
||
return &cli.StringFlag{
|
||
Name: constant.Sort,
|
||
Value: constant.SortDefault,
|
||
Usage: "按照 asc 或者 desc 排序",
|
||
}
|
||
}
|
||
|
||
func Id(required bool) cli.Flag {
|
||
return &cli.StringFlag{
|
||
Name: constant.Id,
|
||
Usage: "项目 ID 或 URL 编码的路径",
|
||
Required: required,
|
||
}
|
||
}
|
||
|
||
func Repository(required bool) cli.Flag {
|
||
return &cli.StringFlag{
|
||
Name: constant.Repository,
|
||
Usage: "仓库里存储库的 ID",
|
||
Required: required,
|
||
}
|
||
}
|
||
|
||
func TagName(required bool) cli.Flag {
|
||
return &cli.StringFlag{
|
||
Name: constant.TagName,
|
||
Usage: "标签的名称",
|
||
Required: required,
|
||
}
|
||
}
|
||
|
||
func JobId(required bool) cli.Flag {
|
||
return &cli.StringFlag{
|
||
Name: constant.JobId,
|
||
Usage: "作业 ID",
|
||
Required: required,
|
||
}
|
||
}
|
||
|
||
func ArtifactsName() cli.Flag {
|
||
return &cli.StringFlag{
|
||
Name: constant.ArtifactsName,
|
||
Value: "artifacts.zip",
|
||
Usage: "保存产物名称(保存到系统磁盘的名称)",
|
||
}
|
||
}
|
||
|
||
func Page() cli.Flag {
|
||
return &cli.IntFlag{
|
||
Name: constant.Page,
|
||
Value: 1,
|
||
Usage: "页码(默认:1),中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination",
|
||
}
|
||
}
|
||
|
||
func PerPage() cli.Flag {
|
||
return &cli.IntFlag{
|
||
Name: constant.PerPage,
|
||
Value: 20,
|
||
Usage: "每页列出的项目数(默认:20;最大:100),中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination",
|
||
}
|
||
}
|
||
|
||
func OrderBy(usage string) cli.Flag {
|
||
return &cli.StringFlag{
|
||
Name: constant.OrderBy,
|
||
Value: "created_at",
|
||
Usage: usage,
|
||
}
|
||
}
|
||
|
||
func Scope(value string, usage string) cli.Flag {
|
||
return &cli.StringFlag{
|
||
Name: constant.Scope,
|
||
Value: value,
|
||
Usage: usage,
|
||
}
|
||
}
|