Class: CP::App
- Includes:
- Has::Commands, Has::Options, Singleton
- Defined in:
- lib/cp/app.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#runner ⇒ Object
Returns the value of attribute runner.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #app(attr, value) ⇒ Object
- #define_builtin_options ⇒ Object
- #error(msg) ⇒ Object
- #fatal(msg) ⇒ Object
-
#initialize ⇒ App
constructor
A new instance of App.
- #run(*args) ⇒ Object
Methods included from Has::Options
Methods included from Has::Commands
Constructor Details
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/cp/app.rb', line 10 def name @name end |
#runner ⇒ Object
Returns the value of attribute runner.
10 11 12 |
# File 'lib/cp/app.rb', line 10 def runner @runner end |
#version ⇒ Object
Returns the value of attribute version.
10 11 12 |
# File 'lib/cp/app.rb', line 10 def version @version end |
Class Method Details
.exported_methods ⇒ Object
45 46 47 |
# File 'lib/cp/app.rb', line 45 def self.exported_methods [:app, :command, :option] end |
Instance Method Details
#app(attr, value) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/cp/app.rb', line 19 def app( attr, value ) begin self.send( "#{attr}=", value ) rescue NoMethodError raise ArgumentError.new( "no such property: #{attr}" ) end end |
#define_builtin_options ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/cp/app.rb', line 27 def option( "-f", "--format FORMAT", "Output format" ) do |o| o.allowed = [:json, :table, :yaml] o.action = lambda { |value| CP::HighLine.instance.format = value } end end |
#error(msg) ⇒ Object
41 42 43 |
# File 'lib/cp/app.rb', line 41 def error( msg ) $stderr.puts "#{self.name}: #{msg}. See `#{self.name} --help`." end |
#fatal(msg) ⇒ Object
36 37 38 39 |
# File 'lib/cp/app.rb', line 36 def fatal( msg ) self.error( msg ) exit 1 end |