diff --git a/cmd/slackdump/internal/archive/archive.go b/cmd/slackdump/internal/archive/archive.go index ad0d2967..b0eba0ef 100644 --- a/cmd/slackdump/internal/archive/archive.go +++ b/cmd/slackdump/internal/archive/archive.go @@ -8,6 +8,7 @@ import ( "time" "github.com/rusq/fsadapter" + "github.com/rusq/slackdump/v3/cmd/slackdump/internal/bootstrap" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base" "github.com/rusq/slackdump/v3/internal/chunk" @@ -63,7 +64,7 @@ func RunArchive(ctx context.Context, cmd *base.Command, args []string) error { return err } - sess, err := cfg.SlackdumpSession(ctx) + sess, err := bootstrap.SlackdumpSession(ctx) if err != nil { base.SetExitStatus(base.SInitializationError) return err diff --git a/cmd/slackdump/internal/archive/search.go b/cmd/slackdump/internal/archive/search.go index e0b9c771..d460df2a 100644 --- a/cmd/slackdump/internal/archive/search.go +++ b/cmd/slackdump/internal/archive/search.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/rusq/fsadapter" + "github.com/rusq/slackdump/v3/cmd/slackdump/internal/bootstrap" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base" "github.com/rusq/slackdump/v3/internal/chunk" @@ -109,7 +110,7 @@ func initController(ctx context.Context, args []string) (*control.Controller, fu return nil, nil, errNoOutput } - sess, err := cfg.SlackdumpSession(ctx) + sess, err := bootstrap.SlackdumpSession(ctx) if err != nil { base.SetExitStatus(base.SInitializationError) return nil, nil, err diff --git a/cmd/slackdump/internal/bootstrap/bootstrap.go b/cmd/slackdump/internal/bootstrap/bootstrap.go index e2a177b0..008e8cf1 100644 --- a/cmd/slackdump/internal/bootstrap/bootstrap.go +++ b/cmd/slackdump/internal/bootstrap/bootstrap.go @@ -1,20 +1,3 @@ // Package bootstrap contains some initialisation functions that are shared // between main some other top level commands, i.e. wizard. package bootstrap - -import ( - "context" - - "github.com/rusq/slackdump/v3/auth" - "github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg" - "github.com/rusq/slackdump/v3/cmd/slackdump/internal/workspace" -) - -// CurrentProviderCtx returns the context with the current provider. -func CurrentProviderCtx(ctx context.Context) (context.Context, error) { - prov, err := workspace.AuthCurrent(ctx, cfg.CacheDir(), cfg.Workspace, cfg.LegacyBrowser) - if err != nil { - return ctx, err - } - return auth.WithContext(ctx, prov), nil -} diff --git a/cmd/slackdump/internal/cfg/slackdump.go b/cmd/slackdump/internal/bootstrap/slackdump.go similarity index 52% rename from cmd/slackdump/internal/cfg/slackdump.go rename to cmd/slackdump/internal/bootstrap/slackdump.go index b0ce9109..b522fe60 100644 --- a/cmd/slackdump/internal/cfg/slackdump.go +++ b/cmd/slackdump/internal/bootstrap/slackdump.go @@ -1,10 +1,12 @@ -package cfg +package bootstrap import ( "context" "github.com/rusq/slackdump/v3" "github.com/rusq/slackdump/v3/auth" + "github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg" + "github.com/rusq/slackdump/v3/cmd/slackdump/internal/workspace" ) // SlackdumpSession returns the Slackdump Session initialised with the provider @@ -18,9 +20,9 @@ func SlackdumpSession(ctx context.Context, opts ...slackdump.Option) (*slackdump } var stdOpts = []slackdump.Option{ - slackdump.WithLogger(Log), - slackdump.WithForceEnterprise(ForceEnterprise), - slackdump.WithLimits(Limits), + slackdump.WithLogger(cfg.Log), + slackdump.WithForceEnterprise(cfg.ForceEnterprise), + slackdump.WithLimits(cfg.Limits), } stdOpts = append(stdOpts, opts...) @@ -30,3 +32,12 @@ func SlackdumpSession(ctx context.Context, opts ...slackdump.Option) (*slackdump stdOpts..., ) } + +// CurrentProviderCtx returns the context with the current provider. +func CurrentProviderCtx(ctx context.Context) (context.Context, error) { + prov, err := workspace.AuthCurrent(ctx, cfg.CacheDir(), cfg.Workspace, cfg.LegacyBrowser) + if err != nil { + return ctx, err + } + return auth.WithContext(ctx, prov), nil +} diff --git a/cmd/slackdump/internal/cfg/slackdump_test.go b/cmd/slackdump/internal/bootstrap/slackdump_test.go similarity index 98% rename from cmd/slackdump/internal/cfg/slackdump_test.go rename to cmd/slackdump/internal/bootstrap/slackdump_test.go index 10564974..8c71d816 100644 --- a/cmd/slackdump/internal/cfg/slackdump_test.go +++ b/cmd/slackdump/internal/bootstrap/slackdump_test.go @@ -1,4 +1,4 @@ -package cfg +package bootstrap import ( "context" diff --git a/cmd/slackdump/internal/diag/record.go b/cmd/slackdump/internal/diag/record.go index ceb073e5..df716f0f 100644 --- a/cmd/slackdump/internal/diag/record.go +++ b/cmd/slackdump/internal/diag/record.go @@ -8,6 +8,7 @@ import ( "io" "os" + "github.com/rusq/slackdump/v3/cmd/slackdump/internal/bootstrap" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base" "github.com/rusq/slackdump/v3/internal/chunk" @@ -55,7 +56,7 @@ func runRecord(ctx context.Context, _ *base.Command, args []string) error { return errors.New("missing channel argument") } - sess, err := cfg.SlackdumpSession(ctx) + sess, err := bootstrap.SlackdumpSession(ctx) if err != nil { base.SetExitStatus(base.SInitializationError) return err diff --git a/cmd/slackdump/internal/dump/dump.go b/cmd/slackdump/internal/dump/dump.go index c25ecdae..cf252b9f 100644 --- a/cmd/slackdump/internal/dump/dump.go +++ b/cmd/slackdump/internal/dump/dump.go @@ -14,6 +14,7 @@ import ( "time" "github.com/rusq/fsadapter" + "github.com/rusq/slackdump/v3/cmd/slackdump/internal/bootstrap" "github.com/rusq/slackdump/v3" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg" @@ -110,7 +111,7 @@ func RunDump(ctx context.Context, _ *base.Command, args []string) error { } }() - sess, err := cfg.SlackdumpSession(ctx, slackdump.WithFilesystem(fsa)) + sess, err := bootstrap.SlackdumpSession(ctx, slackdump.WithFilesystem(fsa)) if err != nil { base.SetExitStatus(base.SInitializationError) return err diff --git a/cmd/slackdump/internal/emoji/emoji.go b/cmd/slackdump/internal/emoji/emoji.go index 1fb67507..532395e0 100644 --- a/cmd/slackdump/internal/emoji/emoji.go +++ b/cmd/slackdump/internal/emoji/emoji.go @@ -6,6 +6,7 @@ import ( "github.com/rusq/fsadapter" "github.com/rusq/slackdump/v3" + "github.com/rusq/slackdump/v3/cmd/slackdump/internal/bootstrap" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/emoji/emojidl" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base" @@ -38,7 +39,7 @@ func run(ctx context.Context, cmd *base.Command, args []string) error { } defer fsa.Close() - sess, err := cfg.SlackdumpSession(ctx, slackdump.WithFilesystem(fsa)) + sess, err := bootstrap.SlackdumpSession(ctx, slackdump.WithFilesystem(fsa)) if err != nil { base.SetExitStatus(base.SApplicationError) return fmt.Errorf("application error: %s", err) diff --git a/cmd/slackdump/internal/export/export.go b/cmd/slackdump/internal/export/export.go index a332f590..250dd609 100644 --- a/cmd/slackdump/internal/export/export.go +++ b/cmd/slackdump/internal/export/export.go @@ -9,6 +9,7 @@ import ( "github.com/rusq/dlog" "github.com/rusq/fsadapter" + "github.com/rusq/slackdump/v3/cmd/slackdump/internal/bootstrap" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base" @@ -72,7 +73,7 @@ func runExport(ctx context.Context, cmd *base.Command, args []string) error { return fmt.Errorf("error parsing the entity list: %w", err) } - sess, err := cfg.SlackdumpSession(ctx) + sess, err := bootstrap.SlackdumpSession(ctx) if err != nil { base.SetExitStatus(base.SApplicationError) return err diff --git a/cmd/slackdump/internal/format/format.go b/cmd/slackdump/internal/format/format.go index 92029c13..025bceee 100644 --- a/cmd/slackdump/internal/format/format.go +++ b/cmd/slackdump/internal/format/format.go @@ -14,6 +14,7 @@ import ( "github.com/rusq/dlog" "github.com/rusq/slack" + "github.com/rusq/slackdump/v3/cmd/slackdump/internal/bootstrap" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base" @@ -238,7 +239,7 @@ func getUsers(ctx context.Context, dmp *dump, isOnline bool) ([]slack.User, erro } func getUsersOnline(ctx context.Context, cacheDir, wsp string, usePlaywright bool) ([]slack.User, error) { - sess, err := cfg.SlackdumpSession(ctx) + sess, err := bootstrap.SlackdumpSession(ctx) if err != nil { return nil, err } diff --git a/cmd/slackdump/internal/list/list.go b/cmd/slackdump/internal/list/list.go index 0a7b1097..ce3dcc05 100644 --- a/cmd/slackdump/internal/list/list.go +++ b/cmd/slackdump/internal/list/list.go @@ -13,6 +13,7 @@ import ( "github.com/rusq/fsadapter" "github.com/rusq/slack" "github.com/rusq/slackdump/v3" + "github.com/rusq/slackdump/v3/cmd/slackdump/internal/bootstrap" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/cfg" "github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base" "github.com/rusq/slackdump/v3/internal/cache" @@ -89,7 +90,7 @@ func list(ctx context.Context, listFn listFunc) error { } // initialize the session. - sess, err := cfg.SlackdumpSession(ctx) + sess, err := bootstrap.SlackdumpSession(ctx) if err != nil { base.SetExitStatus(base.SInitializationError) return err