Skip to content

Commit

Permalink
fix funky workspace selection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Jan 12, 2024
1 parent a427a60 commit 69fbcef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/slackdump/internal/auth/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func runList(ctx context.Context, cmd *base.Command, args []string) error {
if err != nil {
if errors.Is(err, cache.ErrNoWorkspaces) {
base.SetExitStatus(base.SUserError)
return errors.New("no authenticated workspaces, please run \"slackdump workspace new\"")
return errors.New("no authenticated workspaces, please run \"slackdump " + baseCommand + " new\"")
}
base.SetExitStatus(base.SCacheError)
return err
Expand Down
23 changes: 20 additions & 3 deletions internal/cache/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,30 @@ func (m *Manager) Current() (string, error) {

// selectDefault selects the default workspace if it exists.
func (m *Manager) selectDefault() (string, error) {
var wsp = defName
if !m.Exists(defName) {
return "", ErrNoDefault
// the default workspace does not exist, pick any
w, err := m.firstAvailable()
if err != nil {
return "", err
}
wsp = w
}
if err := m.Select(defName); err != nil {
if err := m.Select(wsp); err != nil {
return "", err
}
return defName, nil
return wsp, nil
}

func (m *Manager) firstAvailable() (string, error) {
all, err := m.List()
if err != nil {
return "", err
}
if len(all) == 0 {
return "", ErrNoWorkspaces
}
return all[0], nil
}

// Select selects the existing workspace with "name".
Expand Down

0 comments on commit 69fbcef

Please sign in to comment.