Skip to content

Commit

Permalink
move session init into bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Oct 11, 2024
1 parent fdd7748 commit b6666b8
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 30 deletions.
3 changes: 2 additions & 1 deletion cmd/slackdump/internal/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion cmd/slackdump/internal/archive/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
17 changes: 0 additions & 17 deletions cmd/slackdump/internal/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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...)
Expand All @@ -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
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cfg
package bootstrap

import (
"context"
Expand Down
3 changes: 2 additions & 1 deletion cmd/slackdump/internal/diag/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion cmd/slackdump/internal/dump/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion cmd/slackdump/internal/emoji/emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion cmd/slackdump/internal/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion cmd/slackdump/internal/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/slackdump/internal/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b6666b8

Please sign in to comment.