Class: Rbkb::Cli::PlugCli
- Inherits:
-
Executable
- Object
- Executable
- Rbkb::Cli::PlugCli
- Defined in:
- lib/rbkb/plug/cli.rb
Overview
Rbkb::Cli::Executable is an abstract class for creating command line executables using the Ruby Black Bag framework.
Direct Known Subclasses
Constant Summary collapse
- RX_HOST_AND_PORT =
/^([\w\._-]+):(\d+)$/
- RX_PORT_OPT_ADDR =
/^(?:([\w\._-]+):)?(\d+)$/
Instance Attribute Summary collapse
-
#blit_addr ⇒ Object
Returns the value of attribute blit_addr.
-
#blit_port ⇒ Object
Returns the value of attribute blit_port.
-
#blit_proto ⇒ Object
Returns the value of attribute blit_proto.
-
#local_addr ⇒ Object
Returns the value of attribute local_addr.
-
#local_port ⇒ Object
Returns the value of attribute local_port.
-
#plug_opts ⇒ Object
Returns the value of attribute plug_opts.
-
#target_addr ⇒ Object
Returns the value of attribute target_addr.
-
#target_port ⇒ Object
Returns the value of attribute target_port.
-
#transport ⇒ Object
Returns the value of attribute transport.
Attributes inherited from Executable
#argv, #exit_status, #oparse, #opts, #stderr, #stdin, #stdout
Instance Method Summary collapse
-
#initialize(*args) ⇒ PlugCli
constructor
A new instance of PlugCli.
- #make_parser ⇒ Object
- #parse_target_argument ⇒ Object
Methods inherited from Executable
#bail, #bail_args, #exit, #go, #parse, run
Constructor Details
#initialize(*args) ⇒ PlugCli
Returns a new instance of PlugCli.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rbkb/plug/cli.rb', line 21 def initialize(*args) super(*args) do |this| this.blit_addr ||= Plug::Blit::DEFAULT_IPADDR this.blit_port ||= Plug::Blit::DEFAULT_PORT this.transport ||= :TCP this.plug_opts ||= {} yield this if block_given? end # TODO Plug::UI obviously need fixing. # TODO It shouldn't be driven by constants for configuration Plug::UI::LOGCFG[:verbose] = true Plug::UI::LOGCFG[:dump] = :hex Plug::UI::LOGCFG[:out] = @stderr end |
Instance Attribute Details
#blit_addr ⇒ Object
Returns the value of attribute blit_addr.
17 18 19 |
# File 'lib/rbkb/plug/cli.rb', line 17 def blit_addr @blit_addr end |
#blit_port ⇒ Object
Returns the value of attribute blit_port.
17 18 19 |
# File 'lib/rbkb/plug/cli.rb', line 17 def blit_port @blit_port end |
#blit_proto ⇒ Object
Returns the value of attribute blit_proto.
17 18 19 |
# File 'lib/rbkb/plug/cli.rb', line 17 def blit_proto @blit_proto end |
#local_addr ⇒ Object
Returns the value of attribute local_addr.
17 18 19 |
# File 'lib/rbkb/plug/cli.rb', line 17 def local_addr @local_addr end |
#local_port ⇒ Object
Returns the value of attribute local_port.
17 18 19 |
# File 'lib/rbkb/plug/cli.rb', line 17 def local_port @local_port end |
#plug_opts ⇒ Object
Returns the value of attribute plug_opts.
17 18 19 |
# File 'lib/rbkb/plug/cli.rb', line 17 def plug_opts @plug_opts end |
#target_addr ⇒ Object
Returns the value of attribute target_addr.
17 18 19 |
# File 'lib/rbkb/plug/cli.rb', line 17 def target_addr @target_addr end |
#target_port ⇒ Object
Returns the value of attribute target_port.
17 18 19 |
# File 'lib/rbkb/plug/cli.rb', line 17 def target_port @target_port end |
#transport ⇒ Object
Returns the value of attribute transport.
17 18 19 |
# File 'lib/rbkb/plug/cli.rb', line 17 def transport @transport end |
Instance Method Details
#make_parser ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rbkb/plug/cli.rb', line 37 def make_parser() arg = super() arg. << " host:port" arg.on("-o", "--output=FILE", "Output to file") do |o| Plug::UI::LOGCFG[:out] = File.open(o, "w") # XXX end arg.on("-q", "--quiet", "Turn off verbose logging") do Plug::UI::LOGCFG[:verbose] = false # XXX end arg.on("-d", "--dump-format=hex/raw", "Output conversations in hexdump or raw") do |d| if m=/^(hex|raw)$/i.match(d) Plug::UI::LOGCFG[:dump] = m[1].downcase.to_sym # XXX else bail "Invalid dump format: #{d.inspect}" end end arg.on("-b", "--blit=ADDR:PORT", "Where to listen for blit") do |b| unless m=RX_PORT_OPT_ADDR.match(b) bail("Invalid blit address/port") end @blit_port = m[2].to_i @blit_addr = m[1] if m[1] end arg.on("-u", "--udp", "UDP mode") { @transport=:UDP } arg.on("-S", "--start-tls", "Initiate TLS") {|s| @plug_opts[:tls]=true } return arg end |
#parse_target_argument ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/rbkb/plug/cli.rb', line 73 def parse_target_argument() unless (m = RX_HOST_AND_PORT.match(tgt=@argv.shift)) bail "Invalid target: #{tgt}\n Hint: use -h" end @target_addr = m[1] @target_port = m[2].to_i return m end |