Pigeon-Ruby/pigeon-cli

104 lines
2.5 KiB
Plaintext
Raw Normal View History

2019-09-22 02:30:03 +00:00
#!/usr/bin/env ruby
require_relative File.join("dist", "pigeon")
require "thor"
module Pigeon
class Identity < Thor
class ConfigAlreadyExists < StandardError; end
2019-09-22 02:30:03 +00:00
desc "new", "Creates a new identiy in `.pigeon` directory if none exists"
def new
# TODO: --force flag
# TODO: --seed flag
if Dir.exist?(Pigeon::Storage::ROOT_DIR)
puts "Pigeon has detected a `.pigeon` directory.
Refusing to overwrite existing Pigeon config.
Remove config dir or switch to a different directory."
raise ConfigAlreadyExists
2019-09-22 02:30:03 +00:00
end
kp = Pigeon::KeyPair.new()
kp.save!
puts kp.public_key
end
desc "show", "Prints a base64 identiy string to STDOUT"
def show
puts Pigeon::Storage.current.get_conf("public_key")
end
end
class Blob < Thor
desc "set", "Copy arbitrary binary data into the database"
2019-09-22 02:30:03 +00:00
2019-09-22 17:34:08 +00:00
def set(data = "")
blob = (data != "") ? data : STDIN.read
puts Pigeon::Storage.current.set_blob(blob)
2019-09-22 02:30:03 +00:00
end
desc "get", "Read arbitrary data from the database"
2019-09-22 02:30:03 +00:00
2019-09-22 11:00:19 +00:00
def get(hex_digest)
puts Pigeon::Storage.current.get_blob(hex_digest)
2019-09-22 02:30:03 +00:00
end
end
class Peer < Thor
desc "add", "Begin following a Pigeon peer"
def add(identity)
puts Pigeon::Storage.current.add_peer(identity)
end
desc "remove", "Stop following a Pigeon peer"
def remove(identity)
puts Pigeon::Storage.current.remove_peer(identity)
end
desc "block", "Stop following a Pigeon peer AND refuse to replicate"
def block(identity)
puts Pigeon::Storage.current.block_peer(identity)
end
desc "all", "List all Pigeon peers"
def all
puts Pigeon::Storage.current.all_peers
end
end
2019-09-22 02:30:03 +00:00
class CLI < Thor
desc "status", "Show various information about the `.pigeon` directory"
def status
2019-09-25 01:54:32 +00:00
puts "
,.------------------------------------
| -`. Pigeon Protocol Ruby Client
| '( @ > Version: #{Config::VERSION}
| _) ( Peers: #{Dir[File.join(".pigeon", "peers", "*")].count}
| / ) Blocked: #{Dir[File.join(".pigeon", "blocked", "*")].count}
| /_,' /
| \ /
|===m" "m===
'-,___________________________________
"
2019-09-22 02:30:03 +00:00
end
desc "identity SUBCOMMAND ...ARGS", "Manage `.pigeon` identity"
subcommand "identity", Identity
desc "blob SUBCOMMAND ...ARGS", "Manage blob storage"
subcommand "blob", Blob
desc "peer SUBCOMMAND ...ARGS", "Manage blob storage"
subcommand "peer", Peer
2019-09-22 02:30:03 +00:00
end
end
Pigeon::CLI.start(ARGV)