8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/rawfeed/post.rb', line 8
def self.post
drafts = Dir.glob(File.join(Rawfeed::CONFIG['DRAFTS_DIR'], "*.#{Rawfeed::CONFIG['markdown_extension']}"))
if drafts.empty?
puts "No files found in #{DRAFTS_DIR}".yellow
return
end
puts "Select the file to move:\n".cyan
drafts.each_with_index do |file, index|
puts "#{index + 1} - #{File.basename(file)}"
end
puts "#{drafts.size + 1} - move all"
puts "#{drafts.size + 2} - cancel"
print "\nEnter option number: ".cyan
trap("INT") do
puts "\n[!] Operation canceled by user (Ctrl+C).".yellow
exit!
end
choice = STDIN.gets.strip.to_i
if choice == drafts.size + 1
drafts.each { |file| move_file(file) }
puts "\n[*] All drafts have been moved to #{Rawfeed::CONFIG['POSTS_DIR']}".green
elsif choice == drafts.size + 2
puts "\n[!] Operation canceled by user.".yellow
exit!
elsif choice.between?(1, drafts.size)
move_file(drafts[choice - 1])
else
puts "\n[x] Invalid option.".red
end
end
|