Class: Webgen::CLI::CreateCommand

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

Overview

The CLI command for creating a webgen website.

Instance Method Summary collapse

Constructor Details

#initializeCreateCommand

:nodoc:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/webgen/cli/create_command.rb', line 11

def initialize #:nodoc:
  super('create', false)
  self.description = Utils.format("If the verbosity level is set to verbose, the created files are listed.")
  @bundles = []

  self.short_desc = 'Create a basic webgen website from website bundles'
  self.options = CmdParse::OptionParserWrapper.new do |opts|
    opts.separator "Options:"
    opts.on('-b', '--bundle BUNDLE', String, "A website bundle name/URL or 'none'. Can be used more than once (default: [default, style-andreas07])") do |val|
      if val.downcase == 'none'
        @bundles = nil
      elsif !@bundles.nil?
        @bundles << val
      end
    end
    opts.separator ""
    opts.separator "Arguments:"
    opts.separator opts.summary_indent + "DIR: the directory in which the website should be created"
  end
end

Instance Method Details

#execute(args) ⇒ Object

Create a webgen website in the directory args[0].



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/webgen/cli/create_command.rb', line 47

def execute(args)
  if args.length == 0
    raise OptionParser::MissingArgument.new('DIR')
  else
    wm = Webgen::WebsiteManager.new(args[0])
    paths = wm.create_website
    begin
      if @bundles
        @bundles = ['default', 'style-andreas07'] if @bundles.empty?
        @bundles.each {|name| paths += wm.apply_bundle(Utils.match_bundle_name(wm, name)) }
      end
    rescue
      require 'fileutils'
      FileUtils.rm_rf(args[0])
      raise
    end
    if commandparser.verbosity == :verbose
      puts "The following files were created in the directory #{args[0]}:"
      puts paths.sort.join("\n")
    end
  end
end

#show_helpObject

:nodoc:



36
37
38
39
40
41
42
43
44
# File 'lib/webgen/cli/create_command.rb', line 36

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

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

#usageObject

:nodoc:



32
33
34
# File 'lib/webgen/cli/create_command.rb', line 32

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