func (m *Main) Usage() {
	fmt.Println(`
litestream is a tool for replicating SQLite databases.
Usage:
	litestream <command> [arguments]
The commands are:
	databases    list databases specified in config file
	generations  list available generations for a database
	replicate    runs a server to replicate databases
	restore      recovers database backup from a replica
	snapshots    list available snapshots for a database
	version      prints the binary version
	wal          list available WAL files for a database
`[1:])
}
Usage prints the help screen to STDOUT.
package main
import (
	"context"
	"errors"
	"flag"
	"fmt"
	"io/ioutil"
	"log"
	"net/url"
	"os"
	"os/signal"
	"os/user"
	"path"
	"path/filepath"
	"regexp"
	"strconv"
	"strings"
	"time"
	"github.com/benbjohnson/litestream"
	"github.com/benbjohnson/litestream/abs"
	"github.com/benbjohnson/litestream/file"
	"github.com/benbjohnson/litestream/gcs"
	"github.com/benbjohnson/litestream/s3"
	"github.com/benbjohnson/litestream/sftp"
	_ "github.com/mattn/go-sqlite3"
	"gopkg.in/yaml.v2"
)
var (
	Version = "(development build)"
)
var errStop = errors.New("stop")
func main() {
	log.SetFlags(0)
	m := NewMain()
	if err := m.Run(context.Background(), os.Args[1:]); err == flag.ErrHelp || err == errStop {
		os.Exit(1)
	} else if err != nil {
		log.Println(err)
		os.Exit(1)
	}
}
type Main struct{}
func NewMain() *Main {
	return &Main{}
}
func (m *Main) Run(ctx context.Context, args []string) (err error) {
	if isService, err := isWindowsService(); err != nil {
		return err
	} else if isService {
		return runWindowsService(ctx)
	}
	applyLitestreamEnv()
	var cmd string
	if len(args) > 0 {
		cmd, args = args[0], args[1:]
	}
	switch cmd {
	case "databases":
		return (&DatabasesCommand{}).Run(ctx, args)
	case "generations":
		return (&GenerationsCommand{}).Run(ctx, args)
	case "replicate":
		c := NewReplicateCommand()
		if err := c.ParseFlags(ctx, args); err != nil {
			return err
		}
		ctx, cancel := context.WithCancel(ctx)
		signalCh := make(chan os.Signal, 1)
		signal.Notify(signalCh, notifySignals...)
		if err := c.Run(ctx); err != nil {
			return err
		}
		select {
		case <-ctx.Done():
			fmt.Println("context done, litestream shutting down")
		case err = <-c.execCh:
			cancel()
			fmt.Println("subprocess exited, litestream shutting down")
		case sig := <-signalCh:
			cancel()
			fmt.Println("signal received, litestream shutting down")
			if c.cmd != nil {
				fmt.Println("sending signal to exec process")
				if err := c.cmd.Process.Signal(sig); err != nil {
					return fmt.Errorf("cannot signal exec process: %w", err)
				}
				fmt.Println("waiting for exec process to close")
				if err := <-c.execCh; err != nil && !strings.HasPrefix(err.Error(), "signal:") {
					return fmt.Errorf("cannot wait for exec process: %w", err)
				}
			}
		}
		if e := c.Close(); e != nil && err == nil {
			err = e
		}
		fmt.Println("litestream shut down")
		return err
	case "restore":
		return (&RestoreCommand{}).Run(ctx, args)
	case "snapshots":
		return (&SnapshotsCommand{}).Run(ctx, args)
	case "version":
		return (&VersionCommand{}).Run(ctx, args)
	case "wal":
		return (&WALCommand{}).Run(ctx, args)
	default:
		if cmd == "" || cmd == "help" || strings.HasPrefix(cmd, "-") {
			m.Usage()
			return flag.ErrHelp
		}
		return fmt.Errorf("litestream %s: unknown command", cmd)
	}
}