Class: Webgen::CLI::ApplyCommand

Inherits:
CmdParse::Command
  • Object
show all
Defined in:
lib/webgen/cli/apply_command.rb

Overview

The CLI command for applying a style to a webgen website.

Instance Method Summary collapse

Constructor Details

#initializeApplyCommand

:nodoc:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/webgen/cli/apply_command.rb', line 11

def initialize #:nodoc:
  super('apply', false)
  @force = false

  self.short_desc = 'Apply a website style to an existing webgen website'
  self.options = CmdParse::OptionParserWrapper.new do |opts|
    opts.separator "Options:"
    opts.on('-f', '--[no-]force', 'Specifies whether files should be overwritten (default: no)') do |val|
      @force = val
    end
    opts.separator ""
    opts.separator "Arguments:"
    opts.separator opts.summary_indent + "STYLE: the style the should be applied to the website"
  end
end

Instance Method Details

#execute(args) ⇒ Object

Apply the style specified in args[0] to the webgen website.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/webgen/cli/apply_command.rb', line 42

def execute(args)
  wm = Webgen::WebsiteManager.new(commandparser.directory)
  if !File.directory?(commandparser.directory)
    puts "You need to specify a valid webgen website directory!"
  elsif args.length == 0
    raise OptionParser::MissingArgument.new('STYLE')
  elsif !wm.styles.has_key?(args[0])
    raise OptionParser::InvalidArgument.new("#{args[0]} is not a valid style")
  else
    puts "The following files in the website directory will be created or overwritten:"
    puts wm.styles[args[0]].paths.to_a.sort.join("\n")
    continue = @force
    if !continue
      print "Procede? (yes/no): "
      continue = ($stdin.readline =~ /y(es)?/)
    end
    wm.apply_style(args[0]) if continue
  end
end

#show_helpObject

:nodoc:



31
32
33
34
35
36
37
38
39
# File 'lib/webgen/cli/apply_command.rb', line 31

def show_help # :nodoc:
  super
  wm = Webgen::WebsiteManager.new(commandparser.directory)

  puts
  puts "Available styles:"
  puts Utils.headline('Styles')
  wm.styles.sort.each {|name, entry| Utils.hash_output(name, entry.instance_eval { @table }) }
end

#usageObject

:nodoc:



27
28
29
# File 'lib/webgen/cli/apply_command.rb', line 27

def usage # :nodoc:
  "Usage: #{commandparser.program_name} [global options] apply [options] STYLE"
end