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

feat: manage db #652

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 25 additions & 6 deletions cmd/depviz/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ import (
"os/signal"
"time"

"github.com/cayleygraph/cayley"
"github.com/cayleygraph/cayley/graph"
_ "github.com/cayleygraph/cayley/graph/kv/bolt"
"github.com/cayleygraph/cayley/schema"
"github.com/oklog/run"
"github.com/peterbourgon/ff/v3/ffcli"
"go.uber.org/zap"
"moul.io/banner"
"moul.io/depviz/v3/internal/dvcore"
Expand All @@ -26,6 +20,13 @@ import (
"moul.io/srand"
"moul.io/u"
"moul.io/zapconfig"

"github.com/cayleygraph/cayley"
"github.com/cayleygraph/cayley/graph"
_ "github.com/cayleygraph/cayley/graph/kv/bolt"
"github.com/cayleygraph/cayley/schema"
"github.com/oklog/run"
"github.com/peterbourgon/ff/v3/ffcli"
)

var (
Expand Down Expand Up @@ -74,6 +75,8 @@ var (
fetchFlags = flag.NewFlagSet("fetch", flag.ExitOnError)
fetchGitHubToken = fetchFlags.String("github-token", "", "GitHub token")
fetchResync = fetchFlags.Bool("resync", false, "resync already synced content")

//dbFlags = flag.NewFlagSet("db", flag.ExitOnError)
)

func main() {
Expand Down Expand Up @@ -140,6 +143,12 @@ func Main(args []string) error {
ShortHelp: "fetch data from providers",
Exec: execFetch,
FlagSet: fetchFlags,
}, {
Name: "db",
ShortHelp: "manage the database",
Subcommands: []*ffcli.Command{
{Name: "cleanup", Exec: execDBCleanup, ShortHelp: "cleanup the database"},
},
},
},
Exec: func(context.Context, []string) error { return flag.ErrHelp },
Expand Down Expand Up @@ -420,3 +429,13 @@ func execFetch(ctx context.Context, args []string) error {
}
return dvcore.Fetch(store, args, opts)
}

func execDBCleanup(ctx context.Context, args []string) error {
err := os.RemoveAll(*globalStorePath)
if err != nil {
return err
}

fmt.Println("DB cleanup successfully.")
return nil
}