Class: Commands::Base

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

Direct Known Subclasses

Finish, Pick

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input = STDIN, output = STDOUT, *args) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
15
# File 'lib/commands/base.rb', line 8

def initialize(input=STDIN, output=STDOUT, *args)
  @input = input
  @output = output
  @options = {}
  
  parse_gitconfig
  parse_argv(*args)
end

Instance Attribute Details

#inputObject

Returns the value of attribute input.



6
7
8
# File 'lib/commands/base.rb', line 6

def input
  @input
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/commands/base.rb', line 6

def options
  @options
end

#outputObject

Returns the value of attribute output.



6
7
8
# File 'lib/commands/base.rb', line 6

def output
  @output
end

Instance Method Details

#get(cmd) ⇒ Object



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

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

#put(string, newline = true) ⇒ Object



17
18
19
# File 'lib/commands/base.rb', line 17

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

#run!Object



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

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

#sys(cmd) ⇒ Object



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

def sys(cmd)
  put cmd if options[:verbose]
  system cmd
end