mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-07-27 23:42:28 +02:00
feat: add cli help menus
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -206,6 +207,58 @@ func TestParseGlobalArgsNoDBBeforeCommand(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseGlobalArgsHelp(t *testing.T) {
|
||||
opts, err := parseGlobalArgs([]string{"--help"})
|
||||
if err != nil {
|
||||
t.Fatalf("parseGlobalArgs() error = %v", err)
|
||||
}
|
||||
if !opts.help {
|
||||
t.Fatalf("expected help=true")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommandWantsHelp(t *testing.T) {
|
||||
if !commandWantsHelp([]string{"https://example.com", "-h"}) {
|
||||
t.Fatalf("expected command help")
|
||||
}
|
||||
if commandWantsHelp([]string{"https://example.com"}) {
|
||||
t.Fatalf("did not expect command help")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMainHelpHidesDeveloperCommands(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
printMainHelp(&buf)
|
||||
out := buf.String()
|
||||
if !strings.Contains(out, "rip help [command]") || !strings.Contains(out, "Commands:") {
|
||||
t.Fatalf("main help missing expected text: %s", out)
|
||||
}
|
||||
if strings.Contains(out, "dev-help") || strings.Contains(out, "smoke") {
|
||||
t.Fatalf("main help should hide developer commands: %s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommandHelpURL(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
if !printCommandHelp(&buf, "url") {
|
||||
t.Fatalf("expected url help")
|
||||
}
|
||||
out := buf.String()
|
||||
if !strings.Contains(out, "rip url <url...>") || !strings.Contains(out, "--ignore-db") {
|
||||
t.Fatalf("url help missing expected text: %s", out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintCommandHelpRejectsUnknown(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
if printCommandHelp(&buf, "nope") {
|
||||
t.Fatalf("unexpected help for unknown command")
|
||||
}
|
||||
if buf.Len() != 0 {
|
||||
t.Fatalf("unexpected output for unknown command: %s", buf.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseGlobalArgsAllOfficialFlags(t *testing.T) {
|
||||
opts, err := parseGlobalArgs([]string{
|
||||
"--config-path", "/tmp/custom.toml",
|
||||
|
||||
Reference in New Issue
Block a user