WIP add/remove peers from cli
This commit is contained in:
@@ -111,6 +111,81 @@ var showCmd = &cobra.Command{
|
||||
},
|
||||
}
|
||||
|
||||
var printPeerStrCmd = &cobra.Command{
|
||||
Use: "peerstring",
|
||||
Short: "prints your own peerstring",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
dbPath, _ := cmd.Flags().GetString("db")
|
||||
client, err := rpc.Receive(dbPath)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("dialing: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
var result *string
|
||||
err = client.Call("Query.GetPeerString", 0, &result)
|
||||
fmt.Println(*result)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
var addPeerCmd = &cobra.Command{
|
||||
Use: "addpeer",
|
||||
Short: "add a peer",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
dbPath, _ := cmd.Flags().GetString("db")
|
||||
client, err := rpc.Receive(dbPath)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("dialing: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
peerString := args[0]
|
||||
|
||||
var success *bool
|
||||
np := rpc.NamespacePeer{ Namespace: "root", Peer: peerString }
|
||||
err = client.Call("Query.AddPeer", &np, &success)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(*success)
|
||||
},
|
||||
}
|
||||
|
||||
var removePeerCmd = &cobra.Command{
|
||||
Use: "removepeer",
|
||||
Short: "remove a peer",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
dbPath, _ := cmd.Flags().GetString("db")
|
||||
client, err := rpc.Receive(dbPath)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("dialing: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
peerString := args[0]
|
||||
|
||||
var success *bool
|
||||
np := rpc.NamespacePeer{ Namespace: "root", Peer: peerString }
|
||||
err = client.Call("Query.DeletePeer", &np, &success)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(*success)
|
||||
},
|
||||
}
|
||||
|
||||
var deleteCmd = &cobra.Command{
|
||||
Use: "delete",
|
||||
Short: "delete a Password",
|
||||
@@ -150,6 +225,9 @@ func init() {
|
||||
rootCmd.AddCommand(generateCmd)
|
||||
rootCmd.AddCommand(showCmd)
|
||||
rootCmd.AddCommand(deleteCmd)
|
||||
rootCmd.AddCommand(addPeerCmd)
|
||||
rootCmd.AddCommand(removePeerCmd)
|
||||
rootCmd.AddCommand(printPeerStrCmd)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -76,12 +76,6 @@ func main() {
|
||||
logger.Fatal(err)
|
||||
}
|
||||
|
||||
Cfg, err := storage.NewConfig(*dbPath + "/config.json")
|
||||
|
||||
if err != nil {
|
||||
logger.Fatal(err)
|
||||
}
|
||||
|
||||
storageHandler := storage.StorageHandler{
|
||||
Ctx: ctx ,
|
||||
Store: store,
|
||||
@@ -89,9 +83,16 @@ func main() {
|
||||
Ipfs: ipfs,
|
||||
PubSub: ps,
|
||||
Key: key,
|
||||
Config: Cfg,
|
||||
}
|
||||
|
||||
Cfg, err := storageHandler.NewConfig(*dbPath + "/config.json")
|
||||
|
||||
if err != nil {
|
||||
logger.Fatal(err)
|
||||
}
|
||||
|
||||
storageHandler.Config = Cfg
|
||||
storageHandler.ConfigPath = *dbPath + "/config.json"
|
||||
storageHandler.InitNamespaces()
|
||||
|
||||
for _, val := range storageHandler.Namespaces {
|
||||
|
||||
Reference in New Issue
Block a user