class Aucast::Cli

Public Class Methods

exit_on_failure?() click to toggle source
# File lib/aucast/cli.rb, line 13
def self.exit_on_failure?
  true
end

Public Instance Methods

copy(*args) click to toggle source
# File lib/aucast/cli.rb, line 59
def copy(*args)
  destination_dir = options[:copy_to] || options[:destination]
  
  unless Dir.exist?(destination_dir)
    say("The dir used to copy file doesn't exist (#{destination_dir})", :red)
    return
  end
  
  args.each do |arg|
    if arg =~ URI::regexp
      youtube = YoutubeDl.new(arg)
      youtube.copy(destination_dir)
    else
      FileUtils.cp(arg, destination_dir)
    end
    
    say("Successfully copied #{arg}", :green)
  end
end
setup() click to toggle source
# File lib/aucast/cli.rb, line 18
def setup
  yaml = {
  }
  
  server_address = ask("Type your Aucast bonjour webserver name (leave blank if you don't want to use it): ")
  
  if server_address.length > 0
    yaml["address"] = server_address
  end
  
  copy_to_path = ask("Type your inbox dir (leave blank if you doesn't want to use it): ", path: true)
  
  if copy_to_path.length > 0
    yaml["copy_to"] = copy_to_path
  end
  
  if yaml.count == 0
    say("Exit, nothing to write.")
    return
  end
  
  file_path = File.join(Dir.home, "/#{CONFIG_FILENAME}")
  File.write(file_path, yaml.to_yaml)
end
upload(*args) click to toggle source
# File lib/aucast/cli.rb, line 45
def upload(*args)
  args.each do |arg|
    if arg =~ URI::regexp
      youtube = YoutubeDl.new(arg)
      upload_file(youtube)
    else
      file = FileUpload.new(arg)
      upload_file(file)
    end
  end
end
version() click to toggle source
# File lib/aucast/cli.rb, line 80
def version
  puts Aucast::VERSION
end

Private Instance Methods

options() click to toggle source
Calls superclass method
# File lib/aucast/cli.rb, line 105
def options
  original_options = super
  config_path = File.join(Dir.home, "/#{CONFIG_FILENAME}")
  return original_options unless ::File.file?(config_path)
  defaults = ::YAML::load_file(config_path) || {}
  Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
end
upload_file(uploadable) click to toggle source
# File lib/aucast/cli.rb, line 86
def upload_file(uploadable)
  endpoint = Endpoint.new("http://#{options[:address]}")
  
  say("Uploading...")
  
  begin
    ret = uploadable.upload(endpoint)
  rescue => e
    say(e.message, :red)
    return
  end
  
  if ret
    say("Successfully uploaded #{uploadable.filename}", :green)
  else
    say(ret, :red)
  end
end