refactor: remove db package and move database logic to service layer
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"axolotl/db"
|
||||
"axolotl/output"
|
||||
"axolotl/service"
|
||||
"fmt"
|
||||
@@ -13,14 +12,13 @@ import (
|
||||
var showCmd = &cobra.Command{
|
||||
Use: "show <id>", Short: "Show node details", Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
d, err := db.GetDB()
|
||||
svc, err := service.GetNodeService(cfg)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
return
|
||||
}
|
||||
svc := service.NewSQLiteNodeService(d.DB, cfg.GetUser())
|
||||
if n, err := svc.GetByID(args[0]); err == nil {
|
||||
output.PrintNode(cmd.OutOrStdout(), n, jsonFlag)
|
||||
output.PrintNode(cmd.OutOrStdout(), svc, n, jsonFlag)
|
||||
} else {
|
||||
fmt.Fprintln(os.Stderr, "node not found:", args[0])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user