class StaticFM::CommandLine

Public Class Methods

new(args) click to toggle source
# File lib/static_fm/command_line.rb, line 8
def initialize(args)
  parser.parse!(args) # remove switches destructively
  @args = args
end

Public Instance Methods

default_options() click to toggle source
# File lib/static_fm/command_line.rb, line 17
def default_options
  {
    :compressed => false
  }
end
execute() click to toggle source
# File lib/static_fm/command_line.rb, line 27
def execute
  case method
  when :install
    install @args[1], @args[2]
  when :list
    list
  else
    parser.help
  end
end
install(asset_name, destination) click to toggle source
# File lib/static_fm/command_line.rb, line 38
def install(asset_name, destination)
  Installer.download(asset_name, destination, default_options.merge(options))
end
list() click to toggle source
# File lib/static_fm/command_line.rb, line 42
def list
  Asset.recipe_names.join("\n")
end
method() click to toggle source
# File lib/static_fm/command_line.rb, line 23
def method
  @args.any? && @args[0].to_sym
end
options() click to toggle source
# File lib/static_fm/command_line.rb, line 13
def options
  @options ||= {}
end
parser() click to toggle source
# File lib/static_fm/command_line.rb, line 46
def parser
  @parser ||= OptionParser.new do |opts|
    opts.banner = "Usage: static [options] COMMAND"

    opts.separator ""
    opts.separator "Options:"

    opts.on("-c", "--compressed", "Retrieve compressed version") do |host|
      options[:compressed] = true
    end

    opts.separator ""
    opts.separator "Commands:"
    opts.separator "  install ASSET DEST  Downloads asset to destination"
    opts.separator "  list                Lists available download recipes"
  end
end