Class: Webgen::CLI::ApplyCommand
- Inherits:
-
CmdParse::Command
- Object
- CmdParse::Command
- Webgen::CLI::ApplyCommand
- Defined in:
- lib/webgen/cli/apply_command.rb
Overview
The CLI command for applying a bundle to a webgen website.
Instance Method Summary collapse
-
#execute(args) ⇒ Object
Apply the style specified in
args[0]
to the webgen website. -
#initialize ⇒ ApplyCommand
constructor
:nodoc:.
-
#show_help ⇒ Object
:nodoc:.
-
#usage ⇒ Object
:nodoc:.
Constructor Details
#initialize ⇒ ApplyCommand
:nodoc:
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/webgen/cli/apply_command.rb', line 11 def initialize #:nodoc: super('apply', false) @force = false self.short_desc = 'Apply a website bundle to an existing webgen website' self. = 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 + "BUNDLE_NAME: The name of a bundle shipped with webgen. The name is " opts.separator opts.summary_indent + " matched against all possible bundle names and if there is only " opts.separator opts.summary_indent + " match the bundle is applied." opts.separator opts.summary_indent + "BUNDLE_URL: The URL of a bundle (needs to be a tar archive" end end |
Instance Method Details
#execute(args) ⇒ Object
Apply the style specified in args[0]
to the webgen website.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/webgen/cli/apply_command.rb', line 45 def execute(args) wm = Webgen::WebsiteManager.new(commandparser.directory) if !File.directory?(wm.website.directory) raise "You need to specify a valid webgen website directory!" elsif args.length == 0 raise OptionParser::MissingArgument.new('STYLE') else name = Utils.match_bundle_name(wm, args[0]) puts "The following files in the website directory will be created or overwritten:" puts wm.bundles[name].paths.sort.join("\n") continue = @force if !continue print "Procede? (yes/no): " continue = ($stdin.readline =~ /y(es)?/) end wm.apply_bundle(name) if continue end end |
#show_help ⇒ Object
:nodoc:
34 35 36 37 38 39 40 41 42 |
# File 'lib/webgen/cli/apply_command.rb', line 34 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 |
#usage ⇒ Object
:nodoc:
30 31 32 |
# File 'lib/webgen/cli/apply_command.rb', line 30 def usage # :nodoc: "Usage: #{commandparser.program_name} [global options] apply [options] (BUNDLE_NAME|BUNDLE_URL)" end |