-
-
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
10 changed files
with
307 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
package base | ||
|
||
// StatusCode is the code returned to the OS. | ||
// | ||
//go:generate stringer -type StatusCode -trimprefix S | ||
type StatusCode uint8 | ||
|
||
// Status codes returned by the main executable. | ||
const ( | ||
SNoError = iota | ||
SNoError StatusCode = iota | ||
SGenericError | ||
SInvalidParameters | ||
SHelpRequested | ||
SAuthError | ||
SApplicationError | ||
SWorkspaceError | ||
SCacheError | ||
SUserError | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,116 @@ | ||
package workspace | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/rusq/slackdump/v2/cmd/slackdump/internal/cfg" | ||
"github.com/rusq/slackdump/v2/cmd/slackdump/internal/golang/base" | ||
"github.com/rusq/slackdump/v2/internal/app/appauth" | ||
) | ||
|
||
var CmdWspDel = &base.Command{ | ||
UsageLine: "slackdump workspace del [flags]", | ||
Short: "deletes the saved workspace login information", | ||
Long: ` | ||
Del can be used to delete the Slack Workspace login information (forgets the | ||
workspace). | ||
If the workspace login information is deleted, you will need to re-authorize | ||
in that Slack Workspace by running "slackdump workspace new <name>". | ||
`, | ||
CustomFlags: false, | ||
FlagMask: cfg.OmitAll, | ||
PrintFlags: true, | ||
} | ||
|
||
func init() { | ||
CmdWspDel.Run = runWspDel | ||
} | ||
|
||
var ( | ||
delAll = CmdWspDel.Flag.Bool("a", false, "delete all workspaces") | ||
delConfirm = CmdWspDel.Flag.Bool("y", false, "answer yes to all questions") | ||
) | ||
|
||
func runWspDel(ctx context.Context, cmd *base.Command, args []string) { | ||
if *delAll { | ||
delAllWsp() | ||
} else { | ||
delOneWsp(args) | ||
} | ||
} | ||
|
||
func delAllWsp() { | ||
m, err := appauth.NewManager(cfg.CacheDir()) | ||
if err != nil { | ||
base.SetExitStatusMsg(base.SCacheError, err.Error()) | ||
return | ||
} | ||
|
||
workspaces, err := m.List() | ||
if err != nil { | ||
base.SetExitStatusMsg(base.SApplicationError, err.Error()) | ||
} | ||
|
||
if !*delConfirm && !yesno("This will delete ALL workspaces") { | ||
base.SetExitStatusMsg(base.SNoError, "operation cancelled") | ||
return | ||
} | ||
for _, name := range workspaces { | ||
if err := m.Delete(name); err != nil { | ||
base.SetExitStatusMsg(base.SCacheError, err.Error()) | ||
return | ||
} | ||
fmt.Printf("workspace %q deleted\n", name) | ||
} | ||
} | ||
|
||
func delOneWsp(args []string) { | ||
wsp, err := argsWorkspace(args) | ||
if err != nil { | ||
base.SetExitStatusMsg(base.SInvalidParameters, err.Error()) | ||
return | ||
} | ||
|
||
m, err := appauth.NewManager(cfg.CacheDir()) | ||
if err != nil { | ||
base.SetExitStatusMsg(base.SCacheError, err.Error()) | ||
return | ||
} | ||
|
||
if !m.Exists(wsp) { | ||
base.SetExitStatusMsg(base.SUserError, "workspace does not exist") | ||
return | ||
} | ||
|
||
if !*delConfirm && !yesno(fmt.Sprintf("workspace %q is about to be deleted", wsp)) { | ||
base.SetExitStatusMsg(base.SNoError, "operation cancelled") | ||
return | ||
} | ||
|
||
if err := m.Delete(wsp); err != nil { | ||
base.SetExitStatusMsg(base.SApplicationError, err.Error()) | ||
return | ||
} | ||
fmt.Printf("workspace %q deleted\n", wsp) | ||
} | ||
|
||
func yesno(message string) bool { | ||
for { | ||
fmt.Print(message, "? (y/N) ") | ||
var resp string | ||
fmt.Scanln(&resp) | ||
resp = strings.TrimSpace(resp) | ||
if len(resp) > 0 { | ||
switch strings.ToLower(resp)[0] { | ||
case 'y': | ||
return true | ||
case 'n': | ||
return false | ||
} | ||
} | ||
fmt.Println("Please answer yes or no and press Enter or Return.") | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -37,5 +37,6 @@ Workspaces are stored in cache directory on this device: | |
CmdWspNew, | ||
CmdWspList, | ||
CmdWspSelect, | ||
CmdWspDel, | ||
}, | ||
} |
Oops, something went wrong.