Class: DK::CLI

Inherits:
Thor
  • Object
show all
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/accounts.rb,
lib/draftking/cli/commands/_template.rb,
lib/draftking/cli/commands/movedrafts.rb

Overview

Command Line Interface

Constant Summary

Constants included from CliHelpers

DK::CliHelpers::VALID_OPTS

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.launch_consoleObject

Launch IRB with tumblr_draftking loaded as $dk



10
11
12
13
14
15
16
# File 'lib/draftking/cli/commands/console.rb', line 10

def self.launch_console
  require 'irb'
  require 'irb/completion'
  ARGV.clear
  $dk = DK::Client.new simulate: true
  IRB.start
end

.status_print(blog, simulate = false) ⇒ Object

Print blog status



15
16
17
18
19
20
21
22
# File 'lib/draftking/cli/commands/status.rb', line 15

def self.status_print(blog, simulate = false)
  res  = "\n#------ #{blog.name} ------#"
  res += "\nDrafts      : #{blog.drafts}"
  res += "\nQueued      : #{blog.queue}"
  res += "\nQueue space : #{301 - blog.queue.to_i}\n\n"
  puts res unless simulate
  res
end

Instance Method Details

#accountsObject



6
7
8
9
10
11
12
13
14
15
# File 'lib/draftking/cli/commands/accounts.rb', line 6

def accounts
  files = DK::Config.available_configs
  show_accounts(files)
  return if options.empty? # Empty = no action to take
  puts accounts_input_dialogue(options)
  choice = DK::Config.get_input
  return if /[^0-9]/ =~ choice
  file = files[choice.to_i]
  accounts_action(file, options)
end

#blogsObject



5
6
7
8
# File 'lib/draftking/cli/commands/blogs.rb', line 5

def blogs
  configured?
  self.class.blogs_print_list(get_dk_instance(options))
end

#comment(comm) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/draftking/cli/commands/comment.rb', line 24

def comment(comm)
  configured?
  opts = process_options(options)
  opts[:comment] = comm
  dk = get_dk_instance(opts)
  dk.comment_posts(opts)
end

#consoleObject



4
5
6
7
# File 'lib/draftking/cli/commands/console.rb', line 4

def console
  configured?
  self.class.launch_console
end

#movedraftsObject



23
24
25
26
27
28
29
30
# File 'lib/draftking/cli/commands/movedrafts.rb', line 23

def movedrafts
  configured?
  opts = process_options(options)
  dk = get_dk_instance(opts)
  result = dk.drafts_to_queue(opts)
  self.class.status_print(dk.blog, dk.simulate)
  result
end

#setupObject



21
22
23
# File 'lib/draftking/cli.rb', line 21

def setup
  DK::Config.setup
end

#status(blog = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/draftking/cli/commands/status.rb', line 4

def status(blog = nil)
  configured?
  opts = process_options(options.dup.merge(blog: blog))
  dk = get_dk_instance(opts)
  dk.user.blogs.map do |b|
    next unless blog.nil? || b.name == blog
    self.class.status_print(b, dk.simulate)
  end
end

#stripObject



11
12
13
14
15
16
# File 'lib/draftking/cli/commands/strip.rb', line 11

def strip
  configured?
  opts = process_options(options)
  dk = get_dk_instance(opts)
  dk.strip_old_comments(opts)
end

#tagObject



14
15
16
17
18
# File 'lib/draftking/cli/commands/tag.rb', line 14

def tag
  opts = process_options(options)
  dk = get_dk_instance(opts)
  dk.tag_posts(opts)
end

#versionObject



27
28
29
30
31
# File 'lib/draftking/cli.rb', line 27

def version
  vstr = "tumblr_draftking #{DK::VERSION}"
  puts vstr unless options[:simulate]
  vstr
end