Class: ApCommand::Application
- Inherits:
-
Object
- Object
- ApCommand::Application
- Defined in:
- lib/ap_command.rb
Overview
ap_command main class.
Class Method Summary collapse
-
.invoke(argv) ⇒ void
execute application shortcut.
Instance Method Summary collapse
-
#awesome(data) ⇒ void
call awesome_print.
-
#run(argv) ⇒ void
execute application.
-
#usage ⇒ void
show usage.
-
#version ⇒ void
show version.
Class Method Details
.invoke(argv) ⇒ void
This method returns an undefined value.
execute application shortcut.
65 66 67 |
# File 'lib/ap_command.rb', line 65 def self.invoke(argv) self.new.run(argv) end |
Instance Method Details
#awesome(data) ⇒ void
This method returns an undefined value.
call awesome_print.
38 39 40 |
# File 'lib/ap_command.rb', line 38 def awesome(data) ap(data, indent: 2) end |
#run(argv) ⇒ void
This method returns an undefined value.
execute application.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ap_command.rb', line 19 def run(argv) path = argv.first.to_s version if(path == '--version' or path == '-v') usage if(path == '--help' or path == '-h') usage unless(File.exists?(path)) begin awesome(JSON.parse(File.read(path))) rescue JSON::ParserError => e puts "Error: #{e.class} message => #{e.}" puts usage end end |
#usage ⇒ void
This method returns an undefined value.
show usage.
45 46 47 48 49 50 |
# File 'lib/ap_command.rb', line 45 def usage puts "usage:" puts "% #{File.basename($0)} /path/to/file.json" puts "json file awsome print for command line tool." exit end |
#version ⇒ void
This method returns an undefined value.
show version.
55 56 57 58 |
# File 'lib/ap_command.rb', line 55 def version puts "#{File.basename($0)} #{VERSION}" exit end |