diff --git a/cmd/info.go b/cmd/info.go new file mode 100644 index 0000000..535d8f3 --- /dev/null +++ b/cmd/info.go @@ -0,0 +1,69 @@ +package cmd + +import ( + "database/sql" + "fmt" + + "github.com/Jaculabilis/intake/core" + "github.com/spf13/cobra" +) + +var infoCmd = &cobra.Command{ + Use: "info", + Short: "Print intake config", + Long: `Print intake config as it would be used by other commands. +`, + Run: func(cmd *cobra.Command, args []string) { + info() + }, + DisableFlagsInUseLine: true, +} + +func init() { + rootCmd.AddCommand(infoCmd) +} + +func info() { + fmt.Printf("Revision: %s\n", core.GetRevInfo()) + + fmt.Printf("Data path: %s\n", dataPath) + fmt.Printf("Database: %s\n", core.DatabasePath(dataPath)) + + db := openDb() + + row := db.QueryRow("select exists(select 1 from password)") + var hasPassword bool + if err := row.Scan(&hasPassword); err != nil && err != sql.ErrNoRows { + fmt.Printf("Password: error: %v\n", err) + } else { + if hasPassword { + fmt.Printf("Password: yes\n") + } else { + fmt.Printf("Password: no\n") + } + } + + row = db.QueryRow("select count(*) from sources") + var sources int + if err := row.Scan(&sources); err != nil { + fmt.Printf("Sources: error: %v\n", err) + } else { + fmt.Printf("Sources: %d\n", sources) + } + + row = db.QueryRow("select count(*) from channels") + var channels int + if err := row.Scan(&channels); err != nil { + fmt.Printf("Channels: error: %v\n", err) + } else { + fmt.Printf("Channels: %d\n", channels) + } + + row = db.QueryRow("select count(*) from items") + var items int + if err := row.Scan(&items); err != nil { + fmt.Printf("Items: error: %v\n", err) + } else { + fmt.Printf("Items: %d\n", items) + } +} diff --git a/core/info.go b/core/info.go new file mode 100644 index 0000000..d28ac3c --- /dev/null +++ b/core/info.go @@ -0,0 +1,18 @@ +package core + +import "runtime/debug" + +func GetRevInfo() (rev string) { + rev = "" + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + if setting.Key == "vcs.revision" { + rev = setting.Value + rev + } + if setting.Key == "vcs.modified" { + rev = rev + "-dirty" + } + } + } + return +}