fix: do not ask for confirmation right after prompting for input

secret set, variable set, team create, webhook create and admin user
create asked a confirmation that defaults to No right after the user
typed the missing values, so pressing Enter discarded the input. They
now submit what the user entered; deletions still confirm.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-11 21:59:18 +02:00
1 parent fcfc497a77
commit b6b3ddc91b
6 files changed
+43 -29

No files matched your search

+1 -3
View File
@@ -78,7 +78,6 @@ func (a *application) actionValueCommand(secret bool) *cobra.Command {
if strings.EqualFold(name, "CI") || strings.HasPrefix(strings.ToUpper(name), "GITEA_") || strings.HasPrefix(strings.ToUpper(name), "GITHUB_") {
return clierr.Wrap(clierr.Usage, errors.New("CI and names beginning GITEA_ or GITHUB_ are reserved"))
}
prompted := false
if verb == "set" {
var err error
if value, err = a.readSecret(cmd, value, file, "value", "value-file"); err != nil {
@@ -100,7 +99,6 @@ func (a *application) actionValueCommand(secret bool) *cobra.Command {
if err != nil {
return err
}
prompted = true
}
if value == "" {
return clierr.Wrap(clierr.Usage, fmt.Errorf("%s value cannot be empty", kind))
@@ -113,7 +111,7 @@ func (a *application) actionValueCommand(secret bool) *cobra.Command {
if err != nil {
return err
}
if verb == "delete" || prompted {
if verb == "delete" {
if err := a.confirm(cmd, verb+" Actions "+kind+" "+name); err != nil {
return err
}
+2 -6
View File
@@ -76,7 +76,6 @@ func (a *application) adminCommand() *cobra.Command {
command.Flags().BoolVar(&mustChangePassword, "must-change-password", true, "Require password change on next sign-in (use =false to disable)")
}
command.RunE = func(cmd *cobra.Command, args []string) error {
prompted := false
if verb == "create" {
if len(args) > 0 {
if cmd.Flags().Changed("username") {
@@ -88,11 +87,9 @@ func (a *application) adminCommand() *cobra.Command {
value *string
flag string
}{{&username, "username"}, {&email, "email"}} {
completed, err := a.require(cmd, field.value, field.flag)
if err != nil {
if _, err := a.require(cmd, field.value, field.flag); err != nil {
return err
}
prompted = prompted || completed
}
opts.Email = &email
opts.FullName = &fullName
@@ -159,7 +156,6 @@ func (a *application) adminCommand() *cobra.Command {
if password != confirmation {
return clierr.Wrap(clierr.Usage, errors.New("passwords do not match"))
}
prompted = true
}
if password == "" {
return clierr.Wrap(clierr.Usage, errors.New("password cannot be empty"))
@@ -178,7 +174,7 @@ func (a *application) adminCommand() *cobra.Command {
if err != nil {
return err
}
if verb == "delete" || prompted {
if verb == "delete" {
if err := a.confirm(cmd, verb+" account "+username+" on "+target.Host); err != nil {
return err
}
+1 -1
View File
@@ -30,7 +30,7 @@ func TestAdminPromptAndFlagsReachEquivalentPayloads(t *testing.T) {
require.NoError(t, Execute(context.Background(), deps, []string{"admin", "user", "create", "account", "--full-name", "Test Account"}))
require.Equal(t, []string{"email"}, prompt.asked)
require.Len(t, prompt.secrets, 2)
require.Len(t, prompt.confirmations, 1)
require.Empty(t, prompt.confirmations)
out.Reset()
require.NoError(t, Execute(context.Background(), deps, []string{"admin", "user", "create", "account", "--full-name", "Test Account", "--email", "account@example.test", "--password", " preserved password ", "--no-input"}))
require.Equal(t, payloads[0], payloads[1])
+1 -8
View File
@@ -61,7 +61,6 @@ func (a *application) teamCommand() *cobra.Command {
command.RunE = func(cmd *cobra.Command, args []string) error {
var id int64
var err error
prompted := false
opts := services.TeamOptions{}
if verb != "create" {
id, err = number(args[0])
@@ -85,8 +84,7 @@ func (a *application) teamCommand() *cobra.Command {
}
}
if verb == "create" {
prompted, err = a.require(cmd, &name, "name")
if err != nil {
if _, err := a.require(cmd, &name, "name"); err != nil {
return err
}
opts.Name = &name
@@ -131,11 +129,6 @@ func (a *application) teamCommand() *cobra.Command {
return err
}
service := services.Teams{Client: target.client}
if prompted {
if err := a.confirm(cmd, "create team "+name+" in "+args[0]+" on "+target.Host); err != nil {
return err
}
}
var item services.Team
switch verb {
case "view":
+35 -2
View File
@@ -257,8 +257,6 @@ func TestConfirmationsNameResolvedValues(t *testing.T) {
}{
{[]string{"wiki", "create"}, map[string]string{"title": "Home", "body": "text"}, "create wiki page Home on alice/project"},
{[]string{"release", "create"}, map[string]string{"tag": "v1.0.0"}, "create release v1.0.0 on alice/project"},
{[]string{"webhook", "create"}, map[string]string{"url": "https://hooks.test/path"}, "create webhook https://hooks.test/path"},
{[]string{"team", "create", "acme"}, map[string]string{"name": "Developers"}, "create team Developers in acme"},
{[]string{"time", "delete", "5", "7"}, nil, "delete tracked time entry 7 on alice/project #5"},
} {
t.Run(strings.Join(tc.args, " "), func(t *testing.T) {
@@ -280,6 +278,41 @@ func TestConfirmationsNameResolvedValues(t *testing.T) {
}
}
func TestPromptedCreateSubmitsWithoutConfirmation(t *testing.T) {
for _, tc := range []struct {
args []string
inputs map[string]string
secret, write string
}{
{[]string{"secret", "set", "TOKEN"}, nil, "private", "PUT /api/v1/repos/alice/project/actions/secrets/TOKEN"},
{[]string{"variable", "set", "MODE"}, map[string]string{"Variable value": "fast"}, "", "POST /api/v1/repos/alice/project/actions/variables/MODE"},
{[]string{"webhook", "create"}, map[string]string{"url": "https://hooks.test/path"}, "", "POST /api/v1/repos/alice/project/hooks"},
{[]string{"team", "create", "acme"}, map[string]string{"name": "Developers"}, "", "POST /api/v1/orgs/acme/teams"},
} {
t.Run(strings.Join(tc.args, " "), func(t *testing.T) {
var writes []string
server := newAuthenticatedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
w.WriteHeader(http.StatusNotFound)
return
}
writes = append(writes, r.Method+" "+r.URL.Path)
w.WriteHeader(http.StatusCreated)
_, _ = w.Write([]byte(`{"id":1}`))
}))
defer server.Close()
deps, _, _ := testDeps(t)
deps.Getenv = serverEnv(server.URL, map[string]string{"TEA_REPO": "alice/project"})
prompt := &scriptedPrompter{inputs: tc.inputs, secret: tc.secret}
deps.Prompter = prompt
deps.Streams.InTTY, deps.Streams.ErrTTY = true, true
require.NoError(t, Execute(context.Background(), deps, tc.args))
require.Empty(t, prompt.confirmations)
require.Equal(t, []string{tc.write}, writes)
})
}
}
type unexpectedForms struct{ t *testing.T }
func (f unexpectedForms) CreateIssue(context.Context, terminal.IssueFormChoices) (terminal.IssueFormValues, error) {
+3 -9
View File
@@ -88,7 +88,6 @@ func (a *application) webhookCommand() *cobra.Command {
command.RunE = func(cmd *cobra.Command, args []string) error {
var id int64
var err error
prompted := false
opts := services.WebhookOptions{}
if verb != "create" {
id, err = number(args[0])
@@ -125,8 +124,7 @@ func (a *application) webhookCommand() *cobra.Command {
endpoint = args[0]
}
if verb == "create" {
prompted, err = a.require(cmd, &endpoint, "url")
if err != nil {
if _, err := a.require(cmd, &endpoint, "url"); err != nil {
return err
}
}
@@ -200,12 +198,8 @@ func (a *application) webhookCommand() *cobra.Command {
if err != nil {
return err
}
if verb == "delete" || prompted {
subject := endpoint
if verb == "delete" {
subject = args[0]
}
if err := a.confirm(cmd, verb+" webhook "+subject); err != nil {
if verb == "delete" {
if err := a.confirm(cmd, "delete webhook "+args[0]); err != nil {
return err
}
}