MCPcopy
hub / github.com/benbjohnson/litestream / Run

Method Run

cmd/litestream/ltx.go:20–131  ·  view source on GitHub ↗

Run executes the command.

(ctx context.Context, args []string)

Source from the content-addressed store, hash-verified

18
19// Run executes the command.
20func (c *LTXCommand) Run(ctx context.Context, args []string) (err error) {
21 fs := flag.NewFlagSet("litestream-ltx", flag.ContinueOnError)
22 configPath, noExpandEnv := registerConfigFlag(fs)
23 jsonOutput := fs.Bool("json", false, "output raw JSON")
24 var level levelVar
25 fs.Var(&level, "level", "compaction level (0-9 or \"all\")")
26 fs.Usage = c.Usage
27 if err := fs.Parse(args); err != nil {
28 return err
29 } else if fs.NArg() == 0 || fs.Arg(0) == "" {
30 return &usageError{
31 message: "database path or replica URL required",
32 hint: "litestream ltx /path/to/db",
33 }
34 } else if fs.NArg() > 1 {
35 return fmt.Errorf("too many arguments")
36 }
37
38 var r *litestream.Replica
39 if litestream.IsURL(fs.Arg(0)) {
40 if *configPath != "" {
41 return fmt.Errorf("cannot specify a replica URL and the -config flag")
42 }
43 if r, err = NewReplicaFromConfig(&ReplicaConfig{URL: fs.Arg(0)}, nil); err != nil {
44 return err
45 }
46 internal.InitLog(os.Stdout, "INFO", "text", false)
47 } else {
48 if *configPath == "" {
49 *configPath = DefaultConfigPath()
50 }
51
52 // Load configuration.
53 config, err := ReadConfigFile(*configPath, !*noExpandEnv)
54 if err != nil {
55 return err
56 }
57
58 // Lookup database from configuration file by path.
59 path, err := expand(fs.Arg(0))
60 if err != nil {
61 return err
62 }
63 dbc := config.DBConfig(path)
64 if dbc == nil {
65 return fmt.Errorf("database not found in config: %s", path)
66 }
67
68 db, err := NewDBFromConfig(dbc)
69 if err != nil {
70 return err
71 } else if db.Replica == nil {
72 return fmt.Errorf("database has no replica")
73 }
74 r = db.Replica
75 }
76
77 // Determine which levels to iterate.

Calls 14

IsURLFunction · 0.92
InitLogFunction · 0.92
registerConfigFlagFunction · 0.85
NewReplicaFromConfigFunction · 0.85
DefaultConfigPathFunction · 0.85
ReadConfigFileFunction · 0.85
expandFunction · 0.85
NewDBFromConfigFunction · 0.85
DBConfigMethod · 0.80
LTXFilesMethod · 0.65
NextMethod · 0.45
ItemMethod · 0.45

Tested by 2