Class: Btape::CLI
- Inherits:
-
Object
- Object
- Btape::CLI
- Defined in:
- lib/btape/cli.rb
Overview
Entry point invoked by the btape executable: parses argv, runs the
script, and reports success or failure.
Defined Under Namespace
Classes: Options
Constant Summary collapse
- USAGE =
'Usage: btape [options] SCRIPT.tape'- HELP_ARGUMENTS =
%w[help -h --help].freeze
- HELP_COMMANDS =
Parser::SIGNATURES.map { |name, arguments| "#{name} #{arguments}".strip }.freeze
- GENERATE =
'generate'- WS_URL_KEYS =
The two ways a flag can name a browser: --ws-url and --set WsUrl=.
[:ws_url, 'WsUrl'].freeze
Instance Method Summary collapse
-
#initialize(out: $stdout, err: $stderr, stdin: $stdin, runner: nil, generator: nil) ⇒ CLI
constructor
The runner is built after the flags are read, so that --verbose can reach it.
- #run(argv) ⇒ Object
Constructor Details
#initialize(out: $stdout, err: $stderr, stdin: $stdin, runner: nil, generator: nil) ⇒ CLI
The runner is built after the flags are read, so that --verbose can reach it. Pass one to use it as given.
23 24 25 26 27 28 29 |
# File 'lib/btape/cli.rb', line 23 def initialize(out: $stdout, err: $stderr, stdin: $stdin, runner: nil, generator: nil) @out = out @err = err @stdin = stdin @runner = runner @generator = generator end |
Instance Method Details
#run(argv) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/btape/cli.rb', line 31 def run(argv) return generate(argv.drop(1)) if argv.first == GENERATE = Options.new(false, {}, nil, false) arguments = (argv, ) return print_help if .help || arguments.empty? || HELP_ARGUMENTS.include?(arguments.first) raise Error, USAGE unless arguments.length == 1 record(arguments.first, ) 0 rescue Error, SystemCallError => e @err.puts "btape: #{e.}" 1 end |