Skip to content

Commit

Permalink
Merge pull request #332 from rusq/workspace-fixes
Browse files Browse the repository at this point in the history
Workspace fixes
  • Loading branch information
rusq authored Oct 6, 2024
2 parents a15a1dc + 363c3f6 commit fe9973e
Show file tree
Hide file tree
Showing 43 changed files with 1,250 additions and 287 deletions.
7 changes: 3 additions & 4 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"

"github.com/rusq/slackdump/v3/internal/fixtures"
"github.com/stretchr/testify/assert"
)

func TestLoad(t *testing.T) {
Expand Down Expand Up @@ -71,7 +72,7 @@ func TestSave(t *testing.T) {
args{ValueAuth{simpleProvider{Token: "token_value", Cookie: []*http.Cookie{
{Name: "d", Value: "abc"},
}}}},
`{"Token":"token_value","Cookie":[{"Name":"d","Value":"abc","Path":"","Domain":"","Expires":"0001-01-01T00:00:00Z","RawExpires":"","MaxAge":0,"Secure":false,"HttpOnly":false,"SameSite":0,"Raw":"","Unparsed":null}]}` + "\n",
`{"Token":"token_value","Cookie":[{"Name":"d","Value":"abc","Quoted":false,"Path":"","Domain":"","Expires":"0001-01-01T00:00:00Z","RawExpires":"","MaxAge":0,"Secure":false,"HttpOnly":false,"SameSite":0,"Partitioned":false,"Raw":"","Unparsed":null}]}` + "\n",
false,
},
{
Expand Down Expand Up @@ -110,9 +111,7 @@ func TestSave(t *testing.T) {
return
}
gotW := w.String()
if gotW != tt.wantW {
t.Errorf("Save() = %v, want %v", gotW, tt.wantW)
}
assert.Equal(t, tt.wantW, gotW)
})
}
}
1 change: 1 addition & 0 deletions auth/browser/playwright_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clienter_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/slackdump/internal/emoji/emojidl/emoji_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/slackdump/internal/golang/base/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ const (
SWorkspaceError // Workspace Error
SCacheError // Cache Error
SUserError // User Error
SCancelled // Cancelled
)
5 changes: 3 additions & 2 deletions cmd/slackdump/internal/golang/base/statuscode_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions cmd/slackdump/internal/golang/base/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ package base

import (
"fmt"
"io"
"os"
"strings"
)

func YesNo(message string) bool {
return YesNoWR(os.Stdout, os.Stdin, message)
}

func YesNoWR(w io.Writer, r io.Reader, message string) bool {
for {
fmt.Print(message, "? (y/N) ")
fmt.Fprint(w, message, "? (y/N) ")
var resp string
fmt.Scanln(&resp)
fmt.Fscanln(r, &resp)
resp = strings.TrimSpace(resp)
if len(resp) > 0 {
switch strings.ToLower(resp)[0] {
Expand All @@ -19,6 +25,6 @@ func YesNo(message string) bool {
return false
}
}
fmt.Println("Please answer yes or no and press Enter or Return.")
fmt.Fprintln(w, "Please answer yes or no and press Enter or Return.")
}
}
62 changes: 62 additions & 0 deletions cmd/slackdump/internal/golang/base/ui_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package base

import (
"bytes"
"io"
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func TestYesNoWR(t *testing.T) {
type args struct {
r io.Reader
message string
}
tests := []struct {
name string
args args
want bool
wantW string
}{
{
name: "yes",
args: args{
r: strings.NewReader("y\n"),
message: "message",
},
want: true,
wantW: "message? (y/N) ",
},
{
name: "no",
args: args{
r: strings.NewReader("n\n"),
message: "message",
},
want: false,
wantW: "message? (y/N) ",
},
{
name: "any other key",
args: args{
r: strings.NewReader("x\nn\n"),
message: "message",
},
want: false,
wantW: "message? (y/N) Please answer yes or no and press Enter or Return.\nmessage? (y/N) ",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
w := &bytes.Buffer{}
if got := YesNoWR(w, tt.args.r, tt.args.message); got != tt.want {
t.Errorf("YesNoWR() = %v, want %v", got, tt.want)
}
if gotW := w.String(); !assert.Equal(t, tt.wantW, gotW) {
t.Errorf("YesNoWR() = %v, want %v", gotW, tt.wantW)
}
})
}
}
1 change: 1 addition & 0 deletions cmd/slackdump/internal/list/mocks_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 10 additions & 12 deletions cmd/slackdump/internal/workspace/del.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ var (

var CmdWspDel = &base.Command{
UsageLine: baseCommand + " del [flags]",
Short: "deletes the saved authentication information",
Short: "deletes the saved workspace credentials",
Long: `
# Auth Del(ete) Command
# Workspace Delete Command
Use ` + "`del`" + ` to delete the Slack Workspace login information ("forget"
the workspace).
If the workspace login information is deleted, in case you will need to use this
workspace again, you will need to login into that workspace again by running
` + " `slackdump auth new <name>`." + `
If the workspace login information is deleted, you will need to login into that
workspace again by running ` + " `slackdump auth new <name>`" + `, in case you
need to use this workspace again.
Slackdump will ask for the confirmation before deleting. To omit the
question, use ` + "`-y`" + ` flag.
Expand All @@ -42,7 +42,7 @@ func init() {

var (
delAll = CmdWspDel.Flag.Bool("a", false, "delete all workspaces")
delConfirm = CmdWspDel.Flag.Bool("y", false, "answer yes to all questions")
delConfirm = CmdWspDel.Flag.Bool("y", false, "answer 'yes' to all questions")
)

func runWspDel(ctx context.Context, cmd *base.Command, args []string) error {
Expand All @@ -52,23 +52,21 @@ func runWspDel(ctx context.Context, cmd *base.Command, args []string) error {
return err
}
if *delAll {
return delAllWsp(m)
return delAllWsp(m, *delConfirm)
} else {
return delOneWsp(m, args)
}
}

var yesno = base.YesNo

func delAllWsp(m manager) error {
func delAllWsp(m manager, confirm bool) error {
workspaces, err := m.List()
if err != nil {
base.SetExitStatus(base.SApplicationError)
return err
}

if !*delConfirm && !yesno("This will delete ALL workspaces") {
base.SetExitStatus(base.SNoError)
if !confirm && !yesno("This will delete ALL workspaces") {
base.SetExitStatus(base.SCancelled)
return ErrOpCancelled
}
for _, name := range workspaces {
Expand Down
Loading

0 comments on commit fe9973e

Please sign in to comment.