mirror of
https://codeberg.org/scip/anydb.git
synced 2025-12-16 20:10:59 +01:00
add list command, fix set command
This commit is contained in:
@@ -2,10 +2,12 @@ package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/tlinden/anydb/app"
|
||||
"github.com/tlinden/anydb/cfg"
|
||||
"github.com/tlinden/anydb/output"
|
||||
)
|
||||
|
||||
func Set(conf *cfg.Config) *cobra.Command {
|
||||
@@ -52,7 +54,37 @@ func Del(conf *cfg.Config) *cobra.Command {
|
||||
}
|
||||
|
||||
func List(conf *cfg.Config) *cobra.Command {
|
||||
return nil
|
||||
var (
|
||||
attr app.DbAttr
|
||||
)
|
||||
|
||||
var cmd = &cobra.Command{
|
||||
Use: "list [-t <tag>] [-o <mode>] [<filter-regex>]",
|
||||
Short: "List database contents",
|
||||
Long: `List database contents`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
// errors at this stage do not cause the usage to be shown
|
||||
cmd.SilenceUsage = true
|
||||
|
||||
if len(args) > 0 {
|
||||
attr.Args = args
|
||||
}
|
||||
|
||||
entries, err := conf.DB.List(&attr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
output.List(os.Stdout, conf, entries)
|
||||
|
||||
return conf.DB.Close()
|
||||
},
|
||||
}
|
||||
|
||||
cmd.PersistentFlags().StringVarP(&conf.Mode, "output-mode", "o", "", "output mode: wide, yaml, json, table")
|
||||
cmd.PersistentFlags().StringArrayVarP(&attr.Tags, "tags", "t", nil, "tags, multiple allowed")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func Find(conf *cfg.Config) *cobra.Command {
|
||||
|
||||
Reference in New Issue
Block a user