Skip to content

Replace --delete-remote-wip-branch with a prompt for the user on whether they would like to continue #462

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
wants to merge 1 commit into
base: main
Choose a base branch
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
32 changes: 32 additions & 0 deletions ask/ask.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ask

import (
"bufio"
"github.com/remotemobprogramming/mob/v5/say"
"io"
"os"
"strings"
)

func YesNo(q string) bool {
say.Say(q)
reader := ReadFromConsole(io.Reader(os.Stdin))
for {
text, err := reader.ReadString('\n')
if err != nil && err != io.EOF {
say.Error("Error reading from console")
return false
}

if strings.ToLower(text) == "y\n" || text == "\n" {
return true
} else {
say.Say("Aborted")
return false
}
}
}

var ReadFromConsole = func(reader io.Reader) *bufio.Reader {
return bufio.NewReader(reader)
}
2 changes: 0 additions & 2 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ func ParseArgs(args []string, configuration Configuration) (command string, para
newConfiguration.StartCreate = true
case "--join", "-j":
newConfiguration.StartJoin = true
case "--delete-remote-wip-branch":
newConfiguration.ResetDeleteRemoteWipBranch = true
case "--room":
if i+1 != len(args) {
newConfiguration.TimerRoom = args[i+1]
Expand Down
5 changes: 3 additions & 2 deletions mob.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"errors"
"fmt"
"github.com/remotemobprogramming/mob/v5/ask"
config "github.com/remotemobprogramming/mob/v5/configuration"
"github.com/remotemobprogramming/mob/v5/goal"
"github.com/remotemobprogramming/mob/v5/help"
Expand Down Expand Up @@ -519,8 +520,8 @@ func moo(configuration config.Configuration) {
func reset(configuration config.Configuration) {
if configuration.ResetDeleteRemoteWipBranch {
deleteRemoteWipBranch(configuration)
} else {
say.Fix("Executing this command deletes the mob branch for everyone. If you're sure you want that, use", configuration.Mob("reset --delete-remote-wip-branch"))
} else if ask.YesNo("Executing this command deletes the mob branch for everyone. Are you sure you want to continue? (Y/n)") {
deleteRemoteWipBranch(configuration)
}
}

Expand Down
18 changes: 15 additions & 3 deletions mob_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package main

import (
"bufio"
"fmt"
"github.com/remotemobprogramming/mob/v5/ask"
config "github.com/remotemobprogramming/mob/v5/configuration"
"github.com/remotemobprogramming/mob/v5/open"
"github.com/remotemobprogramming/mob/v5/say"
"io"
"os"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -416,7 +419,7 @@ func TestReset(t *testing.T) {

reset(configuration)

assertOutputContains(t, output, "mob reset --delete-remote-wip-branch")
assertOutputContains(t, output, "Executing this command deletes the mob branch for everyone. Are you sure you want to continue? (Y/n)")
}

func TestResetDeleteRemoteWipBranch(t *testing.T) {
Expand All @@ -435,10 +438,11 @@ func TestResetCommit(t *testing.T) {
createFile(t, "example.txt", "contentIrrelevant")
next(configuration)
assertMobSessionBranches(t, configuration, "mob-session")
simulateUserInput("y")

reset(configuration)

assertOutputContains(t, output, "mob reset --delete-remote-wip-branch")
assertOutputContains(t, output, "Executing this command deletes the mob branch for everyone. Are you sure you want to continue? (Y/n)")
assertMobSessionBranches(t, configuration, "mob-session")
}

Expand All @@ -463,10 +467,12 @@ func TestResetCommitBranch(t *testing.T) {
createFile(t, "example.txt", "contentIrrelevant")
next(configuration)
assertMobSessionBranches(t, configuration, "mob/master-green")
simulateUserInput("n")

reset(configuration)

assertOutputContains(t, output, "mob reset --delete-remote-wip-branch")
assertOutputContains(t, output, "Executing this command deletes the mob branch for everyone. Are you sure you want to continue? (Y/n)")
assertOutputContains(t, output, "Aborted")
assertMobSessionBranches(t, configuration, "mob/master-green")
}

Expand Down Expand Up @@ -2015,6 +2021,12 @@ func setup(t *testing.T) (output *string, configuration config.Configuration) {
return output, configuration
}

func simulateUserInput(a string) {
ask.ReadFromConsole = func(reader io.Reader) *bufio.Reader {
return bufio.NewReader(strings.NewReader(a))
}
}

func captureOutput(t *testing.T) *string {
messages := ""
say.PrintToConsole = func(text string) {
Expand Down