feat: implement second level of verbosity

This commit is contained in:
lb-a
2026-05-07 18:45:36 +02:00
parent 04cc56040b
commit 3909ba5113
3 changed files with 15 additions and 5 deletions

View File

@@ -24,7 +24,7 @@ type globalOptions struct {
codec string codec string
noProgress bool noProgress bool
noSSLVerify bool noSSLVerify bool
verbose bool verbose int
command string command string
commandArgs []string commandArgs []string
} }
@@ -52,7 +52,13 @@ func parseGlobalArgs(args []string) (globalOptions, error) {
case arg == "--no-ssl-verify": case arg == "--no-ssl-verify":
opts.noSSLVerify = true opts.noSSLVerify = true
case arg == "-v" || arg == "--verbose": case arg == "-v" || arg == "--verbose":
opts.verbose = true if opts.verbose < 2 {
opts.verbose++
}
case arg == "-vv":
if opts.verbose < 2 {
opts.verbose = 2
}
case arg == "-f" || arg == "--folder": case arg == "-f" || arg == "--folder":
if i+1 >= len(args) { if i+1 >= len(args) {
return globalOptions{}, fmt.Errorf("%s requires a value", arg) return globalOptions{}, fmt.Errorf("%s requires a value", arg)

View File

@@ -14,6 +14,7 @@ import (
"streamrip-go/internal/app" "streamrip-go/internal/app"
"streamrip-go/internal/config" "streamrip-go/internal/config"
"streamrip-go/internal/provider" "streamrip-go/internal/provider"
"streamrip-go/internal/verbose"
_ "modernc.org/sqlite" _ "modernc.org/sqlite"
) )
@@ -49,8 +50,11 @@ func main() {
os.Exit(1) os.Exit(1)
} }
applyGlobalConfigOverrides(cfg, gopts) applyGlobalConfigOverrides(cfg, gopts)
if gopts.verbose { verbose.SetLevel(gopts.verbose)
fmt.Fprintln(os.Stderr, "verbose mode enabled") if gopts.verbose >= 2 {
fmt.Fprintln(os.Stderr, "verbose mode enabled (level 2: downloads + http)")
} else if gopts.verbose >= 1 {
fmt.Fprintln(os.Stderr, "verbose mode enabled (level 1: downloads)")
} }
os.Args = append([]string{os.Args[0], gopts.command}, gopts.commandArgs...) os.Args = append([]string{os.Args[0], gopts.command}, gopts.commandArgs...)

View File

@@ -227,7 +227,7 @@ func TestParseGlobalArgsAllOfficialFlags(t *testing.T) {
if !opts.noDB || !opts.qualitySet || opts.quality != 3 || !opts.codecSet || opts.codec != "VORBIS" { if !opts.noDB || !opts.qualitySet || opts.quality != 3 || !opts.codecSet || opts.codec != "VORBIS" {
t.Fatalf("unexpected quality/codec/db opts: %+v", opts) t.Fatalf("unexpected quality/codec/db opts: %+v", opts)
} }
if !opts.noProgress || !opts.noSSLVerify || !opts.verbose { if !opts.noProgress || !opts.noSSLVerify || opts.verbose != 1 {
t.Fatalf("unexpected boolean opts: %+v", opts) t.Fatalf("unexpected boolean opts: %+v", opts)
} }
if opts.command != "search" { if opts.command != "search" {