Class: Rallycat::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/rallycat/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, stdout = STDOUT) ⇒ CLI

Returns a new instance of CLI.



7
8
9
10
11
12
13
# File 'lib/rallycat/cli.rb', line 7

def initialize(argv, stdout=STDOUT)
  @argv   = argv
  @stdout = stdout

  parse_global_options!
  parse_command_options!
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/rallycat/cli.rb', line 5

def options
  @options
end

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
25
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
# File 'lib/rallycat/cli.rb', line 15

def run
  case @command
  when 'cat'
    api = Rallycat::Connection.new(options[:username], options[:password]).api

    story_number = @argv.shift

    abort 'The "cat" command requires a story or defect number.' unless story_number

    @stdout.puts Rallycat::Cat.new(api).story(story_number)
  when 'update'
    api = Rallycat::Connection.new(options[:username], options[:password]).api

    task_number = @argv.shift

    abort 'The "update" command requires a task number.' unless task_number

    opts = {}
    opts[:blocked] = true            if options[:blocked]
    opts[:state]   = "In-Progress"   if options[:in_progress]
    opts[:state]   = "Completed"     if options[:completed]
    opts[:state]   = "Defined"       if options[:defined]
    opts[:owner]   = options[:owner] if options[:owner]

    @stdout.puts Rallycat::Update.new(api).task(task_number, opts)
  when 'list'
    api = Rallycat::Connection.new(options[:username], options[:password]).api
    project = options[:project]

    if options[:iteration]
      @stdout.puts Rallycat::List.new(api).stories(project, options[:iteration])
    else
      @stdout.puts Rallycat::List.new(api).iterations(project)
    end
  when 'help'
    # `puts` calls `to_s`
    @stdout.puts Rallycat::Help.new
  else
    @stdout.puts "'#{@command}' is not a supported command. See 'rallycat help'."
  end

rescue Rallycat::RallycatError, ArgumentError => e
  abort e.message
end