Class: Launchy::Cli
- Inherits:
-
Object
- Object
- Launchy::Cli
- Defined in:
- lib/launchy/cli.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #error_output(error) ⇒ Object
- #good_run(argv, env) ⇒ Object
-
#initialize ⇒ Cli
constructor
A new instance of Cli.
- #parse(argv, env) ⇒ Object
- #parser ⇒ Object
- #run(argv = ARGV, env = ENV) ⇒ Object
Constructor Details
#initialize ⇒ Cli
Returns a new instance of Cli.
7 8 9 |
# File 'lib/launchy/cli.rb', line 7 def initialize @options = {} end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/launchy/cli.rb', line 6 def @options end |
Instance Method Details
#error_output(error) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/launchy/cli.rb', line 75 def error_output( error ) $stderr.puts "ERROR: #{error}" Launchy.log "ERROR: #{error}" error.backtrace.each do |bt| Launchy.log bt end $stderr.puts "Try `#{parser.program_name} --help' for more information." return false end |
#good_run(argv, env) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/launchy/cli.rb', line 66 def good_run( argv, env ) if parse( argv, env ) then Launchy.open( argv.shift, ) { |e| error_output( e ) } return true else return false end end |
#parse(argv, env) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/launchy/cli.rb', line 59 def parse( argv, env ) parser.parse!( argv ) return true rescue ::OptionParser::ParseError => pe error_output( pe ) end |
#parser ⇒ Object
11 12 13 14 15 16 17 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 |
# File 'lib/launchy/cli.rb', line 11 def parser @parser ||= OptionParser.new do |op| op. = "Usage: launchy [options] thing-to-launch" op.separator "" op.separator "Launch Options:" op.on( "-a", "--application APPLICATION", "Explicitly specify the application class to use in the launch") do |app| @options[:application] = app end op.on( "-d", "--debug", "Force debug. Output lots of information.") do |d| @options[:debug] = true end op.on( "-e", "--engine RUBY_ENGINE", "Force launchy to behave as if it was on a particular ruby engine.") do |e| @options[:ruby_engine] = e end op.on( "-n", "--dry-run", "Don't launchy, print the command to be executed on stdout" ) do |x| @options[:dry_run] = true end op.on( "-o", "--host-os HOST_OS", "Force launchy to behave as if it was on a particular host os.") do |os| @options[:host_os] = os end op.separator "" op.separator "Standard Options:" op.on( "-h", "--help", "Print this message.") do |h| $stdout.puts op.to_s exit 0 end op.on( "-v", "--version", "Output the version of Launchy") do |v| $stdout.puts "Launchy version #{Launchy::VERSION}" exit 0 end end end |
#run(argv = ARGV, env = ENV) ⇒ Object
85 86 87 |
# File 'lib/launchy/cli.rb', line 85 def run( argv = ARGV, env = ENV ) exit 1 unless good_run( argv, env ) end |