func (m *Main) Run(args ...string) error {
	if len(args) == 0 || strings.HasPrefix(args[0], "-") {
		fmt.Fprintln(m.Stderr, m.Usage())
		return ErrUsage
	}
	switch args[0] {
	case "help":
		fmt.Fprintln(m.Stderr, m.Usage())
		return ErrUsage
	case "bench":
		return newBenchCommand(m).Run(args[1:]...)
	case "buckets":
		return newBucketsCommand(m).Run(args[1:]...)
	case "check":
		return newCheckCommand(m).Run(args[1:]...)
	case "compact":
		return newCompactCommand(m).Run(args[1:]...)
	case "dump":
		return newDumpCommand(m).Run(args[1:]...)
	case "page-item":
		return newPageItemCommand(m).Run(args[1:]...)
	case "get":
		return newGetCommand(m).Run(args[1:]...)
	case "info":
		return newInfoCommand(m).Run(args[1:]...)
	case "keys":
		return newKeysCommand(m).Run(args[1:]...)
	case "page":
		return newPageCommand(m).Run(args[1:]...)
	case "pages":
		return newPagesCommand(m).Run(args[1:]...)
	case "stats":
		return newStatsCommand(m).Run(args[1:]...)
	default:
		return ErrUnknownCommand
	}
}
Run executes the program.
package main
import (
	"bytes"
	"encoding/binary"
	"errors"
	"flag"
	"fmt"
	"io"
	"io/ioutil"
	"math/rand"
	"os"
	"runtime"
	"runtime/pprof"
	"strconv"
	"strings"
	"time"
	"unicode"
	"unicode/utf8"
	"unsafe"
	bolt "github.com/coreos/bbolt"
)
var (
	ErrUsage = errors.New("usage")
	ErrUnknownCommand = errors.New("unknown command")
	ErrPathRequired = errors.New("path required")
	ErrFileNotFound = errors.New("file not found")
	ErrInvalidValue = errors.New("invalid value")
	ErrCorrupt = errors.New("invalid value")
	ErrNonDivisibleBatchSize = errors.New("number of iterations must be divisible by the batch size")
	ErrPageIDRequired = errors.New("page id required")
	ErrBucketRequired = errors.New("bucket required")
	ErrBucketNotFound = errors.New("bucket not found")
	ErrKeyRequired = errors.New("key required")
	ErrKeyNotFound = errors.New("key not found")
)
const PageHeaderSize = 16
func main() {
	m := NewMain()
	if err := m.Run(os.Args[1:]...); err == ErrUsage {
		os.Exit(2)
	} else if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
}
type Main struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}
func NewMain() *Main {
	return &Main{
		Stdin:  os.Stdin,
		Stdout: os.Stdout,
		Stderr: os.Stderr,
	}
}