Class: ApCommand::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/ap_command.rb

Overview

ap_command main class.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.invoke(argv) ⇒ void

This method returns an undefined value.

execute application shortcut.

Parameters:

  • argv (Array)

    ARGV object.



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.

Parameters:

  • data (Hash)

    awesome print object.



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.

Parameters:

  • argv (Array)

    ARGV object.



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.message}"
    puts
    usage
  end
end

#usagevoid

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

#versionvoid

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