From 7a05be436c0a494bcb3c3edd4461496e7efa63ec Mon Sep 17 00:00:00 2001 From: Norwin Date: Wed, 29 Sep 2021 04:42:51 +0800 Subject: [PATCH] Add more flags to `tea repo create` (#409) adds the `--template` and `--trustmodel` flags Co-authored-by: Norwin Reviewed-on: https://gitea.com/gitea/tea/pulls/409 Reviewed-by: Lunny Xiao Reviewed-by: techknowlogick Co-authored-by: Norwin Co-committed-by: Norwin --- cmd/repos/create.go | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/cmd/repos/create.go b/cmd/repos/create.go index 51d989c..a6f1547 100644 --- a/cmd/repos/create.go +++ b/cmd/repos/create.go @@ -79,6 +79,14 @@ var CmdRepoCreate = cli.Command{ Required: false, Usage: "use custom default branch (need --init)", }, + &cli.BoolFlag{ + Name: "template", + Usage: "make repo a template repo", + }, + &cli.StringFlag{ + Name: "trustmodel", + Usage: "select trust model (committer,collaborator,collaborator+committer)", + }, }, flags.LoginOutputFlags...), } @@ -86,9 +94,24 @@ func runRepoCreate(cmd *cli.Context) error { ctx := context.InitCommand(cmd) client := ctx.Login.Client() var ( - repo *gitea.Repository - err error + repo *gitea.Repository + err error + trustmodel gitea.TrustModel ) + + if ctx.IsSet("trustmodel") { + switch ctx.String("trustmodel") { + case "committer": + trustmodel = gitea.TrustModelCommitter + case "collaborator": + trustmodel = gitea.TrustModelCollaborator + case "collaborator+committer": + trustmodel = gitea.TrustModelCollaboratorCommitter + default: + return fmt.Errorf("unknown trustmodel type '%s'", ctx.String("trustmodel")) + } + } + opts := gitea.CreateRepoOption{ Name: ctx.String("name"), Description: ctx.String("description"), @@ -99,6 +122,8 @@ func runRepoCreate(cmd *cli.Context) error { License: ctx.String("license"), Readme: ctx.String("readme"), DefaultBranch: ctx.String("branch"), + Template: ctx.Bool("template"), + TrustModel: trustmodel, } if len(ctx.String("owner")) != 0 { repo, _, err = client.CreateOrgRepo(ctx.String("owner"), opts)