Class: Commands::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/base.rb

Direct Known Subclasses

Accept, Block, Finish, Info, Pick, Unblock

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
16
17
18
# File 'lib/commands/base.rb', line 10

def initialize(*args)
  @input = STDIN
  @output = STDOUT

  @options = {}

  parse_gitconfig
  parse_argv(*args)
end

Instance Attribute Details

#inputObject

Returns the value of attribute input.



8
9
10
# File 'lib/commands/base.rb', line 8

def input
  @input
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/commands/base.rb', line 8

def options
  @options
end

#outputObject

Returns the value of attribute output.



8
9
10
# File 'lib/commands/base.rb', line 8

def output
  @output
end

Instance Method Details

#get(cmd) ⇒ Object



36
37
38
39
# File 'lib/commands/base.rb', line 36

def get(cmd)
  put cmd if options[:verbose]
  `#{cmd}`
end

#put(string, newline = true) ⇒ Object



27
28
29
# File 'lib/commands/base.rb', line 27

def put(string, newline=true)
  @output.print(newline ? string + "\n" : string) unless options[:quiet]
end

#run!Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/commands/base.rb', line 41

def run!
  unless options[:api_token] && options[:project_id]
    put "Pivotal Tracker API Token and Project ID are required"
    return 1
  end

  PivotalTracker::Client.token = options[:api_token]
  PivotalTracker::Client.use_ssl = options[:use_ssl]

  return 0
end

#sys(cmd) ⇒ Object



31
32
33
34
# File 'lib/commands/base.rb', line 31

def sys(cmd)
  put cmd if options[:verbose]
  system cmd #"#{cmd} > /dev/null 2>&1"
end

#with(input, output) ⇒ Object



20
21
22
23
24
25
# File 'lib/commands/base.rb', line 20

def with(input, output)
  tap do
    @input = input
    @output = output
  end
end