Class: Furaffinity::CliQueue

Inherits:
Thor
  • Object
show all
Includes:
CliBase
Defined in:
lib/furaffinity/cli_queue.rb

Instance Method Summary collapse

Methods included from CliBase

included

Instance Method Details

#add(*files) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/furaffinity/cli_queue.rb', line 19

def add(*files)
  if files.empty?
    say "You need to pass a file.", :red
    help :add
    exit 1
  end

  queue.reload

  files_added = queue.add(*files)
  files_added.each do |file|
    say "added #{file.inspect}", :green
  end
rescue Furaffinity::Error => e
  say e.message, :red
  exit 1
end

#cleanObject



57
58
59
60
61
62
63
64
# File 'lib/furaffinity/cli_queue.rb', line 57

def clean
  queue.reload
  queue.clean
  say "Removed uploaded files", :green
rescue Furaffinity::Error => e
  say e.message, :red
  exit 1
end

#init(dir = Dir.pwd) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/furaffinity/cli_queue.rb', line 10

def init(dir = Dir.pwd)
  result = queue(dir).init
  say "Created new queue dir in #{result.inspect}", :green
rescue Furaffinity::Error => e
  say e.message, :red
  exit 1
end

#remove(*files) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/furaffinity/cli_queue.rb', line 38

def remove(*files)
  if files.empty?
    say "You need to pass a file.", :red
    help :remove
    exit 1
  end

  queue.reload

  files_removed = queue.remove(*files)
  files_removed.each do |file|
    say "removed #{file.inspect}", :green
  end
rescue Furaffinity::Error => e
  say e.message, :red
  exit 1
end

#reorderObject



67
68
69
70
71
72
# File 'lib/furaffinity/cli_queue.rb', line 67

def reorder
  queue.reload
  queue.reorder unless queue.queue.empty?

  invoke :status
end

#statusObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/furaffinity/cli_queue.rb', line 75

def status
  queue.reload

  if queue.queue.empty?
    say "Nothing is in the queue yet, use `#{File.basename $0} queue add ...` to add files.", :yellow

    print_uploaded_files
    return
  end

  say "Enqueued files:"
  queue_table = [["Position", "File name", "Title", "Rating"], :separator]
  queue.queue.each_with_index do |file_name, idx|
    file_info = queue.file_info.fetch(file_name)
    queue_table << [idx + 1, file_name, file_info[:title], file_info[:rating]]
  end
  print_table queue_table, borders: true

  print_uploaded_files

rescue Furaffinity::Error => e
  say e.message, :red
  exit 1
end

#uploadObject



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/furaffinity/cli_queue.rb', line 102

def upload
  if options[:wait_time] < 30
    say "--wait-time must be at least 30", :red
    exit 1
  end

  queue.reload
  queue.upload(options[:wait_time])
  say "Submissions uploaded.", :green
rescue Furaffinity::Error => e
  say e.message, :red
  exit 1
end