-
-
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
23 changed files
with
375 additions
and
34 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package auth | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
) | ||
|
||
type ctxKey int | ||
|
||
const providerKey ctxKey = 0 | ||
|
||
func FromContext(ctx context.Context) (Provider, error) { | ||
prov, ok := ctx.Value(providerKey).(Provider) | ||
if !ok { | ||
return nil, errors.New("internal error: no provider in context") | ||
} | ||
return prov, nil | ||
} | ||
|
||
func WithContext(pctx context.Context, p Provider) context.Context { | ||
return context.WithValue(pctx, providerKey, p) | ||
} |
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
2 changes: 1 addition & 1 deletion
2
internal/app/cache_test.go → cmd/slackdump/internal/cfg/cache_test.go
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,4 +1,4 @@ | ||
package app | ||
package cfg | ||
|
||
import ( | ||
"errors" | ||
|
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,53 @@ | ||
package emoji | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/rusq/dlog" | ||
|
||
"github.com/rusq/slackdump/v2" | ||
"github.com/rusq/slackdump/v2/auth" | ||
"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/emoji" | ||
) | ||
|
||
var CmdEmoji = &base.Command{ | ||
Run: runEmoji, | ||
Wizard: func(context.Context, *base.Command, []string) error { panic("not implemented") }, | ||
UsageLine: "slackdump emoji [flags]", | ||
Short: "download workspace emojis", | ||
Long: "", | ||
FlagMask: cfg.OmitDownloadFlag | cfg.OmitConfigFlag, | ||
RequireAuth: true, | ||
PrintFlags: true, | ||
} | ||
|
||
// emoji specific flags | ||
var ( | ||
ignoreErrors bool | ||
) | ||
|
||
func init() { | ||
CmdEmoji.Flag.BoolVar(&ignoreErrors, "ignore-errors", true, "ignore download errors (skip failed emojis)") | ||
} | ||
|
||
func runEmoji(ctx context.Context, cmd *base.Command, args []string) { | ||
prov, err := auth.FromContext(ctx) | ||
if err != nil { | ||
base.SetExitStatus(base.SAuthError) | ||
dlog.Printf("auth error: %s", err) | ||
return | ||
} | ||
sess, err := slackdump.NewWithOptions(ctx, prov, cfg.SlackOptions) | ||
if err != nil { | ||
base.SetExitStatus(base.SApplicationError) | ||
dlog.Printf("application error: %s", err) | ||
return | ||
} | ||
if err := emoji.Dl(ctx, sess, cfg.BaseLoc, ignoreErrors); err != nil { | ||
base.SetExitStatus(base.SApplicationError) | ||
dlog.Printf("application error: %s", err) | ||
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 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,13 @@ | ||
package base | ||
|
||
// Some status codes returned by the main executable. | ||
const ( | ||
SNoError = iota | ||
SGenericError | ||
SInvalidParameters | ||
SHelpRequested | ||
SAuthError | ||
SApplicationError | ||
SWorkspaceError | ||
SCacheError | ||
) |
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 @@ | ||
package workspace |
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,76 @@ | ||
package workspace | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/rusq/dlog" | ||
|
||
"github.com/rusq/slackdump/v2/cmd/slackdump/internal/cfg" | ||
"github.com/rusq/slackdump/v2/cmd/slackdump/internal/golang/base" | ||
) | ||
|
||
var CmdListWsp = &base.Command{ | ||
Run: runList, | ||
Wizard: nil, | ||
UsageLine: "slackdump workspace list [flags]", | ||
Short: "list saved workspaces", | ||
Long: ` | ||
List allows to list Slack Workspaces, that you have previously authenticated in. | ||
`, | ||
FlagMask: flagmask, | ||
PrintFlags: true, | ||
} | ||
|
||
func runList(ctx context.Context, cmd *base.Command, args []string) { | ||
entries, err := filepath.Glob(filepath.Join(cfg.CacheDir(), "*.bin")) | ||
if err != nil { | ||
dlog.Printf("error trying to find existing workspaces: %s", err) | ||
base.SetExitStatus(base.SCacheError) | ||
return | ||
} | ||
if len(entries) == 0 { | ||
fmt.Println("No workspaces exist on this device.") | ||
fmt.Println("Run: slackdump workspaces auth to authenticate.") | ||
// TODO: do we want to ask user to authenticate? | ||
return | ||
} | ||
fmt.Printf("Workspaces in %q:\n\n", cfg.CacheDir()) | ||
current, err := Current() | ||
if err != nil { | ||
dlog.Printf("error getting the current workspace: %s", err) | ||
base.SetExitStatus(base.SWorkspaceError) | ||
} | ||
for _, direntry := range entries { | ||
fmt.Println("\t" + formatWsp(direntry, current)) | ||
} | ||
fmt.Println("\nCurrent workspace is marked with ' => '.") | ||
} | ||
|
||
func wspName(filename string) string { | ||
name := filepath.Base(filename) | ||
if name == defaultWspFilename { | ||
name = "default" | ||
} else { | ||
ext := filepath.Ext(name) | ||
name = name[:len(name)-len(ext)] | ||
} | ||
return name | ||
} | ||
|
||
func formatWsp(filename string, current string) string { | ||
timestamp := "unknown" | ||
if fi, err := os.Stat(filename); err == nil { | ||
timestamp = fi.ModTime().Format("2006-01-02 15:04:05") | ||
} | ||
name := wspName(filename) | ||
if filepath.Base(filename) == current { | ||
name = "=> " + name | ||
} else { | ||
name = " " + name | ||
} | ||
|
||
return fmt.Sprintf("%s (last modified: %s)", name, timestamp) | ||
} |
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,3 @@ | ||
package workspace | ||
|
||
// reset deletes all workspaces. |
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 @@ | ||
package workspace |
Oops, something went wrong.