ppass use new logger

This commit is contained in:
2024-10-10 10:31:44 +02:00
parent f2e25cb402
commit 7cb3636328

View File

@@ -2,13 +2,13 @@ package main
import ( import (
"flag" "flag"
"fmt"
"os" "os"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/k4lipso/pentapass/rpc" "github.com/k4lipso/pentapass/rpc"
"github.com/k4lipso/pentapass/crypto" "github.com/k4lipso/pentapass/crypto"
. "github.com/k4lipso/pentapass/internal/log"
) )
var ( var (
@@ -32,7 +32,7 @@ var listCmd = &cobra.Command{
client, err := rpc.Receive(dbPath) client, err := rpc.Receive(dbPath)
if err != nil { if err != nil {
fmt.Printf("dialing: %s\n", err) Logger.Errorf("dialing: %s\n", err)
return return
} }
@@ -41,11 +41,11 @@ var listCmd = &cobra.Command{
err = client.Call("Query.GetAllNames", &namespace, &names) err = client.Call("Query.GetAllNames", &namespace, &names)
if err != nil { if err != nil {
fmt.Println(err) Logger.Error(err)
} }
for _, name := range names { for _, name := range names {
fmt.Println(name) Logger.Info(name)
} }
}, },
@@ -60,7 +60,7 @@ var generateCmd = &cobra.Command{
client, err := rpc.Receive(dbPath) client, err := rpc.Receive(dbPath)
if err != nil { if err != nil {
fmt.Printf("dialing: %s\n", err) Logger.Errorf("dialing: %s\n", err)
return return
} }
@@ -71,10 +71,10 @@ var generateCmd = &cobra.Command{
err = client.Call("Query.Generate", &np, &password) err = client.Call("Query.Generate", &np, &password)
if err != nil { if err != nil {
fmt.Println(err) Logger.Error(err)
} }
fmt.Println(*password) Logger.Info(*password)
}, },
} }
@@ -87,7 +87,7 @@ var showCmd = &cobra.Command{
client, err := rpc.Receive(dbPath) client, err := rpc.Receive(dbPath)
if err != nil { if err != nil {
fmt.Printf("dialing: %s\n", err) Logger.Errorf("dialing: %s\n", err)
return return
} }
@@ -98,11 +98,11 @@ var showCmd = &cobra.Command{
err = client.Call("Query.Get", &np, &password) err = client.Call("Query.Get", &np, &password)
if err != nil { if err != nil {
fmt.Println(err) Logger.Error(err)
return return
} }
fmt.Println(password.Password) Logger.Info(password.Password)
}, },
} }
@@ -120,7 +120,7 @@ var addNamespaceCmd = &cobra.Command{
client, err := rpc.Receive(dbPath) client, err := rpc.Receive(dbPath)
if err != nil { if err != nil {
fmt.Printf("dialing: %s\n", err) Logger.Errorf("dialing: %s\n", err)
return return
} }
@@ -130,11 +130,11 @@ var addNamespaceCmd = &cobra.Command{
err = client.Call("Query.AddNamespace", &namespace, &placeholder) err = client.Call("Query.AddNamespace", &namespace, &placeholder)
if err != nil { if err != nil {
fmt.Println(err) Logger.Error(err)
return return
} }
fmt.Printf("Namespace %s was added\n", namespace) Logger.Infof("Namespace %s was added\n", namespace)
}, },
} }
@@ -147,7 +147,7 @@ var deleteNamespaceCmd = &cobra.Command{
client, err := rpc.Receive(dbPath) client, err := rpc.Receive(dbPath)
if err != nil { if err != nil {
fmt.Printf("dialing: %s\n", err) Logger.Errorf("dialing: %s\n", err)
return return
} }
@@ -157,11 +157,11 @@ var deleteNamespaceCmd = &cobra.Command{
err = client.Call("Query.DeleteNamespace", &namespace, &placeholder) err = client.Call("Query.DeleteNamespace", &namespace, &placeholder)
if err != nil { if err != nil {
fmt.Println(err) Logger.Error(err)
return return
} }
fmt.Printf("Namespace %s was deleted\n", namespace) Logger.Infof("Namespace %s was deleted\n", namespace)
}, },
} }
@@ -173,7 +173,7 @@ var listNamespacesCmd = &cobra.Command{
client, err := rpc.Receive(dbPath) client, err := rpc.Receive(dbPath)
if err != nil { if err != nil {
fmt.Printf("dialing: %s\n", err) Logger.Errorf("dialing: %s\n", err)
return return
} }
@@ -181,13 +181,13 @@ var listNamespacesCmd = &cobra.Command{
err = client.Call("Query.ListNamespaces", 0, &reply) err = client.Call("Query.ListNamespaces", 0, &reply)
if err != nil { if err != nil {
fmt.Println(err) Logger.Error(err)
return return
} }
fmt.Printf("Namespaces:\n") Logger.Info("Namespaces:")
for _, ns := range reply { for _, ns := range reply {
fmt.Println(ns) Logger.Info(ns)
} }
}, },
} }
@@ -206,13 +206,13 @@ var infoCmd = &cobra.Command{
client, err := rpc.Receive(dbPath) client, err := rpc.Receive(dbPath)
if err != nil { if err != nil {
fmt.Printf("dialing: %s\n", err) Logger.Errorf("dialing: %s\n", err)
return return
} }
var result *string var result *string
err = client.Call("Query.GetPeerString", 0, &result) err = client.Call("Query.GetPeerString", 0, &result)
fmt.Println(*result) Logger.Info(*result)
}, },
} }
@@ -226,7 +226,7 @@ var addPeerCmd = &cobra.Command{
client, err := rpc.Receive(dbPath) client, err := rpc.Receive(dbPath)
if err != nil { if err != nil {
fmt.Printf("dialing: %s\n", err) Logger.Errorf("dialing: %s\n", err)
return return
} }
@@ -246,11 +246,11 @@ var addPeerCmd = &cobra.Command{
err = client.Call("Query.AddPeer", &np, &success) err = client.Call("Query.AddPeer", &np, &success)
if err != nil { if err != nil {
fmt.Println(err) Logger.Error(err)
return return
} }
fmt.Println(*success) Logger.Info(*success)
}, },
} }
@@ -263,7 +263,7 @@ var removePeerCmd = &cobra.Command{
client, err := rpc.Receive(dbPath) client, err := rpc.Receive(dbPath)
if err != nil { if err != nil {
fmt.Printf("dialing: %s\n", err) Logger.Errorf("dialing: %s\n", err)
return return
} }
@@ -283,11 +283,11 @@ var removePeerCmd = &cobra.Command{
err = client.Call("Query.DeletePeer", &np, &success) err = client.Call("Query.DeletePeer", &np, &success)
if err != nil { if err != nil {
fmt.Println(err) Logger.Error(err)
return return
} }
fmt.Println(*success) Logger.Info(*success)
}, },
} }
@@ -300,7 +300,7 @@ var deleteCmd = &cobra.Command{
client, err := rpc.Receive(dbPath) client, err := rpc.Receive(dbPath)
if err != nil { if err != nil {
fmt.Printf("dialing: %s\n", err) Logger.Errorf("dialing: %s\n", err)
return return
} }
@@ -320,16 +320,15 @@ var deleteCmd = &cobra.Command{
err = client.Call("Query.Delete", &np, &success) err = client.Call("Query.Delete", &np, &success)
if err != nil { if err != nil {
fmt.Println(err) Logger.Error(err)
} }
fmt.Println(*success) Logger.Info(*success)
}, },
} }
func init() { func init() {
//listCmd.Flags().BoolP("all", "a", false, "List all items")
rootCmd.PersistentFlags().String("db", "", "db path") rootCmd.PersistentFlags().String("db", "", "db path")
rootCmd.MarkPersistentFlagRequired("db") rootCmd.MarkPersistentFlagRequired("db")
@@ -350,8 +349,9 @@ func init() {
} }
func main() { func main() {
InitLogger(true)
if err := rootCmd.Execute(); err != nil { if err := rootCmd.Execute(); err != nil {
fmt.Println(err) Logger.Error(err)
os.Exit(1) os.Exit(1)
} }
} }