Method: Inspec::Plugin::V2::Loader#activate_mentioned_cli_plugins

Defined in:
lib/inspec/plugin/v2/loader.rb

#activate_mentioned_cli_plugins(cli_args = ARGV) ⇒ Object



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
# File 'lib/inspec/plugin/v2/loader.rb', line 78

def activate_mentioned_cli_plugins(cli_args = ARGV)
  # Get a list of CLI plugin activation hooks
  registry.find_activators(plugin_type: :cli_command).each do |act|
    next if act.activated?

    # Decide whether to activate.  Several conditions, so split them out for clarity.
    # Assume no, to start.  Each condition may flip it true, which will short-circuit
    # all following ||= ops.
    activate_me = false

    # If the user invoked `inspec help`, activate all CLI plugins, so they can
    # display their usage message.
    activate_me ||= cli_args.first == 'help'

    # Likewise, if they invoked simply `inspec`, they are confused, and need
    # usage info.
    activate_me ||= cli_args.empty?

    # If there is anything in the CLI args with the same name, activate it.
    # This is the expected usual activation for individual plugins.
    # `inspec dosomething` => activate the :dosomething hook
    activate_me ||= cli_args.include?(act.activator_name.to_s)

    # OK, activate.
    if activate_me
      activate(:cli_command, act.activator_name)
      act.implementation_class.register_with_thor
    end
  end
end