Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

refactor(actions): take rename's prompt off the TUI; drop tui from restack #1164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jonnii wants to merge 1 commit into main
base: main
Choose a base branch
Loading
from jonnii/20260605031052/take-rename-s-prompt-off-the-TUI-drop-tui-from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions internal/actions/rename.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/getstackit/stackit/internal/actions/validation"
"github.com/getstackit/stackit/internal/app"
"github.com/getstackit/stackit/internal/output"
"github.com/getstackit/stackit/internal/tui"
"github.com/getstackit/stackit/internal/utils"
)

Expand All @@ -16,8 +15,18 @@ type RenameOptions struct {
Force bool
}

// RenameHandler supplies a new branch name interactively when one is not given
// on the command line. The CLI adapter implements it; the action layer does not
// import the TUI.
type RenameHandler interface {
// PromptNewName asks the user for a new branch name, given the current one.
// Implementations should return an error when prompting is not possible
// (e.g. non-interactive mode).
PromptNewName(currentName string) (string, error)
}

// RenameAction renames the current branch and updates metadata
func RenameAction(ctx *app.Context, opts RenameOptions) error {
func RenameAction(ctx *app.Context, opts RenameOptions, handler RenameHandler) error {
eng := ctx.Engine
out := ctx.Output

Expand All @@ -29,12 +38,8 @@ func RenameAction(ctx *app.Context, opts RenameOptions) error {

newName := opts.NewName
if newName == "" {
if !utils.IsInteractive() {
return fmt.Errorf("branch name is required in non-interactive mode")
}

var err error
newName, err = tui.PromptTextInput("Enter new branch name:", currentBranch)
newName, err = handler.PromptNewName(currentBranch)
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions internal/actions/restack.go
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/getstackit/stackit/internal/engine"
"github.com/getstackit/stackit/internal/handlers"
"github.com/getstackit/stackit/internal/rerere"
"github.com/getstackit/stackit/internal/tui"
"github.com/getstackit/stackit/internal/utils"
)

Expand Down Expand Up @@ -154,7 +153,7 @@ func RestackAction(ctx *app.Context, plan *RestackPlan, handler handlers.Restack
handler = &handlers.NullRestackHandler{}
}

interactiveRererePrompt := ctx.Interactive && !ctx.Quiet && tui.IsTTY()
interactiveRererePrompt := ctx.Interactive && !ctx.Quiet && utils.IsTTY()
if _, jsonOutput := handler.(*handlers.JSONRestackHandler); jsonOutput {
interactiveRererePrompt = false
}
Expand Down
18 changes: 17 additions & 1 deletion internal/cli/branch/rename.go
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
package branch

import (
"fmt"

"github.com/spf13/cobra"

"github.com/getstackit/stackit/internal/actions"
"github.com/getstackit/stackit/internal/app"
"github.com/getstackit/stackit/internal/cli/common"
"github.com/getstackit/stackit/internal/tui"
"github.com/getstackit/stackit/internal/utils"
)

// renameHandler prompts for a new branch name via the TUI when running
// interactively, and reports that a name is required otherwise. It keeps the
// TUI dependency in the CLI adapter, out of the action layer.
type renameHandler struct{}

func (renameHandler) PromptNewName(currentName string) (string, error) {
if !utils.IsInteractive() {
return "", fmt.Errorf("branch name is required in non-interactive mode")
}
return tui.PromptTextInput("Enter new branch name:", currentName)
}

// NewRenameCmd creates the rename command
func NewRenameCmd() *cobra.Command {
var (
Expand Down Expand Up @@ -35,7 +51,7 @@ Note that this removes any association to a pull request, as GitHub pull request
Force: force,
}

return actions.RenameAction(ctx, opts)
return actions.RenameAction(ctx, opts, renameHandler{})
})
},
}
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /