2022-04-14 16:32:39 +00:00
package cmd
import (
"errors"
"os"
"git.bullercodeworks.com/brian/boltbrowser/ui"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
const (
AppVersion = 3.0
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = & cobra . Command {
Use : "boltbrowser" ,
Short : "A browser and editor for bolt databases" ,
Long : ` ` ,
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
if len ( args ) == 0 {
return errors . New ( "No database given." )
}
viper . Set ( "dbs" , args )
2022-04-20 21:22:43 +00:00
viper . Set ( "dbidx" , 0 )
2022-04-14 16:32:39 +00:00
if err := ui . NewUi ( ) . Start ( ) ; err != nil {
return err
}
return nil
} ,
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute ( ) {
err := rootCmd . Execute ( )
if err != nil {
os . Exit ( 1 )
}
}
func init ( ) {
2022-04-20 21:22:43 +00:00
rootCmd . Flags ( ) . BoolP ( "readonly" , "r" , false , "Open database in read only mode" )
2022-04-14 16:32:39 +00:00
viper . BindPFlag ( "readonly" , rootCmd . Flags ( ) . Lookup ( "readonly" ) )
rootCmd . Flags ( ) . Bool ( "no-value" , false , "Do not output values in the left pane" )
viper . BindPFlag ( "no-value" , rootCmd . Flags ( ) . Lookup ( "no-value" ) )
rootCmd . Flags ( ) . String ( "timeout" , "1s" , "Amount of time to wait for the DB to open, otherwise error. Given in 'duration' format (e.g. 1s for one second, 1m for one minute)" )
viper . BindPFlag ( "timeout" , rootCmd . Flags ( ) . Lookup ( "timeout" ) )
viper . Set ( "version" , AppVersion )
}