Class: DiscourseCli::Commands::Topics
- Defined in:
- lib/discourse_cli/commands/topics.rb
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#create ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/discourse_cli/commands/topics.rb', line 28 def create raw = resolve_raw([:raw]) params = { title: [:title], raw: raw } params[:category] = [:category] if [:category] params[:tags] = [:tags].split(",").map(&:strip) if [:tags] formatter.print_item(client.create_topic(params)) rescue DiscourseApi::DiscourseError => e handle_error(e) end |
#delete(id) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/discourse_cli/commands/topics.rb', line 82 def delete(id) client.delete_topic(id.to_i) formatter.print_success("Deleted topic #{id}") rescue DiscourseApi::DiscourseError => e handle_error(e) end |
#list ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/discourse_cli/commands/topics.rb', line 8 def list params = {} params[:category] = [:category] if [:category] formatter.print_list(client.latest_topics(params)) rescue DiscourseApi::DiscourseError => e handle_error(e) end |
#show(id) ⇒ Object
17 18 19 20 21 |
# File 'lib/discourse_cli/commands/topics.rb', line 17 def show(id) formatter.print_item(client.topic(id.to_i)) rescue DiscourseApi::DiscourseError => e handle_error(e) end |
#update(id) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/discourse_cli/commands/topics.rb', line 42 def update(id) updated_anything = false if [:title] client.rename_topic(id.to_i, [:title]) updated_anything = true end if [:category] cats = client.categories cat = cats.find { |c| c["slug"] == [:category] || c["name"] == [:category] } unless cat $stderr.puts "Category not found: #{[:category]}" exit 1 end client.recategorize_topic(id.to_i, cat["id"]) updated_anything = true end raw = if [:raw] [:raw] elsif !updated_anything && !$stdin.tty? $stdin.read elsif !updated_anything Editor.new.open end if raw topic_data = client.topic(id.to_i) first_post_id = topic_data["post_stream"]["posts"][0]["id"] client.edit_post(first_post_id, raw) end formatter.print_success("Updated topic #{id}") rescue DiscourseApi::DiscourseError => e handle_error(e) end |