From 83d54bb336e8c6f756fd0fbcf81c20a761ca07fa Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Thu, 23 Apr 2026 14:24:15 -0500 Subject: [PATCH] docs(cli): add register help examples --- cmd/litestream/register.go | 10 +++++++ cmd/litestream/register_test.go | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/cmd/litestream/register.go b/cmd/litestream/register.go index 0aff77f27..19167ff28 100644 --- a/cmd/litestream/register.go +++ b/cmd/litestream/register.go @@ -114,5 +114,15 @@ Options: -socket PATH Path to control socket (default: /var/run/litestream.sock). + +Examples: + # Register a database with an S3 replica. + $ litestream register -replica s3://mybucket/db /path/to/db + + # Register a database with a file replica. + $ litestream register -replica file:///backup/path /path/to/db + + # Register using a non-default control socket. + $ litestream register -socket /tmp/litestream.sock -replica s3://mybucket/db /path/to/db `[1:]) } diff --git a/cmd/litestream/register_test.go b/cmd/litestream/register_test.go index 1784326d5..d85cc6a60 100644 --- a/cmd/litestream/register_test.go +++ b/cmd/litestream/register_test.go @@ -2,7 +2,10 @@ package main_test import ( "context" + "io" + "os" "path/filepath" + "strings" "testing" "github.com/benbjohnson/litestream" @@ -160,3 +163,48 @@ func TestRegisterCommand_Run(t *testing.T) { } }) } + +func TestRegisterCommand_Usage(t *testing.T) { + output := captureStdout(t, func() { + (&main.RegisterCommand{}).Usage() + }) + + for _, example := range []string{ + "Examples:", + "$ litestream register -replica s3://mybucket/db /path/to/db", + "$ litestream register -replica file:///backup/path /path/to/db", + "$ litestream register -socket /tmp/litestream.sock -replica s3://mybucket/db /path/to/db", + } { + if !strings.Contains(output, example) { + t.Fatalf("usage output missing %q:\n%s", example, output) + } + } +} + +func captureStdout(t *testing.T, fn func()) string { + t.Helper() + + orig := os.Stdout + r, w, err := os.Pipe() + if err != nil { + t.Fatal(err) + } + os.Stdout = w + t.Cleanup(func() { + os.Stdout = orig + }) + + fn() + + if err := w.Close(); err != nil { + t.Fatal(err) + } + output, err := io.ReadAll(r) + if err != nil { + t.Fatal(err) + } + if err := r.Close(); err != nil { + t.Fatal(err) + } + return string(output) +}