Add info command
This commit is contained in:
parent
270215b260
commit
77fc95e9b9
69
cmd/info.go
Normal file
69
cmd/info.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
18
core/info.go
Normal file
18
core/info.go
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user