frostfs-node/cmd/frostfs-lens/internal/meta/tui.go
Aleksey Savchuk ced78fd939
[#1223] lens/tui: Make database open in read-only mode
Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
2024-08-16 11:33:31 +03:00

38 lines
827 B
Go

package meta
import (
common "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-lens/internal"
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-lens/internal/tuiutil"
"github.com/spf13/cobra"
"go.etcd.io/bbolt"
)
var tuiCMD = &cobra.Command{
Use: "tui",
Short: "",
Long: "",
Run: tuiFunc,
}
func init() {
common.AddComponentPathFlag(tuiCMD, &vPath)
}
func tuiFunc(cmd *cobra.Command, _ []string) {
db := openBoltDB(cmd, false)
defer db.Close()
app, err := tuiutil.NewApplication(db)
common.ExitOnErr(cmd, err)
err = app.Run()
common.ExitOnErr(cmd, err)
}
func openBoltDB(cmd *cobra.Command, writable bool) *bbolt.DB {
db, err := bbolt.Open(vPath, 0o600, &bbolt.Options{
ReadOnly: !writable,
})
common.ExitOnErr(cmd, common.Errf("couldn't open bbolt database: %w", err))
return db
}