mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
fix(repo): reject --repo on commands that act on no repository
tea repo list -R acme/service listed the account's repositories and tea repo create foo -R alice/project created alice/foo: the flag was silently ignored. repo list, repo create, repo migrate and search repo now fail with a usage error that suggests the intended command, such as "--repo is not used by repo list; did you mean: tea repo list acme". repo list takes the owner as an argument (--owner still works), and repo create accepts OWNER/NAME, creating in the organization OWNER. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
7 files changed
+96
-7
No files matched your search
@@ -4,6 +4,7 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
@@ -32,6 +33,15 @@ func (a *application) repoCreateCommand() *cobra.Command {
|
||||
}
|
||||
opts.Name = args[0]
|
||||
}
|
||||
if err := a.rejectRepoFlag(cmd, func(owner string) string { return "tea repo create " + owner + "/" + cmp.Or(opts.Name, "NAME") }); err != nil {
|
||||
return err
|
||||
}
|
||||
if owner, name, ok := strings.Cut(opts.Name, "/"); ok {
|
||||
if cmd.Flags().Changed("org") {
|
||||
return clierr.Wrap(clierr.Usage, errors.New("supply the owner as OWNER/NAME or --org, not both"))
|
||||
}
|
||||
org, opts.Name = owner, name
|
||||
}
|
||||
if cmd.Flags().Changed("team") && (org == "" || strings.TrimSpace(team) == "") {
|
||||
return clierr.Wrap(clierr.Usage, errors.New("--team requires --org and a team name"))
|
||||
}
|
||||
@@ -66,9 +76,6 @@ func (a *application) repoCreateCommand() *cobra.Command {
|
||||
}
|
||||
selected := *a
|
||||
if source != "" {
|
||||
if a.options.repo != "" {
|
||||
return clierr.Wrap(clierr.Usage, errors.New("--template and --repo cannot both select a source repository"))
|
||||
}
|
||||
for _, flag := range []string{"auto-init", "label-template", "gitignores", "license", "readme", "as-template", "trust-model", "object-format"} {
|
||||
if cmd.Flags().Changed(flag) {
|
||||
return clierr.Wrap(clierr.Usage, errors.New("repository initialization options cannot be combined with --template"))
|
||||
@@ -86,6 +93,12 @@ func (a *application) repoCreateCommand() *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !cmd.Flags().Changed("org") && strings.EqualFold(org, target.User) {
|
||||
if team != "" {
|
||||
return clierr.Wrap(clierr.Usage, errors.New("--team requires a repository owned by an organization"))
|
||||
}
|
||||
org = ""
|
||||
}
|
||||
if prompted {
|
||||
if err := a.confirm(cmd, "Create repository "+opts.Name+" on "+target.Host); err != nil {
|
||||
return err
|
||||
|
||||
Reference in new issue
Block a user