Class: Hobo::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/hobo are propagated to the application
24 25 26 27 28 29 30 |
# File 'lib/hobo/cli.rb', line 24 def initialize opts = {} @opts = opts @slop = opts[:slop] || Slop.new @help_formatter = opts[:help] || Hobo::HelpFormatter.new(@slop) @help_opts = {} @host_check = opts[:host_check] || Hobo::Lib::HostCheck end |
Instance Attribute Details
#help_formatter ⇒ Object
Returns the value of attribute help_formatter.
15 16 17 |
# File 'lib/hobo/cli.rb', line 15 def help_formatter @help_formatter end |
#slop ⇒ Object
Returns the value of attribute slop.
15 16 17 |
# File 'lib/hobo/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
75 76 77 78 |
# File 'lib/hobo/cli.rb', line 75 def show_help(opts = {}) Hobo.ui.info @help_formatter.help(@help_opts.merge(opts)) halt end |
#start(args = ARGV) ⇒ Object
entry point for application
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 |
# File 'lib/hobo/cli.rb', line 34 def start args = ARGV load_user_config load_builtin_tasks load_hobofiles load_project_config tasks = structure_tasks Hobo::Metadata..keys define_global_opts @slop begin # Parse out global args first @slop.parse! args opts = @slop.to_hash perform_host_checks unless opts[:'skip-host-checks'] @help_opts[:all] = opts[:all] @slop.add_callback :empty do show_help end # Necessary to make command level help work args.push "--help" if @slop.help? @help_formatter.command_map = define_tasks(tasks, @slop) remaining = @slop.parse! args raise Hobo::InvalidCommandOrOpt.new remaining.join(" "), self if remaining.size > 0 show_help if @slop.help? rescue Halt # NOP end return 0 end |