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
Execute all the stats methodes for all modules.
-
.delegate(category, stat) ⇒ Object
Delegate command to proper class.
-
.execute(*args) ⇒ Object
Executes a command.
-
.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
Execute all the stats methodes for all modules
42 43 44 45 46 47 48 49 |
# File 'lib/iStats/command.rb', line 42 def all puts "--- CPU Stats ---\n" Cpu.all puts "\n--- Fan Stats ---\n" Fan.all puts "\n--- Battery Stats ---\n" Battery.all end |
.delegate(category, stat) ⇒ Object
Delegate command to proper class
category - Hardware we are targeting (CPU, fan, etc.) stat - The stat we want
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/iStats/command.rb', line 25 def delegate(category, stat) case category when 'all' all when 'cpu' Cpu.delegate stat when 'fan' Fan.delegate stat when 'battery' Battery.delegate stat else help("Unknown category: #{category}") end end |
.execute(*args) ⇒ Object
Executes a command
args - Command line arguments
11 12 13 14 15 16 17 18 |
# File 'lib/iStats/command.rb', line 11 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.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/iStats/command.rb', line 79 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 istats fan Print all fan stats istats fan [speed] Print fan speed istats battery Print all battery stats istats battery [health] Print battery health istats battery [time | remain] Print battery time remaining istats battery [cycle_count | cc] Print battery cycle count info istats battery [temp | temperature] Print battery temperature istats battery [charge] Print battery charge istats battery [capacity] Print battery capacity info 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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/iStats/command.rb', line 54 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
109 110 111 |
# File 'lib/iStats/command.rb', line 109 def quit exit(1) end |