Class: Backlog::Cli::Commands

Inherits:
Thor
  • Object
show all
Defined in:
lib/backlog/cli/commands.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ Commands

Returns a new instance of Commands.



21
22
23
24
25
# File 'lib/backlog/cli/commands.rb', line 21

def initialize(args = [], options = {}, config = {})
  super(args, options, config)
  profile = config[:shell].base.options['profile']
  @core = Backlog::Cli::Core.new(profile)
end

Instance Method Details

#create_issue(project_key) ⇒ Object



31
32
33
# File 'lib/backlog/cli/commands.rb', line 31

def create_issue(project_key)
  puts JSON.pretty_generate(@core.create_issue(project_key.upcase, options))
end

#create_issue_by_fileObject



113
114
115
116
117
# File 'lib/backlog/cli/commands.rb', line 113

def create_issue_by_file
  yaml = load_yaml
  project_key = yaml.delete(:project_key)
  @core.create_issue(project_key, yaml)
end

#find_issue(project_key) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/backlog/cli/commands.rb', line 68

def find_issue(project_key)
  results = @core.find_issue(project_key.upcase, options)
  selected = results.map do |result|
    result.select { |k, v| %w(id url key summary description).include? k }
  end
  puts JSON.pretty_generate(selected.reverse)
end

#get_commentsObject



37
38
39
# File 'lib/backlog/cli/commands.rb', line 37

def get_comments
  puts JSON.pretty_generate(@core.get_comments(options))
end

#get_issueObject



50
51
52
53
# File 'lib/backlog/cli/commands.rb', line 50

def get_issue
  result = @core.get_issue(options)
  puts JSON.pretty_generate(result)
end

#get_project_summariesObject



101
102
103
104
# File 'lib/backlog/cli/commands.rb', line 101

def get_project_summaries
  results = @core.get_project_summaries
  puts JSON.pretty_generate(results)
end

#get_projectsObject



95
96
97
98
# File 'lib/backlog/cli/commands.rb', line 95

def get_projects
  results = @core.get_projects
  puts JSON.pretty_generate(results)
end

#get_users(project_key) ⇒ Object



107
108
109
110
# File 'lib/backlog/cli/commands.rb', line 107

def get_users(project_key)
  results = @core.get_users(project_key.upcase)
  puts JSON.pretty_generate(results)
end

#list(project_key) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/backlog/cli/commands.rb', line 78

def list(project_key)
  items = @core.get_rss(project_key.upcase).slice(0, options[:limit])
  results = []
  items.each do |item|
    result = {}
    result[:title] = item.title
    result[:content] = item.content
    result[:authors] = item.authors.first
    result[:date_published] = item.date_published
    result[:url] = item.id
    result[:urls] = @core.urls(item.content)
    results << result
  end
  puts JSON.pretty_generate(results.reverse)
end

#openObject



57
58
59
60
# File 'lib/backlog/cli/commands.rb', line 57

def open
  result = @core.get_issue(options)
  `open #{result['url']}`
end

#update_issueObject



44
45
46
# File 'lib/backlog/cli/commands.rb', line 44

def update_issue
  puts JSON.pretty_generate(@core.update_issue(options))
end

#update_issue_by_fileObject



120
121
122
# File 'lib/backlog/cli/commands.rb', line 120

def update_issue_by_file
  @core.update_issue(load_yaml)
end

#versionObject



125
126
127
# File 'lib/backlog/cli/commands.rb', line 125

def version
  puts Backlog::Cli::VERSION
end