Class: Sem4rCli::CommandJob
- Inherits:
-
OptParseCommand::Command
- Object
- OptParseCommand::Command
- Sem4rCli::CommandJob
- Defined in:
- lib/sem4r_cli/commands/cmd_job.rb
Overview
BulkMutateJob
Class Method Summary collapse
Instance Method Summary collapse
- #command_opt_parser(options) ⇒ Object
-
#initialize(sem4r_cli) ⇒ CommandJob
constructor
A new instance of CommandJob.
- #parse_and_run(argv) ⇒ Object
Constructor Details
#initialize(sem4r_cli) ⇒ CommandJob
Returns a new instance of CommandJob.
46 47 48 |
# File 'lib/sem4r_cli/commands/cmd_job.rb', line 46 def initialize(sem4r_cli) @sem4r_cli = sem4r_cli end |
Class Method Details
.command ⇒ Object
34 35 36 |
# File 'lib/sem4r_cli/commands/cmd_job.rb', line 34 def self.command "job" end |
.description ⇒ Object
42 43 44 |
# File 'lib/sem4r_cli/commands/cmd_job.rb', line 42 def self.description "manage bulk mutate job (subcommands: #{subcommands.join(', ')})" end |
.subcommands ⇒ Object
38 39 40 |
# File 'lib/sem4r_cli/commands/cmd_job.rb', line 38 def self.subcommands %w{list submit submit_pending delete} end |
Instance Method Details
#command_opt_parser(options) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sem4r_cli/commands/cmd_job.rb', line 50 def command_opt_parser() opt_parser = OptionParser.new opt_parser. = "Usage #{self.class.command} [command_options ] [#{self.class.subcommands.join("|")}]" opt_parser.separator "" opt_parser.separator "#{self.class.description}" opt_parser.on("-h", "--help", "show this message") do puts opt_parser .exit = true end end |
#parse_and_run(argv) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/sem4r_cli/commands/cmd_job.rb', line 61 def parse_and_run(argv) = OpenStruct.new rest = command_opt_parser().parse(argv) return false if .exit if rest.empty? puts "missing command" return false end account = @sem4r_cli.account ret = true subcommand = rest[0] subcommand_args = rest[1..-1] case subcommand when "list" Sem4rCli::report(account.jobs, :id, :status) when "delete" job_id = rest[1] account.job_delete(job_id) when "submit" ret = create(account) when "submit_pending" ret = create(account, true) else puts "unknow subcommand '#{subcommand}'; must be one of #{self.class.subcommands.join(", ")}" return false end account.adwords.p_counters ret end |