lib/bolt/cli.rb
# Execute a Bolt command. The +options+ hash includes the subcommand and
# action to be run, as well as any additional arguments and options for the
# command.
#
# @param options [Hash] The CLI options.
#
Execute a Bolt command. The +options+ hash includes the subcommand and
action to be run, as well as any additional arguments and options for the
command.
Execute a Bolt command . The + options + hash includes the subcommand and action to be run as well as any additional arguments and options for the command .
def execute(options)
      with_signal_handling do
        with_error_handling do
          command = options[:subcommand]
          action  = options[:action]
           INITIALIZE CORE CLASSES
          project = if ENV['BOLT_PROJECT']
                      Bolt::Project.create_project(ENV['BOLT_PROJECT'], 'environment')
                    elsif options[:project]
                      dir = Pathname.new(options[:project])
                      if (dir + Bolt::Project::BOLTDIR_NAME).directory?
                        Bolt::Project.create_project(dir + Bolt::Project::BOLTDIR_NAME)
                      else
                        Bolt::Project.create_project(dir)
                      end
                    else
                      Bolt::Project.find_boltdir(Dir.pwd)
                    end
          config = Bolt::Config.from_project(project, options)
          @outputter = Bolt::Outputter.for_format(
            config.format,
            config.color,
            options[:verbose],
            config.trace,
            config.spinner
          )
          @rerun = Bolt::Rerun.new(config.rerunfile, config.save_rerun)
           TODO: Subscribe this to the executor.
          analytics = begin
            client = Bolt::Analytics.build_client(config.analytics)
            client.bundled_content = bundled_content(options)
            client
          end
          Bolt::Logger.configure(config.log, config.color, config.disable_warnings)
          Bolt::Logger.stream = config.stream
          Bolt::Logger.analytics = analytics
          Bolt::Logger.flush_queue
          executor = Bolt::Executor.new(
            config.concurrency,
            analytics,
            options[:noop],
            config.modified_concurrency,
            config.future
          )
          pal = Bolt::PAL.new(
            Bolt::Config::Modulepath.new(config.modulepath),
            config.hiera_config,
            config.project.resource_types,
            config.compile_concurrency,
            config.trusted_external,
            config.apply_settings,
            config.project
          )
          plugins = Bolt::Plugin.new(config, pal, analytics)
          inventory = Bolt::Inventory.from_config(config, plugins)
          log_outputter = Bolt::Outputter::Logger.new(options[:verbose], config.trace)
           FINALIZING SETUP
          check_gem_install
          warn_inventory_overrides_cli(config, options)
          submit_screen_view(analytics, config, inventory, options)
          options[:targets] = process_target_list(plugins, @rerun, options)
           TODO: Fix casing issue in Windows.
          config.check_path_case('modulepath', config.modulepath)
          if options[:clear_cache]
            FileUtils.rm(config.project.plugin_cache_file) if File.exist?(config.project.plugin_cache_file)
            FileUtils.rm(config.project.task_cache_file) if File.exist?(config.project.task_cache_file)
            FileUtils.rm(config.project.plan_cache_file) if File.exist?(config.project.plan_cache_file)
          end
          case command
          when 'apply', 'lookup'
            if %w[human rainbow].include?(config.format)
              executor.subscribe(outputter)
            end
          when 'plan'
            if %w[human rainbow].include?(config.format)
              executor.subscribe(outputter)
            else
              executor.subscribe(outputter, %i[message verbose])
            end
          else
            executor.subscribe(outputter)
          end
          executor.subscribe(log_outputter)
           TODO: Figure out where this should really go. It doesn't seem to
                 make sense in the application, since the params should already
                 be data when they reach that point.
          if %w[plan task].include?(command) && action == 'run'
            options[:params] = parse_params(
              command,
              options[:object],
              pal,
              **options.slice(:params, :params_parsed)
            )
          end
          application = Bolt::Application.new(
            analytics: analytics,
            config:    config,
            executor:  executor,
            inventory: inventory,
            pal:       pal,
            plugins:   plugins
          )
          process_command(application, command, action, options)
        ensure
          analytics&.finish
        end
      end
    end
def execute ( options ) with_signal_handling do with_error_handling do command = options [ :subcommand ] action = options [ :action ] project = if ENV [ 'BOLT_PROJECT' ] Bolt :: Project . create_project ( ENV [ 'BOLT_PROJECT' ] , 'environment' ) elsif options [ :project ] dir = Pathname . new ( options [ :project ] ) if ( dir + Bolt :: Project :: BOLTDIR_NAME ) . directory? Bolt :: Project . create_project ( dir + Bolt :: Project :: BOLTDIR_NAME ) else Bolt :: Project . create_project ( dir ) end else Bolt :: Project . find_boltdir ( Dir . pwd ) end config = Bolt :: Config . from_project ( project , options ) @outputter = Bolt :: Outputter . for_format ( config . format , config . color , options [ :verbose ] , config . trace , config . spinner ) @rerun = Bolt :: Rerun . new ( config . rerunfile , config . save_rerun ) analytics = begin client = Bolt :: Analytics . build_client ( config . analytics ) client . bundled_content = bundled_content ( options ) client end Bolt :: Logger . configure ( config . log , config . color , config . disable_warnings ) Bolt :: Logger . stream = config . stream Bolt :: Logger . analytics = analytics Bolt :: Logger . flush_queue executor = Bolt :: Executor . new ( config . concurrency , analytics , options [ :noop ] , config . modified_concurrency , config . future ) pal = Bolt :: PAL . new ( Bolt :: Config :: Modulepath . new ( config . modulepath ) , config . hiera_config , config . project . resource_types , config . compile_concurrency , config . trusted_external , config . apply_settings , config . project ) plugins = Bolt :: Plugin . new ( config , pal , analytics ) inventory = Bolt :: Inventory . from_config ( config , plugins ) log_outputter = Bolt :: Outputter :: Logger . new ( options [ :verbose ] , config . trace ) check_gem_install warn_inventory_overrides_cli ( config , options ) submit_screen_view ( analytics , config , inventory , options ) options [ :targets ] = process_target_list ( plugins , @rerun , options ) config . check_path_case ( 'modulepath' , config . modulepath ) if options [ :clear_cache ] FileUtils . rm ( config . project . plugin_cache_file ) if File . exist? ( config . project . plugin_cache_file ) FileUtils . rm ( config . project . task_cache_file ) if File . exist? ( config . project . task_cache_file ) FileUtils . rm ( config . project . plan_cache_file ) if File . exist? ( config . project . plan_cache_file ) end case command when 'apply' , 'lookup' if %w[ human rainbow ] . include? ( config . format ) executor . subscribe ( outputter ) end when 'plan' if %w[ human rainbow ] . include? ( config . format ) executor . subscribe ( outputter ) else executor . subscribe ( outputter , %i[ message verbose ] ) end else executor . subscribe ( outputter ) end executor . subscribe ( log_outputter ) if %w[ plan task ] . include? ( command ) && action == 'run' options [ :params ] = parse_params ( command , options [ :object ] , pal , ** options . slice ( :params , :params_parsed ) ) end application = Bolt :: Application . new ( analytics : analytics , config : config , executor : executor , inventory : inventory , pal : pal , plugins : plugins ) process_command ( application , command , action , options ) ensure analytics &. finish end end end
Execute a Bolt command.
Execute a Bolt command .
# TODO: Separate from options hash and pass as own args. # # INITIALIZE CORE CLASSES # # TODO: Subscribe this to the executor. # # FINALIZING SETUP # # TODO: Fix casing issue in Windows. # TODO: Figure out where this should really go. It doesn't seem to #       make sense in the application, since the params should already #       be data when they reach that point.
options
The CLI options.
The CLI options .