Class: Hotdog::Commands::Untag
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Hotdog::Commands::Untag
- Defined in:
- lib/hotdog/commands/untag.rb
Constant Summary
Constants inherited from BaseCommand
BaseCommand::MASK_DATABASE, BaseCommand::MASK_QUERY, BaseCommand::PERSISTENT_DB
Instance Attribute Summary
Attributes inherited from BaseCommand
#application, #logger, #options
Instance Method Summary collapse
Methods inherited from BaseCommand
#execute, #fixed_string?, #initialize, #parse_options, #reload
Constructor Details
This class inherits a constructor from Hotdog::Commands::BaseCommand
Instance Method Details
#define_options(optparse, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hotdog/commands/untag.rb', line 8 def (optparse, ={}) default_option(, :retry, 5) default_option(, :tag_source, "user") default_option(, :tags, []) optparse.on("--retry NUM") do |v| [:retry] = v.to_i end optparse.on("--retry-delay SECONDS") do |v| [:retry_delay] = v.to_i end optparse.on("--source SOURCE") do |v| [:tag_source] = v end optparse.on("-a TAG", "-t TAG", "--tag TAG", "Use specified tag name/value") do |v| [:tags] << v end end |
#run(args = [], options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/hotdog/commands/untag.rb', line 26 def run(args=[], ={}) hosts = args.map { |arg| arg.sub(/\Ahost:/, "") } if [:tags].empty? # refresh all persistent.db since there is no way to identify user tags remove_db(@db) else if open_db with_retry do @db.transaction do [:tags].each do |tag| disassociate_tag_hosts(@db, tag, hosts) end end end end end hosts.each do |host| if [:tags].empty? # delete all user tags with_retry do (host, source=[:tag_source]) end else = with_retry { (host, source=[:tag_source]) } = ["tags"] = - [:tags] if == # nop else with_retry do (host, , source=[:tag_source]) end end end end end |