added db info command

This commit is contained in:
Thomas von Dein
2024-12-22 00:07:33 +01:00
committed by T.v.Dein
parent 3de65aa1c3
commit 8e400c6831
4 changed files with 80 additions and 2 deletions

View File

@@ -352,3 +352,26 @@ func Serve(conf *cfg.Config) *cobra.Command {
return cmd
}
func Info(conf *cfg.Config) *cobra.Command {
var cmd = &cobra.Command{
Use: "info",
Short: "info",
Long: `show info about database`,
RunE: func(cmd *cobra.Command, args []string) error {
// errors at this stage do not cause the usage to be shown
cmd.SilenceUsage = true
info, err := conf.DB.Info()
if err != nil {
return err
}
return output.Info(os.Stdout, conf, info)
},
}
cmd.PersistentFlags().StringVarP(&conf.Listen, "listen", "l", "localhost:8787", "host:port")
return cmd
}

View File

@@ -93,7 +93,7 @@ func Execute() {
rootCmd.PersistentFlags().StringVarP(&conf.Dbfile, "dbfile", "f",
filepath.Join(home, ".config", "anydb", "default.db"), "DB file to use")
rootCmd.PersistentFlags().StringVarP(&conf.Dbbucket, "bucket", "b",
app.BucketData, "use other bucket (default: " + app.BucketData +")")
app.BucketData, "use other bucket (default: "+app.BucketData+")")
rootCmd.AddCommand(Set(&conf))
rootCmd.AddCommand(List(&conf))
@@ -103,6 +103,7 @@ func Execute() {
rootCmd.AddCommand(Import(&conf))
rootCmd.AddCommand(Serve(&conf))
rootCmd.AddCommand(Man(&conf))
rootCmd.AddCommand(Info(&conf))
err = rootCmd.Execute()
if err != nil {