File: state.rb

package info (click to toggle)
ticgit 1.0.2.18-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 488 kB
  • sloc: ruby: 2,848; sh: 124; makefile: 16
file content (45 lines) | stat: -rw-r--r-- 1,095 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
module TicGitNG
  module Command
    module State
      def parser(opts)
        opts.banner = "Usage: ti state [ticid] state"
      end

      def execute
        if args.size > 1
          tid, new_state = args[0].strip, args[1].strip

          if valid_state?(new_state)
            tic.ticket_change(new_state, tid)
          else
            puts "Invalid State - please choose from: #{joined_states}"
          end
        elsif args.size > 0
          # new state
          new_state = args[0].chomp

          if valid_state?(new_state)
            tic.ticket_change(new_state)
          else
            puts "Invalid State - please choose from: #{joined_states}"
          end
        else
          puts 'You need to at least specify a new state for the current ticket'
          puts "please choose from: #{joined_states}"
        end
      end

      def valid_state?(state)
        available_states.include?(state)
      end

      def available_states
        tic.tic_states.sort
      end

      def joined_states
        available_states.join(', ')
      end
    end
  end
end