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"
|
||||
@@ -17,12 +16,11 @@ var lMention string
|
||||
var listCmd = &cobra.Command{
|
||||
Use: "list", Short: "List nodes",
|
||||
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())
|
||||
opts := []service.ListOption{}
|
||||
if len(lTags) > 0 {
|
||||
opts = append(opts, service.WithTags(lTags...))
|
||||
@@ -35,7 +33,7 @@ var listCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
if nodes, err := svc.List(opts...); err == nil {
|
||||
output.PrintNodes(cmd.OutOrStdout(), nodes, jsonFlag)
|
||||
output.PrintNodes(cmd.OutOrStdout(), svc, nodes, jsonFlag)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "err: %v\n", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user