apps/blobs/main.go 1.7 K raw
1
// blobs — S3 browser, CLI uploader, and TUI.
2
//
3
//	blobs                              launch the interactive TUI
4
//	blobs tui [-b BUCKET]              launch the TUI (alias)
5
//	blobs auth                         interactive client config writer
6
//	blobs server [--host H] [--port P] run the web server
7
//	blobs [-b BUCKET] <file>           upload a file and print its URL
8
//	blobs --help
9
package main
10
11
import (
12
	"fmt"
13
	"os"
14
)
15
16
const usage = `blobs — S3 browser, CLI, and TUI
17
18
usage:
19
  blobs                              launch interactive TUI
20
  blobs tui [-b BUCKET] [--prefix P] launch TUI
21
  blobs auth                         write client config to ~/.config/blobs/config.toml
22
  blobs server [--host H] [--port P] run the web server
23
  blobs [-b BUCKET] [--prefix P] [--key K] <file>
24
                                     upload FILE, print URL to stdout
25
  blobs --help
26
27
env:
28
  BLOBS_DEFAULT_BUCKET   bucket used when -b is omitted
29
  S3_ENDPOINT            S3 endpoint URL
30
  S3_REGION              region (default "auto")
31
  S3_ACCESS_KEY_ID       access key
32
  S3_SECRET_ACCESS_KEY   secret key
33
  R2_ACCOUNT_ID          shortcut: derives endpoint for Cloudflare R2
34
  BLOBS_PUBLIC_URLS      bucket=url,bucket=url public URL map
35
  BLOBS_PRESIGN_TTL_SECONDS  presigned URL lifetime (default 3600)
36
  BLOBS_PREVIEW          override preview backend: kitty|iterm|chafa|none
37
`
38
39
func main() {
40
	args := os.Args[1:]
41
	if len(args) == 0 {
42
		runTUI(nil)
43
		return
44
	}
45
	switch args[0] {
46
	case "-h", "--help", "help":
47
		fmt.Print(usage)
48
	case "server":
49
		runServer(args[1:])
50
	case "tui":
51
		runTUI(args[1:])
52
	case "auth":
53
		runAuth(args[1:])
54
	default:
55
		if _, err := os.Stat(args[0]); err == nil {
56
			runUpload(args)
57
			return
58
		}
59
		// no file at args[0] — treat as TUI flags
60
		runTUI(args)
61
	}
62
}