Class: DiscourseCli::Commands::Categories

Inherits:
Base
  • Object
show all
Defined in:
lib/discourse_cli/commands/categories.rb

Instance Method Summary collapse

Methods inherited from Base

exit_on_failure?

Instance Method Details

#createObject



25
26
27
28
29
30
31
32
33
# File 'lib/discourse_cli/commands/categories.rb', line 25

def create
  params = { name: options[:name] }
  params[:color]       = options[:color]          if options[:color]
  params[:text_color]  = options[:"text-color"]   if options[:"text-color"]
  params[:description] = options[:description]    if options[:description]
  formatter.print_item(client.create_category(params))
rescue DiscourseApi::DiscourseError => e
  handle_error(e)
end

#delete(id) ⇒ Object



53
54
55
56
57
58
# File 'lib/discourse_cli/commands/categories.rb', line 53

def delete(id)
  client.delete_category(id.to_i)
  formatter.print_success("Deleted category #{id}")
rescue DiscourseApi::DiscourseError => e
  handle_error(e)
end

#listObject



7
8
9
10
11
# File 'lib/discourse_cli/commands/categories.rb', line 7

def list
  formatter.print_list(client.categories)
rescue DiscourseApi::DiscourseError => e
  handle_error(e)
end

#show(id) ⇒ Object



14
15
16
17
18
# File 'lib/discourse_cli/commands/categories.rb', line 14

def show(id)
  formatter.print_item(client.category(id.to_i))
rescue DiscourseApi::DiscourseError => e
  handle_error(e)
end

#update(id) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/discourse_cli/commands/categories.rb', line 40

def update(id)
  params = { id: id.to_i, name: options[:name] }
  params[:color]       = options[:color]          if options[:color]
  params[:text_color]  = options[:"text-color"]   if options[:"text-color"]
  params[:description] = options[:description]    if options[:description]
  result = client.update_category(params)
  formatter.print_item(result) if result
  formatter.print_success("Updated category #{id}")
rescue DiscourseApi::DiscourseError => e
  handle_error(e)
end