mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
add registry for cli plugins
This commit is contained in:
parent
5e1c9e24fa
commit
589db0bcd0
5 changed files with 56 additions and 7 deletions
17
bin/inspec
17
bin/inspec
|
@ -10,7 +10,7 @@ require 'pp'
|
|||
require_relative '../lib/inspec'
|
||||
require_relative '../lib/utils/json_log'
|
||||
|
||||
class InspecCLI < Thor # rubocop:disable Metrics/ClassLength
|
||||
class Inspec::InspecCLI < Thor # rubocop:disable Metrics/ClassLength
|
||||
class_option :diagnose, type: :boolean,
|
||||
desc: 'Show diagnostics (versions, configurations)'
|
||||
|
||||
|
@ -251,4 +251,17 @@ class InspecCLI < Thor # rubocop:disable Metrics/ClassLength
|
|||
print "\n"
|
||||
end
|
||||
end
|
||||
InspecCLI.start(ARGV)
|
||||
|
||||
# load CLI plugins before the Inspec CLI has been started
|
||||
Inspec::Plugins::CLI.registry.each{ |subcommand, params|
|
||||
Inspec::InspecCLI.register(
|
||||
params[:klass],
|
||||
params[:subcommand_name],
|
||||
params[:usage],
|
||||
params[:description],
|
||||
params[:options]
|
||||
)
|
||||
}
|
||||
|
||||
# start the CLI
|
||||
Inspec::InspecCLI.start(ARGV)
|
||||
|
|
3
lib/bundles/README.md
Normal file
3
lib/bundles/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# InSpec Bundled Plugins
|
||||
|
||||
This directory contains bundled InSpec plugins. Those plugins are shipped with InSpec temporarily only. Over the next months we are going to stabilize the InSpec Plugin API. Once this API reached stability, all bundled plugins will be externalized.
|
|
@ -11,11 +11,13 @@ libdir = File.dirname(__FILE__)
|
|||
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||
|
||||
require 'inspec/version'
|
||||
require 'inspec/plugins'
|
||||
require 'inspec/profile'
|
||||
require 'inspec/resource'
|
||||
require 'inspec/rspec_json_formatter'
|
||||
require 'inspec/rule'
|
||||
require 'inspec/runner'
|
||||
require 'inspec/shell'
|
||||
require 'matchers/matchers'
|
||||
require 'inspec/runner'
|
||||
# ensure resource and plugins are loaded after runner, because the runner loads
|
||||
# targets
|
||||
require 'inspec/resource'
|
||||
require 'inspec/plugins'
|
||||
require 'inspec/shell'
|
||||
|
|
|
@ -3,10 +3,12 @@
|
|||
# author: Christoph Hartmann
|
||||
|
||||
require 'forwardable'
|
||||
|
||||
puts 'plugins'
|
||||
module Inspec
|
||||
# Resource Plugins
|
||||
module Plugins
|
||||
autoload :Resource, 'inspec/plugins/resource'
|
||||
autoload :CLI, 'inspec/plugins/cli'
|
||||
end
|
||||
|
||||
class PluginCtl
|
||||
|
@ -21,6 +23,11 @@ module Inspec
|
|||
.map { |x| File.dirname(x) }
|
||||
.map { |x| Dir[File.join(x, 'lib', 'inspec-*.rb')] }
|
||||
.flatten
|
||||
|
||||
# load bundled plugins
|
||||
bundled_dir = File.expand_path(File.dirname(__FILE__))
|
||||
@paths += Dir[File.join(bundled_dir, '..', 'bundles', 'inspec-*.rb')].flatten
|
||||
|
||||
# map paths to names
|
||||
@registry = Hash[@paths.map { |x|
|
||||
[File.basename(x, '.rb'), x]
|
||||
|
|
24
lib/inspec/plugins/cli.rb
Normal file
24
lib/inspec/plugins/cli.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# encoding: utf-8
|
||||
# author: Christoph Hartmann
|
||||
# author: Dominik Richter
|
||||
|
||||
module Inspec
|
||||
module Plugins
|
||||
# stores all CLI plugin, we expect those to the `Thor` subclasses
|
||||
class CLI
|
||||
def self.registry
|
||||
@registry ||= {}
|
||||
end
|
||||
|
||||
def self.register(klass, subcommand_name, usage, description, options = {})
|
||||
registry[subcommand_name] = {
|
||||
klass: klass,
|
||||
subcommand_name: subcommand_name,
|
||||
usage: usage,
|
||||
description: description,
|
||||
options: options,
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue