Method: Webgen::CLI::CommandParser#initialize
- Defined in:
- lib/webgen/cli.rb
#initialize ⇒ CommandParser
Create a new CommandParser class.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/webgen/cli.rb', line 85 def initialize super(handle_exceptions: :no_help) @directory = nil @verbose = false @do_search = false @log_level = ::Logger::INFO @config_options = {} add_command(CmdParse::VersionCommand.new(add_switches: false)) add_command(CmdParse::HelpCommand.new) .program_name = "webgen" .version = Webgen::VERSION do |opts| opts.on("--directory DIR", "-d", String, "The website directory to use") do |d| @directory = d end opts.on("--search-dirs", "-s", "Search parent directories for website directory") do |s| @do_search = s end opts.on("--version", "-V", "Show webgen version information") do main_command.commands['version'].execute end end do |opts| opts.on("-c", "--[no-]color", "Colorize output (default: #{Webgen::CLI::Utils.use_colors ? "yes" : "no"})") do |a| Webgen::CLI::Utils.use_colors = a end opts.on("-v", "--[no-]verbose", "Verbose output (default: no)") do |v| @verbose = v update_logger(@website.logger) unless @website.nil? end opts.on("-q", "--[no-]quiet", "Quiet output (default: no)") do |v| @log_level = (v ? ::Logger::WARN : :Logger::INFO) update_logger(@website.logger) unless @website.nil? end opts.on("-n", "--[no-]dry-run", "Do a dry run, i.e. don't actually write anything (default: no)") do |v| @config_options['website.dry_run'] = v unless @website.nil? update_config(@website.config) update_logger(@website.logger) end end opts.on("-o", "--option CONFIG_OPTION", String, "Specify a simple configuration option (key=value)") do |v| k, v = v.split('=') begin @config_options[k.to_s] = YAML.load(v.to_s) rescue YAML::SyntaxError raise ConfigurationOptionError.new("Couldn't parse value for '#{k}': #{$!}") end update_config(@website.config) unless @website.nil? end opts.on("--[no-]debug", "Enable debugging") do |v| @log_level = (v ? ::Logger::DEBUG : :Logger::INFO) update_logger(@website.logger) unless @website.nil? end end add_command(Webgen::CLI::GenerateCommand.new, default: true) add_command(Webgen::CLI::ShowCommand.new) add_command(Webgen::CLI::CreateCommand.new) add_command(Webgen::CLI::InstallCommand.new) end |