fix(cli): show tui help without opening the archive

This commit is contained in:
Vincent Koc 2026-05-02 10:42:40 -07:00
parent f3f2496e08
commit dff96610cc
No known key found for this signature in database
4 changed files with 41 additions and 10 deletions

View File

@ -157,6 +157,9 @@ func (r *runtime) dispatch(rest []string) error {
autoShareUpdate := !hasBoolFlag(rest[1:], "--dm")
return r.withLocalStoreDefaultLocked(autoShareUpdate, autoShareUpdate, func() error { return r.runSearch(rest[1:]) })
case "tui":
if hasHelpArg(rest[1:]) {
return r.runTUI(rest[1:])
}
return r.withLocalStoreReadOnly(func() error { return r.runTUI(rest[1:]) })
case "messages":
if hasBoolFlag(rest[1:], "--sync") && !hasBoolFlag(rest[1:], "--dm") {

View File

@ -155,6 +155,16 @@ func TestStatusSearchSQLAndListings(t *testing.T) {
require.Equal(t, before, after, "tui --json should not mutate the database")
}
func TestTUIHelpReturnsUsage(t *testing.T) {
var stdout bytes.Buffer
var stderr bytes.Buffer
require.NoError(t, Run(context.Background(), []string{"tui", "--help"}, &stdout, &stderr))
require.Contains(t, stdout.String(), "Usage of tui:")
require.Contains(t, stdout.String(), "-limit")
require.Empty(t, stderr.String())
}
func TestWiretapImportsDesktopDirectMessages(t *testing.T) {
ctx := context.Background()
dir := t.TempDir()

View File

@ -96,3 +96,12 @@ func hasBoolFlag(args []string, name string) bool {
}
return false
}
func hasHelpArg(args []string) bool {
for _, arg := range args {
if arg == "help" || arg == "--help" || arg == "-h" {
return true
}
}
return false
}

View File

@ -3,7 +3,6 @@ package cli
import (
"errors"
"flag"
"io"
"strings"
"github.com/vincentkoc/crawlkit/tui"
@ -13,16 +12,26 @@ import (
func (r *runtime) runTUI(args []string) error {
fs := flag.NewFlagSet("tui", flag.ContinueOnError)
fs.SetOutput(io.Discard)
channel := fs.String("channel", "", "")
author := fs.String("author", "", "")
limit := fs.Int("limit", 200, "")
includeEmpty := fs.Bool("include-empty", false, "")
dm := fs.Bool("dm", false, "")
guildsFlag := fs.String("guilds", "", "")
guildFlag := fs.String("guild", "", "")
jsonOut := fs.Bool("json", false, "")
fs.SetOutput(r.stderr)
if hasHelpArg(args) {
fs.SetOutput(r.stdout)
}
channel := fs.String("channel", "", "channel id")
author := fs.String("author", "", "author/user id")
limit := fs.Int("limit", 200, "row limit")
includeEmpty := fs.Bool("include-empty", false, "include empty messages")
dm := fs.Bool("dm", false, "browse direct messages")
guildsFlag := fs.String("guilds", "", "comma-separated guild ids")
guildFlag := fs.String("guild", "", "guild id")
jsonOut := fs.Bool("json", false, "write browser rows as JSON")
if len(args) == 1 && args[0] == "help" {
fs.Usage()
return nil
}
if err := fs.Parse(args); err != nil {
if errors.Is(err, flag.ErrHelp) {
return nil
}
return usageErr(err)
}
if *jsonOut {