Class: Commands::Base

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

Direct Known Subclasses

Finish, Info, Pick

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Base.



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

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.



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



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

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

#put(string, newline = true) ⇒ Object



19
20
21
# File 'lib/commands/base.rb', line 19

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

#run!Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/commands/base.rb', line 33

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



23
24
25
26
# File 'lib/commands/base.rb', line 23

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