Class: IStats::Command
- Inherits:
-
Object
- Object
- IStats::Command
- Extended by:
- Color
- Defined in:
- lib/iStats/command.rb
Overview
Main point of entry for ‘istats` command-line tool
Constant Summary
Constants included from Color
Class Method Summary collapse
- .all ⇒ Object
- .delegate(category, stat) ⇒ Object
- .execute(*args) ⇒ Object
-
.help(error = nil) ⇒ Object
Public: Prints help.
-
.parse_options ⇒ Object
Public: Parse extra options.
-
.quit ⇒ Object
Public: Quit / Exit program.
Methods included from Color
Class Method Details
.all ⇒ Object
27 28 29 30 |
# File 'lib/iStats/command.rb', line 27 def all # Exec all Cpu.all end |
.delegate(category, stat) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/iStats/command.rb', line 16 def delegate(category, stat) case category when 'all' all when 'cpu' Cpu.delegate stat else help("Unknown category: #{category}") end end |
.execute(*args) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/iStats/command.rb', line 7 def execute(*args) # Default command is 'all' category = args.empty? ? 'all' : args.shift stat = args.empty? ? 'all' : args.shift delegate(category, stat) end |
.help(error = nil) ⇒ Object
Public: Prints help.
Returns nothing.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/iStats/command.rb', line 60 def help(error = nil) text = " #{error.nil? ? '' : red("\n[Error] #{error}\n")} - iStats: help --------------------------------------------------- istats --help This help text istats --version Print current version istats all Print all stats istats cpu Print all CPU stats istats cpu [temp | temperature] Print CPU temperature for more help see: https://github.com/Chris911/iStats ".gsub(/^ {8}/, '') # strip the first eight spaces of every line puts text end |
.parse_options ⇒ Object
Public: Parse extra options
returns nothing
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/iStats/command.rb', line 35 def o = OptionParser.new do |opts| opts.on('-v', '--version', 'Print Version') do puts "iStats v#{IStats::VERSION}" quit end opts.on('-h', '--help', 'Print Help') do help quit end end begin o.parse! rescue OptionParser::MissingArgument => e help e. quit rescue OptionParser::InvalidOption => e help e. quit end end |
.quit ⇒ Object
Public: Quit / Exit program
Returns nothing
81 82 83 |
# File 'lib/iStats/command.rb', line 81 def quit exit(1) end |