Class: Sem4rCli::CommandJob

Inherits:
OptParseCommand::Command
  • Object
show all
Defined in:
lib/sem4r_cli/commands/cmd_job.rb

Overview

BulkMutateJob

Class Method Summary collapse

Instance Method Summary collapse

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

.commandObject



34
35
36
# File 'lib/sem4r_cli/commands/cmd_job.rb', line 34

def self.command
  "job"
end

.descriptionObject



42
43
44
# File 'lib/sem4r_cli/commands/cmd_job.rb', line 42

def self.description
  "manage bulk mutate job (subcommands: #{subcommands.join(', ')})"
end

.subcommandsObject



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(options)
  opt_parser        = OptionParser.new
  opt_parser.banner = "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
    options.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)
  options = OpenStruct.new
  rest    = command_opt_parser(options).parse(argv)
  return false if options.exit

  if rest.empty?
    puts "missing command"
    return false
  end

           = @sem4r_cli.
  ret             = true
  subcommand      = rest[0]
  subcommand_args = rest[1..-1]
  case subcommand

    when "list"
      Sem4rCli::report(.jobs, :id, :status)

    when "delete"
      job_id = rest[1]
      .job_delete(job_id)

    when "submit"
      ret = create()

    when "submit_pending"
      ret = create(, true)
    else
      puts "unknow subcommand '#{subcommand}'; must be one of #{self.class.subcommands.join(", ")}"
      return false
  end
  .adwords.p_counters
  ret
end