lib/get_happy/cli.rb in get_happy-0.0.1 vs lib/get_happy/cli.rb in get_happy-1.0.0
- old
+ new
@@ -1,17 +1,20 @@
module GetHappy
class CLI < Thor
+ include Thor::Actions
+ CAPTURE_COMMANDS_OUTPUT = !ENV['GH_CAPTURE_COMMANDS_OUTPUT'].nil?
+
desc "play", "play a random song"
def play
@collection ||= GetHappy.get_collection
- system("open", @collection.sample) unless @collection.empty?
- puts "Collection is empty! get_happy seed to seed" if @collection.empty?
+ run("open #{@collection.sample}", :capture => CAPTURE_COMMANDS_OUTPUT) unless @collection.empty?
+ say "Collection is empty! get_happy seed to seed" if @collection.empty?
end
-
- desc "add [LINKS]", "add a link to collection"
+
+ desc "add [LINKS]", "add a link to collection"
def add(*links)
@collection ||= GetHappy.get_collection
links.each {|link| @collection << link.to_s}
GetHappy.write_collection(@collection)
list
@@ -20,24 +23,23 @@
desc "list", "list collection"
def list
@collection ||= GetHappy.get_collection
user = `echo $USER`.gsub("\n", "")
- puts " \n"
- puts "\e[1m\e[4m#{user} Total #{@collection.size}\e[0m \n"
- # puts @collection.join("\n")
+ say " \n"
+ say "\e[1m\e[4m#{user} Total #{@collection.size}\e[0m \n\n"
@collection.each do |item|
- puts "\e[92m🚀 #{item}"
+ say "🚀 #{item}" , :green
end
- puts "\e[0m\n"
+ say "\n"
end
desc "clean", "clean collection"
def clean
@collection = []
GetHappy.write_collection([])
- puts "Collection is empty"
+ say "Collection is empty"
end
desc "seed", "seed with some sample urls"
def seed
GetHappy.seed
@@ -52,6 +54,9 @@
GetHappy.write_collection(@collection)
list
end
end
-end
\ No newline at end of file
+end
+
+
+