Class: DK::CLI
- Includes:
- CliHelpers
- Defined in:
- lib/draftking/cli.rb,
lib/draftking/cli/commands/tag.rb,
lib/draftking/cli/commands/blogs.rb,
lib/draftking/cli/commands/strip.rb,
lib/draftking/cli/commands/status.rb,
lib/draftking/cli/commands/comment.rb,
lib/draftking/cli/commands/console.rb,
lib/draftking/cli/commands/uploads.rb,
lib/draftking/cli/commands/accounts.rb,
lib/draftking/cli/commands/_template.rb,
lib/draftking/cli/commands/autoposter.rb,
lib/draftking/cli/commands/movedrafts.rb
Overview
Command Line Interface
Constant Summary
Constants included from CliHelpers
Class Method Summary collapse
-
.launch_console ⇒ Object
Launch IRB with tumblr_draftking loaded as $dk.
Instance Method Summary collapse
- #accounts ⇒ Object
- #autoposter ⇒ Object
- #blogs ⇒ Object
- #check_for_updates ⇒ Object
- #comment(comm) ⇒ Object
- #console ⇒ Object
- #custom ⇒ Object
-
#method_missing(method, *_args) ⇒ Object
Try to execute unrecognized command as User Command.
- #movedrafts ⇒ Object
- #setup ⇒ Object
- #status(blog = nil) ⇒ Object
- #strip ⇒ Object
- #tag ⇒ Object
- #uploads ⇒ Object
- #version ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *_args) ⇒ Object
Try to execute unrecognized command as User Command
48 49 50 51 52 53 |
# File 'lib/draftking/cli.rb', line 48 def method_missing(method, *_args) name, attribs = DK::Config.new.user_commands.select { |k, _v| k == method.to_s }.first puts "Command '#{method}' not found." && return unless name && attribs attribs[:name] = name DK::UserCommand.new(attribs).exec! end |
Class Method Details
Instance Method Details
#accounts ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/draftking/cli/commands/accounts.rb', line 7 def accounts files = DK::Config.available_configs show_accounts(files) return if .empty? # Empty = no action to take puts accounts_input_dialogue() opts = () choice = config_to_num(opts[:config]) || DK::Config.get_input return if /[^0-9]/ =~ choice file = files[choice.to_i] return if file.nil? msg = accounts_action(file, opts) show_accounts(DK::Config.available_configs, msg) end |
#autoposter ⇒ Object
26 27 28 29 30 31 |
# File 'lib/draftking/cli/commands/autoposter.rb', line 26 def autoposter configured? opts = () dk = get_dk_instance(opts) dk.auto_poster(opts) end |
#blogs ⇒ Object
6 7 8 9 |
# File 'lib/draftking/cli/commands/blogs.rb', line 6 def blogs configured? self.class.blogs_print_list(get_dk_instance(())) end |
#check_for_updates ⇒ Object
40 41 42 43 44 |
# File 'lib/draftking/cli.rb', line 40 def check_for_updates versions = open('https://rubygems.org/api/v1/versions/tumblr_draftking.json').read latest = JSON.parse(versions, object_class: OpenStruct).first.number puts "\n* UPDATE *\n\tDraftKing for Tumblr v#{latest} now available!\n\n" if latest != DK::VERSION end |
#comment(comm) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/draftking/cli/commands/comment.rb', line 27 def comment(comm) configured? opts = () opts[:comment] = comm dk = get_dk_instance(opts) dk.comment_posts(opts) end |
#console ⇒ Object
4 5 6 7 |
# File 'lib/draftking/cli/commands/console.rb', line 4 def console configured? self.class.launch_console end |
#custom ⇒ Object
57 58 59 60 61 62 |
# File 'lib/draftking/cli.rb', line 57 def custom title = 'User Commands' commands = DK::Config.new.config.user_commands.map { |n, d| UserCommand.new d.merge(name: n) } headers = %w(name command description config_name) Reporter.new(title: title, objects: commands, fields: headers).show end |
#movedrafts ⇒ Object
27 28 29 30 31 32 |
# File 'lib/draftking/cli/commands/movedrafts.rb', line 27 def movedrafts configured? opts = () dk = get_dk_instance(opts) dk.drafts_to_queue(opts) end |
#status(blog = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/draftking/cli/commands/status.rb', line 5 def status(blog = nil) configured? title = 'Status Report' fields = %w(Blog Drafts Queued Q.Space) opts = (.dup.merge(blog: blog)) dk = get_dk_instance(opts) rows = build_rows(dk) report = Reporter.new(title: title, rows: rows, headers: fields) report.show unless dk.simulate report end |
#strip ⇒ Object
13 14 15 16 17 18 |
# File 'lib/draftking/cli/commands/strip.rb', line 13 def strip configured? opts = () dk = get_dk_instance(opts) dk.strip_old_comments(opts) end |
#tag ⇒ Object
16 17 18 19 20 |
# File 'lib/draftking/cli/commands/tag.rb', line 16 def tag opts = () dk = get_dk_instance(opts) dk.tag_posts(opts) end |
#uploads ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/draftking/cli/commands/uploads.rb', line 38 def uploads configured? opts = () dk = get_dk_instance(opts) dfile = opts[:file].chomp.strip File.open(dfile, 'r') do |data_file| mod = 0 rows = [] = '' row = Struct.new(:count, :line, :file, :caption, :status) title = ups_title(dfile, dk) data_file.each_line.with_index do |line, idx| line = line.chomp.strip next if line.empty? || is_commented?(line) ( = nil) || next if is_url_group?(line) ( = line) && next if (line, ) ups_progress(mod, ) unless dk.mute post_opts = ups_opts(line, , dk, opts) status = ups_photo_draft(dk, post_opts) rows << row.new(mod += 1, idx + 1, File.basename(line), , status) end # each_line ups_report(title, dk, rows) end # of data_file end |