55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
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)
|
|
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() {
|
|
rootCmd.Flags().BoolP("readonly", "ro", false, "Open database in read only mode")
|
|
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)
|
|
}
|
|
|
|
func printUsage() {
|
|
|
|
}
|