mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-10-16 22:07:30 +02:00
chore: add README, Makefile, CI, lint config and --version
The repo had no README, Makefile, CI, linter config or version string. - README.md: requirements (ffmpeg/ffprobe, plus yt-dlp for SoundCloud), build, the per-source credentials table, usage, the quality scale and the download database's migration behaviour. Every claim was checked against the code rather than written from memory, which is how the quality-range bug below was found. It also records the two deferred refactors (no shared HTTP layer, and metadata as map[string]any) so they are documented rather than lore, and notes that there is no LICENSE file. - Makefile: build, install, test, race, cover, fmt, fmt-check, vet, lint, check, clean, help. `make build` stamps version/commit/date via -ldflags. - .github/workflows/ci.yml: gofmt, vet, build, test and test -race, plus a lint job. The linter is intentionally unpinned, with a comment: a golangci-lint built against an older Go cannot analyse a go1.25 module, which is the same reason a locally installed staticcheck built with go1.24 cannot run here. - .golangci.yml: standard set plus bodyclose, errorlint, nilerr and govet/copylocks. copylocks matters now that config.Config carries a mutex; bodyclose and errorlint target defects this codebase actually has. - `rip --version` / `-V`, documented in the help output, falling back to the VCS revision the toolchain embeds for `go install` builds. Fixes a bug introduced in the previous commit: Validate capped deezer quality at 2 and soundcloud at 1, but config.toml.example documents deezer as 2/3/4 and the global -q flag accepts 0-4, so a documented config would have failed to load. deezer's buildFormatPriority treats anything >= 2 as FLAC and soundcloud ignores the value entirely, so the real ceiling is 4 everywhere; only the Qobuz and Beatport floor of 1 is a genuine constraint. Pinned with a test that walks the whole documented range. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
10 files changed
+433
-6
No files matched your search
@@ -27,6 +27,7 @@ type globalOptions struct {
|
||||
noSSLVerify bool
|
||||
verbose int
|
||||
help bool
|
||||
version bool
|
||||
command string
|
||||
commandArgs []string
|
||||
}
|
||||
@@ -50,6 +51,9 @@ func parseGlobalArgs(args []string) (globalOptions, error) {
|
||||
case isHelpArg(arg):
|
||||
opts.help = true
|
||||
return opts, nil
|
||||
case arg == "--version" || arg == "-V":
|
||||
opts.version = true
|
||||
return opts, nil
|
||||
case arg == "-ndb" || arg == "--no-db":
|
||||
opts.noDB = true
|
||||
case arg == "--no-progress":
|
||||
|
||||
@@ -44,6 +44,7 @@ Global options:
|
||||
--no-ssl-verify Disable TLS verification
|
||||
--config-path <path> Use a custom config file
|
||||
-v, -vv Verbose logging
|
||||
-V, --version Show version
|
||||
-h, --help Show help
|
||||
|
||||
Run 'rip help <command>' for command-specific help.
|
||||
|
||||
@@ -32,6 +32,10 @@ func run() int {
|
||||
fmt.Fprintf(os.Stderr, "option error: %v\n", err)
|
||||
return 2
|
||||
}
|
||||
if gopts.version {
|
||||
printVersion(os.Stdout)
|
||||
return 0
|
||||
}
|
||||
if gopts.help {
|
||||
printMainHelp(os.Stdout)
|
||||
return 0
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
)
|
||||
|
||||
// version is overridden at build time:
|
||||
//
|
||||
// go build -ldflags "-X main.version=$(git describe --tags --always --dirty)"
|
||||
//
|
||||
// It stays "dev" for a plain `go build`. See the Makefile.
|
||||
var version = "dev"
|
||||
|
||||
// commit and date are optional build-time stamps, also set with -X.
|
||||
var (
|
||||
commit = ""
|
||||
date = ""
|
||||
)
|
||||
|
||||
// buildVersion resolves the version string, preferring the ldflags value and
|
||||
// falling back to the VCS revision the Go toolchain embeds for `go install`.
|
||||
func buildVersion() string {
|
||||
v := version
|
||||
c := commit
|
||||
if c == "" {
|
||||
if info, ok := debug.ReadBuildInfo(); ok {
|
||||
for _, s := range info.Settings {
|
||||
if s.Key == "vcs.revision" {
|
||||
c = s.Value
|
||||
}
|
||||
if s.Key == "vcs.time" && date == "" {
|
||||
date = s.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(c) > 12 {
|
||||
c = c[:12]
|
||||
}
|
||||
if c != "" {
|
||||
v += " (" + c + ")"
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func printVersion(w io.Writer) {
|
||||
fmt.Fprintf(w, "rip %s\n", buildVersion())
|
||||
if date != "" {
|
||||
fmt.Fprintf(w, "built: %s\n", date)
|
||||
}
|
||||
fmt.Fprintf(w, "go: %s\n", runtime.Version())
|
||||
fmt.Fprintf(w, "target: %s/%s\n", runtime.GOOS, runtime.GOARCH)
|
||||
}
|
||||
Reference in new issue
Block a user