Class: Appear::Command
- Inherits:
-
Object
- Object
- Appear::Command
- Defined in:
- lib/appear/command.rb
Overview
Entrypoint and manager for the command-line ‘appear` tool.
Instance Method Summary collapse
-
#execute(all_args) ⇒ Object
Execute the command.
-
#initialize ⇒ Command
constructor
A new instance of Command.
-
#option_parser ⇒ OptionParser
The ui for our command.
Constructor Details
Instance Method Details
#execute(all_args) ⇒ Object
Execute the command. Will exit(3) with a status; does not return.
66 67 68 69 70 71 72 73 74 |
# File 'lib/appear/command.rb', line 66 def execute(all_args) argv = option_parser.parse(*all_args) if @config.edit_file return execute_edit(argv) else return execute_pid(argv) end end |
#option_parser ⇒ OptionParser
The ui for our command.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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 |
# File 'lib/appear/command.rb', line 18 def option_parser @option_parser ||= OptionParser.new do |o| o. = 'Usage: appear [OPTION]... [PID]' o.separator 'Appear PID in your user interface.' o.separator 'Appear will use the current process PID by default.' o.separator '' o.separator 'Options:' o.on('-l', '--log-file [PATH]', 'log to a file') do |file| @config.log_file = file end o.on('-v', '--verbose', 'tell many tales about how the appear process is going') do |flag| @config.silent = false if flag end o.on('--record-runs', 'record every executed command as a JSON file in the appear spec folder') do |flag| @config.record_runs = flag end o.on('-e', '--edit [EDITOR]', "instead of revealing a PID, edit a file the given editor. Editors: #{::Appear::Editor::ALL.map {|c| c.name}}") do |flag| @config.edit_file = true @config.editor = flag end o.on('--version', 'show version information, then exit') do puts "appear #{Appear::VERSION}" puts " author: Jake Teton-Landis" puts " repo: https://github.com/airbnb/appear" exit 2 end o.on('-?', '-h', '--help', 'show this help, then exit') do puts o exit 2 end o.separator '' o.separator 'Exit status:' o.separator ' 0 if successfully revealed something,' o.separator ' 1 if an exception occurred,' o.separator ' 2 if there were no errors, but nothing was revealed.' end end |