Class: Hem::Cli
Overview
Main application class
Instance Attribute Summary collapse
-
#help_formatter ⇒ Object
Returns the value of attribute help_formatter.
-
#slop ⇒ Object
Returns the value of attribute slop.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Cli
constructor
:help and :host_check are only used by tests.
-
#show_help(opts = {}) ⇒ Object
Display help and exit Options are mostly used for filtering.
-
#start(args = ARGV) ⇒ Object
entry point for application.
Methods included from Logging
Constructor Details
#initialize(opts = {}) ⇒ Cli
:help and :host_check are only used by tests. :slop is used to ensure low-level args parsed in bin/hem are propagated to the application
24 25 26 27 28 29 30 31 |
# File 'lib/hem/cli.rb', line 24 def initialize opts = {} @opts = opts @slop = opts[:slop] || Slop.new @help_formatter = opts[:help] || Hem::HelpFormatter.new(@slop) @help_opts = {} @host_check = opts[:host_check] || Hem::Lib::HostCheck @pre_task_namespaces = ['shell-init', 'plugin'] end |
Instance Attribute Details
#help_formatter ⇒ Object
Returns the value of attribute help_formatter.
15 16 17 |
# File 'lib/hem/cli.rb', line 15 def help_formatter @help_formatter end |
#slop ⇒ Object
Returns the value of attribute slop.
15 16 17 |
# File 'lib/hem/cli.rb', line 15 def slop @slop end |
Instance Method Details
#show_help(opts = {}) ⇒ Object
Display help and exit Options are mostly used for filtering
76 77 78 79 |
# File 'lib/hem/cli.rb', line 76 def show_help(opts = {}) Hem.ui.info @help_formatter.help(@help_opts.merge(opts)) halt end |
#start(args = ARGV) ⇒ Object
entry point for application
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 |
# File 'lib/hem/cli.rb', line 35 def start args = ARGV load_user_config load_builtin_tasks load_hemfiles load_project_config define_global_opts @slop begin # Parse out global args first @slop.parse! args opts = @slop.to_hash @help_opts[:all] = opts[:all] # Necessary to make command level help work args.push "--help" if @slop.help? || args.empty? include_pre_tasks remaining = @slop.parse! args.dup remaining.push "--help" if @slop.help? if remaining == args include_post_tasks opts remaining = @slop.parse! remaining end raise Hem::InvalidCommandOrOpt.new remaining.join(" ") if remaining.size > 0 show_help if @slop.help? rescue Halt # NOP end return 0 end |