Class: Webgen::CLI::CreateCommand
- Inherits:
-
CmdParse::Command
- Object
- CmdParse::Command
- Webgen::CLI::CreateCommand
- Defined in:
- lib/webgen/cli/create_command.rb
Overview
The CLI command for creating a webgen website.
Instance Method Summary collapse
-
#execute(args) ⇒ Object
Create a webgen website in the directory
args[0]
. -
#initialize ⇒ CreateCommand
constructor
:nodoc:.
-
#show_help ⇒ Object
:nodoc:.
-
#usage ⇒ Object
:nodoc:.
Constructor Details
#initialize ⇒ CreateCommand
: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.") @template = 'default' @style = 'andreas07' self.short_desc = 'Create a basic webgen website with selectable template/style' self. = CmdParse::OptionParserWrapper.new do |opts| opts.separator "Options:" opts.on('-t', '--template TEMPLATE', String, 'A website template or "none" (default: default)') do |val| @template = (val == 'none' ? nil : val) end opts.on('-s', '--style STYLE', String, 'A website style or "none" (default: andreas07)') do |val| @style = (val == 'none' ? nil : val) 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]
.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/webgen/cli/create_command.rb', line 49 def execute(args) if args.length == 0 raise OptionParser::MissingArgument.new('DIR') else wm = Webgen::WebsiteManager.new(args[0]) paths = wm.create_website paths += wm.apply_template(@template) if @template paths += wm.apply_style(@style) if @style if commandparser.verbosity == :verbose puts "The following files were created in the directory #{args[0]}:" puts paths.sort.collect {|f| "- " + f }.join("\n") end end end |
#show_help ⇒ Object
:nodoc:
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/webgen/cli/create_command.rb', line 36 def show_help # :nodoc: super wm = Webgen::WebsiteManager.new(commandparser.directory) puts puts "Available templates and styles:" puts Utils.headline('Templates') wm.templates.sort.each {|name, entry| Utils.hash_output(name, entry.instance_eval { @table }) } puts Utils.headline('Styles') wm.styles.select {|k,v| k =~ /^website-|[^-]+/ }.sort.each {|name, entry| Utils.hash_output(name, entry.instance_eval { @table }) } end |
#usage ⇒ Object
: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 |