Class: Tracker::Cli::Command::List

Inherits:
Object
  • Object
show all
Defined in:
lib/tracker/cli/command/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli:, object_type:, **arguments) ⇒ List

Returns a new instance of List.



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

def initialize(cli: , object_type: , **arguments)
  @cli = cli
  @arguments = arguments
  
  case object_type
  when 'stories' then list_stories
  when 'projects' then list_projects
  end
    
  case arguments[:format_name]
  when 'json'
    print JSON.dump(objects)
  else
    print_objects
  end
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



5
6
7
# File 'lib/tracker/cli/command/list.rb', line 5

def arguments
  @arguments
end

#cliObject (readonly)

Returns the value of attribute cli.



5
6
7
# File 'lib/tracker/cli/command/list.rb', line 5

def cli
  @cli
end

#columnsObject (readonly)

Returns the value of attribute columns.



5
6
7
# File 'lib/tracker/cli/command/list.rb', line 5

def columns
  @columns
end

#objectsObject (readonly)

Returns the value of attribute objects.



5
6
7
# File 'lib/tracker/cli/command/list.rb', line 5

def objects
  @objects
end

Instance Method Details

#list_projectsObject



30
31
32
33
# File 'lib/tracker/cli/command/list.rb', line 30

def list_projects
  @objects = cli.connection.get('projects').body
  @columns = [ 'id', 'name' ]
end

#list_storiesObject



24
25
26
27
28
# File 'lib/tracker/cli/command/list.rb', line 24

def list_stories
  query_params = arguments.fetch(:query_params, {})
  @objects = cli.connection.fetch_stories(project: Tracker.project, query: query_params)
  @columns = [ 'id', 'name', 'current_state', 'story_type' ]
end


35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tracker/cli/command/list.rb', line 35

def print_objects
  objects.each do |object|
    row = object.map do |(k, v)|
      if columns.include?(k)
        k == 'name' ? v.to_json : v
      end
    end.compact
    
    print row.join("\t")
    print "\n"
  end
end