Module: SiteFuel::CommandLine
- Includes:
- Term::ANSIColor
- Defined in:
- lib/sitefuel/CommandLine.rb
Class Method Summary collapse
-
.parse_command_line(runtime) ⇒ Object
parse command line arguments and configure a SiteFuelRuntime.
- .puts_and_exit(*args) ⇒ Object
Class Method Details
.parse_command_line(runtime) ⇒ Object
parse command line arguments and configure a SiteFuelRuntime
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 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 |
# File 'lib/sitefuel/CommandLine.rb', line 31 def self.parse_command_line(runtime) #### BUILD THE OPTIONS PARSER @option_parser = OptionParser.new # the banner text comes from the header comment for this file @option_parser.on('-o PLACE', '--output=ARG', '--output PLACE', String, 'Where to put a deployed site') do |out| runtime.deploy_to = out end @option_parser.on('-v', '--version', 'Gives the version of sitefuel') do puts_and_exit 'SiteFuel ' + VERSION_TEXT end @option_parser.on('--scm=ARG', '--scm PLACE', String, 'What SCM to use (git, svn, or filesystem)') do |out| runtime.scm_system = out end # # Verbosity options # @option_parser.on('--[no-]verbose', 'List actions as they are preformed') do |be_verbose| if be_verbose # fatal, error, warnings, and info runtime.verbosity(3) else # fatal, error, and warnings runtime.verbosity(2) end end @option_parser.on('--debug', 'Gives verbose debugging information') do runtime.verbosity(4) end @option_parser.on('--abort-errors', '[default] Abort deployment if there are errors') do runtime.abort_on_errors = true end @option_parser.on('--ignore-errors', 'Deploy even if there are errors') do runtime.abort_on_errors = false runtime.abort_on_warnings = false end @option_parser.on('--abort-warnings', 'Abort deployment if there are warnings') do runtime.abort_on_warnings = true runtime.abort_on_errors = true end @option_parser.on('--ignore-warnings', '[default] Deploy even if there are warnings') do runtime.abort_on_warnings = true end @option_parser.on('--only-list-recognized-files', 'Only list summaries for files which were changed') do runtime.only_list_recognized_files = true end @option_parser.on('-h', '--help', '-?', '--about', 'Gives help for a specific command.') do RDoc::usage_no_exit('Synopsis', 'Usage', 'Introduction') puts @option_parser RDoc::usage_no_exit('Examples', 'Author', 'Copyright') exit end @option_parser.on('--license', 'Gives the license for SiteFuel.') do puts_and_exit SiteFuel::LICENSE end @option_parser.separator '' @option_parser.separator 'Specific options for a command can be seen with: ' @option_parser.separator ' COMMAND --help' #### ATTEMPT TO PARSE THE COMMAND LINE begin commands = @option_parser.parse(*ARGV) rescue OptionParser::InvalidOption => invalid_option puts invalid_option puts_and_exit $HELP_HINT_LINE rescue => exception # TODO: add better handling for the various exceptions (unnecessary # argument, missing argument, etc.) puts_and_exit "couldn't parse command line: #{exception}", $HELP_HINT_LINE # puts exception.backtrace.join("\n") end # note that --help will have already been intercepted but 'help' still needs # special treatment puts_and_exit 'no command given', $HELP_HINT_LINE if commands.length < 1 puts_and_exit @option_parser if commands[0].downcase == 'help' case commands[0].downcase when 'deploy' runtime.deploy_from = commands[1] runtime.deploy_to = commands[2] runtime.deploy when 'stage' runtime.deploy_from = commands[1] runtime.stage else puts_and_exit "unknown command: '#{commands[0]}'", $HELP_HINT_LINE end end |
.puts_and_exit(*args) ⇒ Object
21 22 23 24 |
# File 'lib/sitefuel/CommandLine.rb', line 21 def self.puts_and_exit(*args) puts(*args) exit end |