-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
411 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package workspaceui | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/rusq/slackdump/v3/auth" | ||
"github.com/rusq/slackdump/v3/auth/auth_ui" | ||
) | ||
|
||
type manager interface { | ||
SaveProvider(workspace string, p auth.Provider) error | ||
Select(workspace string) error | ||
} | ||
|
||
// createAndSelect creates a new workspace with the given provider and selects it. | ||
// It returns the workspace name on success. | ||
func createAndSelect(ctx context.Context, m manager, prov auth.Provider) (string, error) { | ||
authInfo, err := prov.Test(ctx) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
wsp, err := auth_ui.Sanitize(authInfo.URL) | ||
if err != nil { | ||
return "", err | ||
} | ||
if err := m.SaveProvider(wsp, prov); err != nil { | ||
return "", err | ||
} | ||
if err := m.Select(wsp); err != nil { | ||
return "", err | ||
} | ||
return wsp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package workspaceui | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/charmbracelet/huh" | ||
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui" | ||
) | ||
|
||
func askRetry(ctx context.Context, name string, err error) (retry bool) { | ||
var msg string = fmt.Sprintf("The following error occurred: %s", err) | ||
if name != "" { | ||
msg = fmt.Sprintf("Error creating workspace %q: %s", name, err) | ||
} | ||
|
||
if err := huh.NewForm(huh.NewGroup( | ||
huh.NewConfirm().Title("Error Creating Workspace"). | ||
Description(msg). | ||
Value(&retry).Affirmative("Retry").Negative("Cancel"), | ||
)).WithTheme(ui.HuhTheme).RunWithContext(ctx); err != nil { | ||
return false | ||
} | ||
return retry | ||
} | ||
|
||
func success(ctx context.Context, workspace string) error { | ||
return huh.NewForm(huh.NewGroup( | ||
huh.NewNote().Title("Great Success!"). | ||
Description(fmt.Sprintf("Workspace %q was added and selected.\n\n", workspace)). | ||
Next(true). | ||
NextLabel("Exit"), | ||
)).WithTheme(ui.HuhTheme).RunWithContext(ctx) | ||
} |
Oops, something went wrong.