Skip to content

Commit

Permalink
Merge pull request #349 from rusq/ui-2
Browse files Browse the repository at this point in the history
UI implementation 2
  • Loading branch information
rusq authored Nov 5, 2024
2 parents 6b11b67 + 2f0b9d3 commit 24eb419
Show file tree
Hide file tree
Showing 35 changed files with 419 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: "1.23"

- name: Build
run: go build -v ./...
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- run: git fetch --force --tags
- uses: actions/setup-go@v5
with:
go-version: '>=1.22.0'
go-version: '>=1.23.0'
cache: true
# More assembly might be required: Docker logins, GPG, etc. It all depends
# on your needs.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ clean:
-rm slackdump slackdump.exe $(wildcard *.zip)

test:
go test -race -cover -count=3 ./...
go test -race -cover ./...

aurtest:
GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw" go build -o 'deleteme' ./cmd/slackdump
Expand Down
39 changes: 39 additions & 0 deletions cmd/slackdump/internal/archive/archive_wizard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package archive

import (
"context"

"github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui/cfgui"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui/dumpui"
"github.com/rusq/slackdump/v3/internal/structures"
)

func archiveWizard(ctx context.Context, cmd *base.Command, args []string) error {
w := &dumpui.Wizard{
Title: "Archive Slack Workspace",
Name: "Archive",
Cmd: cmd,
LocalConfig: configuration,
ArgsFn: func() []string {
if len(entryList) > 0 {
return structures.SplitEntryList(entryList)
}
return nil
},
}
return w.Run(ctx)
}

var entryList string

func configuration() cfgui.Configuration {
return cfgui.Configuration{
cfgui.ParamGroup{
Name: "Optional parameters",
Params: []cfgui.Parameter{
cfgui.ChannelIDs(&entryList, false),
},
},
}
}
8 changes: 5 additions & 3 deletions cmd/slackdump/internal/archive/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import (
)

var CmdSearch = &base.Command{
UsageLine: "slackdump search",
Short: "dump search results",
Long: `Searches for messages matching criteria.`,
UsageLine: "slackdump search",
Short: "dump search results",
Long: `Searches for messages matching criteria.`,
Wizard: wizSearch,
RequireAuth: true,
Commands: []*base.Command{
cmdSearchMessages,
cmdSearchFiles,
Expand Down
118 changes: 118 additions & 0 deletions cmd/slackdump/internal/archive/search_wizard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package archive

import (
"context"
"errors"
"strings"

"github.com/charmbracelet/huh"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui/cfgui"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui/dumpui"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui/updaters"
)

func wizSearch(ctx context.Context, cmd *base.Command, args []string) error {
w := &dumpui.Wizard{
Title: "Archive Search Results",
Name: "Search",
Cmd: adapterCmd,
LocalConfig: searchCfg,
ArgsFn: func() []string {
return append([]string{action}, strings.Split(terms, " ")...)
},
ValidateParamsFn: func() error {
if action == "" {
return errors.New("select action")
}
if len(terms) == 0 {
return errors.New("search terms are not specified")
}
return nil
},
}
return w.Run(ctx)
}

const (
acMessages = "messages"
acFiles = "files"
acAll = "all"
)

var (
action string = acMessages
terms string
)

func searchCfg() cfgui.Configuration {
return cfgui.Configuration{
cfgui.ParamGroup{
Name: "Required",
Params: []cfgui.Parameter{
{
Name: "Search Terms",
Description: "Enter your search query.",
Value: terms,
Inline: true,
Updater: updaters.NewString(&terms, "Search...", false, huh.ValidateNotEmpty()),
},
},
},
cfgui.ParamGroup{
Name: "Other parameters",
Params: []cfgui.Parameter{

{
Name: "Scope",
Description: "Choose the search scope.",
Value: action,
Inline: false,
Updater: updaters.NewPicklist(&action, huh.NewSelect[string]().Options(
huh.NewOption("messages", acMessages),
huh.NewOption("files", acFiles),
huh.NewOption("all", acAll),
).DescriptionFunc(func() string {
switch action {
case acMessages:
return "Search only in messages"
case acFiles:
return "Search only in files"
case acAll:
return "Search in both messages and in files"
default:
return "undefined search action"
}
}, &action).Title("Search Scope")),
},
},
},
}
}

var adapterCmd = &base.Command{
Run: adaptercmd,
}

func adaptercmd(ctx context.Context, _ *base.Command, args []string) error {
if len(args) < 1 {
panic("internal error: empty arguments")
}
if len(args) < 2 {
return errors.New("no search terms")
}
aCmd := args[0]
var cmd *base.Command
switch aCmd {
case acMessages:
cmd = cmdSearchMessages
case acFiles:
cmd = cmdSearchFiles
case acAll:
cmd = cmdSearchAll
default:
return errors.New("invalid adapter command")
}

return cmd.Run(ctx, cmd, args[1:])
}
17 changes: 0 additions & 17 deletions cmd/slackdump/internal/archive/wizard.go

This file was deleted.

8 changes: 1 addition & 7 deletions cmd/slackdump/internal/diag/eztest.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,10 @@ func tryPlaywrightAuth(ctx context.Context, wsp string) ezResult {

res.HasToken = len(prov.SlackToken()) > 0
res.HasCookies = len(prov.Cookies()) > 0
if err != nil {
res.Err = ptr(err.Error())
return res
}
return res
}

func ptr[T any](t T) *T {
return &t
}
func ptr[T any](t T) *T { return &t }

func tryRodAuth(ctx context.Context, wsp string) ezResult {
ret := ezResult{Engine: "rod"}
Expand Down
4 changes: 2 additions & 2 deletions cmd/slackdump/internal/diag/rawoutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func maybeCreate(filename string) (io.WriteCloser, error) {
return f, nil
}

func saveThread(ctx context.Context, cl *http.Client, w io.Writer, token string, sl structures.SlackLink) error {
func saveThread(_ context.Context, cl *http.Client, w io.Writer, token string, sl structures.SlackLink) error {
v := url.Values{
"token": {token},
"channel": {sl.Channel},
Expand All @@ -135,7 +135,7 @@ func saveThread(ctx context.Context, cl *http.Client, w io.Writer, token string,
return rawDump(w, cl, "conversations.replies", v)
}

func saveConversation(ctx context.Context, cl *http.Client, w io.Writer, token string, sl structures.SlackLink) error {
func saveConversation(_ context.Context, cl *http.Client, w io.Writer, token string, sl structures.SlackLink) error {
v := url.Values{
"token": {token},
"channel": {sl.Channel},
Expand Down
6 changes: 3 additions & 3 deletions cmd/slackdump/internal/diag/wizdebug.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/huh"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui/bubbles/menu"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui/cfgui"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui/dumpui"
)

var CmdWizDebug = &base.Command{
Expand Down Expand Up @@ -56,7 +56,7 @@ func runWizDebug(ctx context.Context, cmd *base.Command, args []string) error {
}

func debugDumpUI(ctx context.Context) error {
menu := []dumpui.MenuItem{
mnu := []menu.MenuItem{
{
ID: "run",
Name: "Run",
Expand All @@ -79,7 +79,7 @@ func debugDumpUI(ctx context.Context) error {
Help: "Exit to main menu",
},
}
w := dumpui.NewModel("Wizard Debug", menu, false)
w := menu.New("Wizard Debug", mnu, false)

if _, err := tea.NewProgram(w, tea.WithContext(ctx)).Run(); err != nil {
return err
Expand Down
9 changes: 2 additions & 7 deletions cmd/slackdump/internal/dump/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dump

import (
"context"
"strings"

"github.com/rusq/slackdump/v3/cmd/slackdump/internal/golang/base"
"github.com/rusq/slackdump/v3/cmd/slackdump/internal/ui/cfgui"
Expand All @@ -19,7 +18,7 @@ func WizDump(ctx context.Context, cmd *base.Command, args []string) error {
LocalConfig: opts.configuration,
Cmd: cmd,
ArgsFn: func() []string {
return splitEntryList(entryList)
return structures.SplitEntryList(entryList)
},
ValidateParamsFn: func() error {
return structures.ValidateEntityList(entryList)
Expand All @@ -30,16 +29,12 @@ func WizDump(ctx context.Context, cmd *base.Command, args []string) error {

var entryList string

func splitEntryList(s string) []string {
return strings.Split(s, " ")
}

func (o *options) configuration() cfgui.Configuration {
return cfgui.Configuration{
{
Name: "Required",
Params: []cfgui.Parameter{
cfgui.ChannelIDs(&entryList),
cfgui.ChannelIDs(&entryList, true),
},
}, {
Name: "Optional",
Expand Down
16 changes: 10 additions & 6 deletions cmd/slackdump/internal/emoji/emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

var CmdEmoji = &base.Command{
Run: run,
Wizard: wizard,
UsageLine: "slackdump emoji [flags]",
Short: "download workspace emojis",
Long: "", // TODO: add long description
Expand All @@ -23,13 +22,18 @@ var CmdEmoji = &base.Command{
PrintFlags: true,
}

// emoji specific flags
var (
type options struct {
ignoreErrors bool
)
}

// emoji specific flags
var cmdFlags = options{
ignoreErrors: false,
}

func init() {
CmdEmoji.Flag.BoolVar(&ignoreErrors, "ignore-errors", true, "ignore download errors (skip failed emojis)")
CmdEmoji.Wizard = wizard
CmdEmoji.Flag.BoolVar(&cmdFlags.ignoreErrors, "ignore-errors", true, "ignore download errors (skip failed emojis)")
}

func run(ctx context.Context, cmd *base.Command, args []string) error {
Expand All @@ -45,7 +49,7 @@ func run(ctx context.Context, cmd *base.Command, args []string) error {
return fmt.Errorf("application error: %s", err)
}

if err := emojidl.DlFS(ctx, sess, fsa, ignoreErrors); err != nil {
if err := emojidl.DlFS(ctx, sess, fsa, cmdFlags.ignoreErrors); err != nil {
base.SetExitStatus(base.SApplicationError)
return fmt.Errorf("application error: %s", err)
}
Expand Down
Loading

0 comments on commit 24eb419

Please sign in to comment.