Class: StaticFM::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/static_fm/command_line.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CommandLine

Returns a new instance of CommandLine.



8
9
10
11
# File 'lib/static_fm/command_line.rb', line 8

def initialize(args)
  parser.parse!(args) # remove switches destructively
  @args = args
end

Instance Method Details

#default_optionsObject



17
18
19
20
21
# File 'lib/static_fm/command_line.rb', line 17

def default_options
  {
    :compressed => false
  }
end

#executeObject



27
28
29
30
31
32
33
34
35
36
# 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) ⇒ Object



38
39
40
# File 'lib/static_fm/command_line.rb', line 38

def install(asset_name, destination)
  Installer.download(asset_name, destination, default_options.merge(options))
end

#listObject



42
43
44
# File 'lib/static_fm/command_line.rb', line 42

def list
  Asset.recipe_names.join("\n")
end

#methodObject



23
24
25
# File 'lib/static_fm/command_line.rb', line 23

def method
  @args.any? && @args[0].to_sym
end

#optionsObject



13
14
15
# File 'lib/static_fm/command_line.rb', line 13

def options
  @options ||= {}
end

#parserObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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