Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seperate cli and cmd main package #564

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,698 changes: 5 additions & 1,693 deletions cmd/bbolt/main.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions cmd/bbolt/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/stretchr/testify/require"

bolt "go.etcd.io/bbolt"
main "go.etcd.io/bbolt/cmd/bbolt"
"go.etcd.io/bbolt/cmd/cli"
"go.etcd.io/bbolt/internal/guts_cli"
)

Expand Down Expand Up @@ -441,15 +441,15 @@ func (b *ConcurrentBuffer) String() string {

// Main represents a test wrapper for main.Main that records output.
type Main struct {
*main.Main
*cli.Main
Stdin ConcurrentBuffer
Stdout ConcurrentBuffer
Stderr ConcurrentBuffer
}

// NewMain returns a new instance of Main.
func NewMain() *Main {
m := &Main{Main: main.NewMain()}
m := &Main{Main: cli.NewMain()}
m.Main.Stdin = &m.Stdin
m.Main.Stdout = &m.Stdout
m.Main.Stderr = &m.Stderr
Expand Down
28 changes: 0 additions & 28 deletions cmd/bbolt/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main_test

import (
"os"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -10,37 +9,10 @@ import (
"go.etcd.io/bbolt/internal/guts_cli"
)

func loadMetaPage(t *testing.T, dbPath string, pageID uint64) *common.Meta {
_, buf, err := guts_cli.ReadPage(dbPath, pageID)
require.NoError(t, err)
return common.LoadPageMeta(buf)
}

func readMetaPage(t *testing.T, path string) *common.Meta {
_, activeMetaPageId, err := guts_cli.GetRootPage(path)
require.NoError(t, err)
_, buf, err := guts_cli.ReadPage(path, uint64(activeMetaPageId))
require.NoError(t, err)
return common.LoadPageMeta(buf)
}

func readPage(t *testing.T, path string, pageId int, pageSize int) []byte {
dbFile, err := os.Open(path)
require.NoError(t, err)
defer dbFile.Close()

fi, err := dbFile.Stat()
require.NoError(t, err)
require.GreaterOrEqual(t, fi.Size(), int64((pageId+1)*pageSize))

buf := make([]byte, pageSize)
byteRead, err := dbFile.ReadAt(buf, int64(pageId*pageSize))
require.NoError(t, err)
require.Equal(t, pageSize, byteRead)

return buf
}

func pageDataWithoutPageId(buf []byte) []byte {
return buf[8:]
}
2 changes: 1 addition & 1 deletion cmd/bbolt/command_root.go → cmd/cli/command_root.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cli

import (
"github.com/spf13/cobra"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cli

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cli

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main_test
package cli_test

import (
"path/filepath"
Expand All @@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/require"

bolt "go.etcd.io/bbolt"
main "go.etcd.io/bbolt/cmd/bbolt"
main "go.etcd.io/bbolt/cmd/cli"
"go.etcd.io/bbolt/internal/btesting"
"go.etcd.io/bbolt/internal/common"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main_test
package cli_test

import (
"fmt"
Expand All @@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"

bolt "go.etcd.io/bbolt"
main "go.etcd.io/bbolt/cmd/bbolt"
main "go.etcd.io/bbolt/cmd/cli"
"go.etcd.io/bbolt/internal/btesting"
"go.etcd.io/bbolt/internal/common"
"go.etcd.io/bbolt/internal/guts_cli"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cli

import (
"fmt"
Expand Down
Loading