class RunLater::CLI
Public Instance Methods
clean()
click to toggle source
# File lib/run_later.rb, line 154 def clean `rm -rf #{defaults[:root]}` end
list()
click to toggle source
# File lib/run_later.rb, line 159 def list initialize_files! say get_commands end
perform()
click to toggle source
# File lib/run_later.rb, line 103 def perform initialize_files! say "Empty", :green and return if get_commands.empty? log = defaults[:log] IO.popen("/bin/bash", "w") do |shell| shell.puts("echo #{Time.now} >> #{log}") get_commands.map{ |command| line = '--------------------------' say "#{line} Starting: #{Time.now} #{line}", :yellow say_status "ID", command[:id] # load preloads command[:preload].each {|source| say_status "Loading:", source # shell.puts("source #{source}") system("source #{source}") } # load env command[:env].each {|key, value| env = "#{key}=#{value}" say_status "Setting ENV", env system("export #{env}") # shell.puts("source #{source}") } unless command[:env].nil? say_status "Running", command[:commands], :yellow # shell.puts("sudo #{command[:commands]} >> #{log}") success = system("#{command[:commands]} >> #{log}") say_status 'Status', (success ? "🍺" : "😩" ), (success ? :green : :red) } say_status "Output saved", log, :green end end
queue()
click to toggle source
# File lib/run_later.rb, line 88 def queue initialize_files! commands = get_commands commands << options.merge({ id: Time.now.to_i }) say "Adding `#{options[:commands]}`", :green open(defaults[:commands], 'w') do |f| f.write commands.to_yaml end end
Private Instance Methods
commands_exist?()
click to toggle source
# File lib/run_later.rb, line 182 def commands_exist? File.exist? defaults[:commands] end
defaults()
click to toggle source
# File lib/run_later.rb, line 166 def defaults root = File.join(ENV['HOME'], '.run_later') env = '/usr/bin/env' set = 'set' { root: root, commands: File.join(root, 'commands.yaml'), log: File.join(root, "run_later.log") } end
get_commands()
click to toggle source
# File lib/run_later.rb, line 178 def get_commands YAML::load_file defaults[:commands] end
initialize_files!()
click to toggle source
# File lib/run_later.rb, line 186 def initialize_files! FileUtils.mkdir_p(defaults[:root]) unless File.directory? defaults[:root] File.open(defaults[:commands], "w") do |file| file.write [].to_yaml end unless commands_exist? end