Class: Tracker::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/tracker/cli.rb,
lib/tracker/cli/view.rb,
lib/tracker/cli/command.rb,
lib/tracker/cli/version.rb,
lib/tracker/cli/view/input.rb,
lib/tracker/cli/view/select.rb,
lib/tracker/cli/command/list.rb,
lib/tracker/cli/view/confirm.rb,
lib/tracker/cli/command/fetch.rb,
lib/tracker/cli/command/create.rb,
lib/tracker/cli/command/destroy.rb

Defined Under Namespace

Modules: Command, View

Constant Summary collapse

VERSION =
"0.1.1"

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Cli

Returns a new instance of Cli.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tracker/cli.rb', line 6

def initialize(argv)
  validate_configuration!
  
  arguments = OptionParser.parse!(argv)
  arguments[:cli] = self
  
  case arguments[:method]
  when :list then Command::List.new(**arguments)
  when :fetch then Command::Fetch.new(**arguments)
  when :create then Command::Create.new(**arguments)
  when :destroy then Command::Destroy.new(**arguments)
  when :request
    case arguments[:request_method]
    when :get
      print connection.get(arguments[:url]).body.to_json
    end
  end
end

Instance Method Details

#connectionObject



25
26
27
# File 'lib/tracker/cli.rb', line 25

def connection
  @connection ||= Client.new(Tracker.api_token)
end

#validate_configuration!Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/tracker/cli.rb', line 29

def validate_configuration!
  if Tracker.api_token.nil?
    error = "API Token missing. Find yours at https://www.pivotaltracker.com/profile and add: \n\napi_token: {{YOUR_TOKEN}}\n\n to ~/.tracker.config"
  end
  
  if Tracker.project.nil?
    error = "Project id is missing. Find the id in the url for the project and add: \n\nproject: {{YOUR_PROJECT_ID}}\n\n to ~/.tracker.config"
  end
  
  if error
    raise ArgumentError, error
  end
end