`-- peer list` command
This commit is contained in:
parent
73ad2a1c46
commit
f17c9eb440
|
@ -17,6 +17,7 @@ You can override this value by specifying a `PIGEON_PATH` ENV var.
|
||||||
- [ ] Figure out a system for where to place the default data storage directory
|
- [ ] Figure out a system for where to place the default data storage directory
|
||||||
- [ ] Get a good CI system going? Run tests at PR time, provide prebuilt binaries, prevent coverage slips, etc..
|
- [ ] Get a good CI system going? Run tests at PR time, provide prebuilt binaries, prevent coverage slips, etc..
|
||||||
- [ ] Add a `transact()` helper to ensure all transactions are closed out.
|
- [ ] Add a `transact()` helper to ensure all transactions are closed out.
|
||||||
|
- [ ] Switch to [SQLX](https://github.com/jmoiron/sqlx) for extra sanity.
|
||||||
- [ ] Finish all the things below:
|
- [ ] Finish all the things below:
|
||||||
|
|
||||||
|Done?|Noun |Verb | Flag / arg 1 | Flag 2 |
|
|Done?|Noun |Verb | Flag / arg 1 | Flag 2 |
|
||||||
|
|
|
@ -75,6 +75,16 @@ var peerBlockCmd = &cobra.Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var peerListCmd = &cobra.Command{
|
||||||
|
Use: "list",
|
||||||
|
Short: "show a list of peers by their status (blocked, following, etc..)",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
for _, peer := range listPeers() {
|
||||||
|
fmt.Printf("%s %s\n", peer.mhash, peer.status)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
var peerFollowCmd = &cobra.Command{
|
var peerFollowCmd = &cobra.Command{
|
||||||
Use: "follow",
|
Use: "follow",
|
||||||
Short: "Follow a peer and replicate their feed when possible.",
|
Short: "Follow a peer and replicate their feed when possible.",
|
||||||
|
@ -95,6 +105,8 @@ func BootstrapCLI() {
|
||||||
|
|
||||||
rootCmd.AddCommand(peerRootCmd)
|
rootCmd.AddCommand(peerRootCmd)
|
||||||
peerRootCmd.AddCommand(peerBlockCmd)
|
peerRootCmd.AddCommand(peerBlockCmd)
|
||||||
|
peerRootCmd.AddCommand(peerFollowCmd)
|
||||||
|
peerRootCmd.AddCommand(peerListCmd)
|
||||||
|
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|
|
@ -15,8 +15,14 @@ const (
|
||||||
unknown = "unknown"
|
unknown = "unknown"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type peer struct {
|
||||||
|
mhash string
|
||||||
|
status PeerStatus
|
||||||
|
}
|
||||||
|
|
||||||
const createPeer = "INSERT INTO peers(mhash, status) VALUES(?1, ?2)"
|
const createPeer = "INSERT INTO peers(mhash, status) VALUES(?1, ?2)"
|
||||||
const findPeerByStatus = "SELECT status FROM peers WHERE mhash=$1;"
|
const findPeerByStatus = "SELECT status FROM peers WHERE mhash=$1;"
|
||||||
|
const getAllPeers = "SELECT mhash, status FROM peers ORDER BY status DESC, mhash ASC;"
|
||||||
|
|
||||||
func getPeerStatus(mHash string) PeerStatus {
|
func getPeerStatus(mHash string) PeerStatus {
|
||||||
var status PeerStatus
|
var status PeerStatus
|
||||||
|
@ -52,7 +58,31 @@ func addPeer(mHash string, status PeerStatus) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// func showPeers() {}
|
func listPeers() []peer {
|
||||||
|
var (
|
||||||
|
status PeerStatus
|
||||||
|
mhash string
|
||||||
|
)
|
||||||
|
rows, err := getDB().Query(getAllPeers)
|
||||||
|
if err != nil {
|
||||||
|
panicf("showPeers query failure: %s", err)
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
output := []peer{}
|
||||||
|
for rows.Next() {
|
||||||
|
err := rows.Scan(&mhash, &status)
|
||||||
|
if err != nil {
|
||||||
|
panicf("Show peers row scan failure: %s", err)
|
||||||
|
}
|
||||||
|
output = append(output, peer{mhash: mhash, status: status})
|
||||||
|
}
|
||||||
|
err = rows.Err()
|
||||||
|
if err != nil {
|
||||||
|
panicf("showPeers row error: %s", err)
|
||||||
|
}
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
// func showBlockedPeers() {}
|
// func showBlockedPeers() {}
|
||||||
// func blockPeer() {}
|
// func blockPeer() {}
|
||||||
// func unblockPeer() {}
|
// func unblockPeer() {}
|
||||||
|
|
Loading…
Reference in New Issue