Class: Above::CLI
- Inherits:
-
Object
- Object
- Above::CLI
- Defined in:
- lib/above/cli.rb
Overview
CLI handled by optparse
Instance Method Summary collapse
- #certs(opts) ⇒ Object
- #create_cert ⇒ Object
- #dir(opts) ⇒ Object
- #help(opts) ⇒ Object
- #server(opts) ⇒ Object
- #start(*_args) ⇒ Object
- #start_server ⇒ Object
- #version(opts) ⇒ Object
Instance Method Details
#certs(opts) ⇒ Object
36 37 38 39 40 |
# File 'lib/above/cli.rb', line 36 def certs(opts) opts.on("-c", "--cert DOMAINS", "Make a certificate for DOMAINS (comma seperated list)") do |opt| [:domain] = opt end end |
#create_cert ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/above/cli.rb', line 42 def create_cert if .key?(:domain) if !.key?(:dir) puts "Directory argument missing" exit end domain_arr = [:domain].split(",") dir = [:dir] cert = Above::Certs.new cert.create(domain_arr:, dir:) cert.dane(domain_arr:, dir:) end end |
#dir(opts) ⇒ Object
57 58 59 60 61 |
# File 'lib/above/cli.rb', line 57 def dir(opts) opts.on("-d", "--dir DIRECTORY", "Make a certificate in, or look for config in DIRECTORY") do |opt| [:dir] = opt end end |
#help(opts) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/above/cli.rb', line 63 def help(opts) opts.on("-h", "--help", "This help message") do puts opts exit end end |
#server(opts) ⇒ Object
70 71 72 73 74 |
# File 'lib/above/cli.rb', line 70 def server(opts) opts.on("-s", "--start", "Start the server, if a config directory isn't found one will be created") do |opt| [:server] = opt end end |
#start(*_args) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/above/cli.rb', line 12 def start(*_args) = {} OptionParser.new do |opts| opts. = " Above\n A Gemini Protocol server\n\n Commands:\n BANNER\n certs(opts)\n dir(opts)\n server(opts)\n help(opts)\n\n version(opts)\n end.parse!\n\n create_cert\n start_server\nrescue OptionParser::InvalidOption\n puts \"Invalid option\"\n # Don't have opts here to show help\nend\n" |
#start_server ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/above/cli.rb', line 76 def start_server return unless [:server] dir = [:dir] Above::Config.init_dir unless dir domains = Above::Config.read_config(dir:) domains.each_pair do |server_name, server_hash| puts "Starting #{server_name}" server = Above::Server.new(config: server_hash) server.start end end |
#version(opts) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/above/cli.rb', line 88 def version(opts) opts.on("-v", "--version", "The version") do puts Above::VERSION exit end end |