Class: Hivonic::Commands::Subcommand
- Inherits:
-
Object
- Object
- Hivonic::Commands::Subcommand
- Defined in:
- lib/hivonic/commands.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#dry_run ⇒ Object
readonly
Returns the value of attribute dry_run.
-
#exitstatus ⇒ Object
readonly
Returns the value of attribute exitstatus.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
-
#subcommand ⇒ Object
readonly
Returns the value of attribute subcommand.
-
#time_format ⇒ Object
readonly
Returns the value of attribute time_format.
-
#time_group_index ⇒ Object
readonly
Returns the value of attribute time_group_index.
-
#ttl ⇒ Object
readonly
Returns the value of attribute ttl.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts, args) ⇒ Subcommand
constructor
A new instance of Subcommand.
- #is_successful?(status) ⇒ Boolean
- #output(stdout) ⇒ Object
- #run ⇒ Object
- #successful? ⇒ Boolean
Constructor Details
#initialize(opts, args) ⇒ Subcommand
Returns a new instance of Subcommand.
47 48 49 50 51 52 53 54 |
# File 'lib/hivonic/commands.rb', line 47 def initialize(opts, args) @regexp = Regexp.new opts['regexp'] @time_format = opts['time-format'] @time_group_index = opts['time-group-index'].to_i @ttl = opts['ttl'].to_i @dry_run = opts['dry-run'] @exitstatus = 1 end |
Instance Attribute Details
#dry_run ⇒ Object (readonly)
Returns the value of attribute dry_run.
44 45 46 |
# File 'lib/hivonic/commands.rb', line 44 def dry_run @dry_run end |
#exitstatus ⇒ Object (readonly)
Returns the value of attribute exitstatus.
45 46 47 |
# File 'lib/hivonic/commands.rb', line 45 def exitstatus @exitstatus end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
42 43 44 |
# File 'lib/hivonic/commands.rb', line 42 def query @query end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
38 39 40 |
# File 'lib/hivonic/commands.rb', line 38 def regexp @regexp end |
#subcommand ⇒ Object (readonly)
Returns the value of attribute subcommand.
43 44 45 |
# File 'lib/hivonic/commands.rb', line 43 def subcommand @subcommand end |
#time_format ⇒ Object (readonly)
Returns the value of attribute time_format.
39 40 41 |
# File 'lib/hivonic/commands.rb', line 39 def time_format @time_format end |
#time_group_index ⇒ Object (readonly)
Returns the value of attribute time_group_index.
40 41 42 |
# File 'lib/hivonic/commands.rb', line 40 def time_group_index @time_group_index end |
#ttl ⇒ Object (readonly)
Returns the value of attribute ttl.
41 42 43 |
# File 'lib/hivonic/commands.rb', line 41 def ttl @ttl end |
Class Method Details
.run(opts, args) ⇒ Object
56 57 58 59 |
# File 'lib/hivonic/commands.rb', line 56 def self.run(opts, args) output, exitstatus = self.new(opts, args).run return output, exitstatus end |
Instance Method Details
#is_successful?(status) ⇒ Boolean
88 89 90 |
# File 'lib/hivonic/commands.rb', line 88 def is_successful?(status) status == 0 end |
#output(stdout) ⇒ Object
65 66 67 |
# File 'lib/hivonic/commands.rb', line 65 def output(stdout) stdout end |
#run ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/hivonic/commands.rb', line 69 def run raise "subcommand can't be nil" if subcommand.nil? if dry_run stdout = "DRY RUN: Subcommand => #{subcommand}" @exitstatus = 0 else puts "Running: Subcommand => #{subcommand}" stdout = `#{subcommand}` @exitstatus = $?.exitstatus end return output(stdout), self.exitstatus end |
#successful? ⇒ Boolean
84 85 86 |
# File 'lib/hivonic/commands.rb', line 84 def successful? self.exitstatus == 0 end |