mirror of
https://github.com/inspec/inspec
synced 2025-02-18 15:08:44 +00:00
semantics: rename CLI plugins registry -> subcommands
Basically make sure everyone understands these are only subcommands. we might consider adding plugins for options or existing commands instead of new subcommands. this just ensures everyone knows what registry is for
This commit is contained in:
parent
e3179fb741
commit
e56321f6c7
4 changed files with 11 additions and 12 deletions
|
@ -147,7 +147,7 @@ ctl = Inspec::PluginCtl.new
|
||||||
ctl.list.each { |x| ctl.load(x) }
|
ctl.list.each { |x| ctl.load(x) }
|
||||||
|
|
||||||
# load CLI plugins before the Inspec CLI has been started
|
# load CLI plugins before the Inspec CLI has been started
|
||||||
Inspec::Plugins::CLI.registry.each { |_subcommand, params|
|
Inspec::Plugins::CLI.subcommands.each { |_subcommand, params|
|
||||||
Inspec::InspecCLI.register(
|
Inspec::InspecCLI.register(
|
||||||
params[:klass],
|
params[:klass],
|
||||||
params[:subcommand_name],
|
params[:subcommand_name],
|
||||||
|
|
|
@ -142,5 +142,5 @@ module Compliance
|
||||||
end
|
end
|
||||||
|
|
||||||
# register the subcommand to Inspec CLI registry
|
# register the subcommand to Inspec CLI registry
|
||||||
Inspec::Plugins::CLI.register(ComplianceCLI, 'compliance', 'compliance SUBCOMMAND ...', 'Chef Compliance commands', {})
|
Inspec::Plugins::CLI.add_subcommand(ComplianceCLI, 'compliance', 'compliance SUBCOMMAND ...', 'Chef Compliance commands', {})
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,12 +6,12 @@ module Inspec
|
||||||
module Plugins
|
module Plugins
|
||||||
# stores all CLI plugin, we expect those to the `Thor` subclasses
|
# stores all CLI plugin, we expect those to the `Thor` subclasses
|
||||||
class CLI
|
class CLI
|
||||||
def self.registry
|
def self.subcommands
|
||||||
@registry ||= {}
|
@subcommands ||= {}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.register(klass, subcommand_name, usage, description, options = {})
|
def self.add_subcommand(klass, subcommand_name, usage, description, options = {})
|
||||||
registry[subcommand_name] = {
|
subcommands[subcommand_name] = {
|
||||||
klass: klass,
|
klass: klass,
|
||||||
subcommand_name: subcommand_name,
|
subcommand_name: subcommand_name,
|
||||||
usage: usage,
|
usage: usage,
|
||||||
|
|
|
@ -16,13 +16,12 @@ describe 'plugin system' do
|
||||||
let(:cli_reg) { Inspec::Plugins::CLI }
|
let(:cli_reg) { Inspec::Plugins::CLI }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
# TODO: remove this, once the plugin loading is not based on ruby-load time
|
# since the registry is a global singleton, clean it before using
|
||||||
# initialization
|
cli_reg.subcommands.clear
|
||||||
cli_reg.registry.clear
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is empty' do
|
it 'is empty' do
|
||||||
cli_reg.registry.must_equal({})
|
cli_reg.subcommands.must_equal({})
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'stores one cli plugin' do
|
it 'stores one cli plugin' do
|
||||||
|
@ -33,14 +32,14 @@ describe 'plugin system' do
|
||||||
description: 'desc of my_cmd',
|
description: 'desc of my_cmd',
|
||||||
options: { test: 1 }
|
options: { test: 1 }
|
||||||
}
|
}
|
||||||
cli_reg.register(
|
cli_reg.add_subcommand(
|
||||||
plugin[:klass],
|
plugin[:klass],
|
||||||
plugin[:subcommand_name],
|
plugin[:subcommand_name],
|
||||||
plugin[:usage],
|
plugin[:usage],
|
||||||
plugin[:description],
|
plugin[:description],
|
||||||
plugin[:options]
|
plugin[:options]
|
||||||
)
|
)
|
||||||
cli_reg.registry['my_cmd'].must_equal(plugin)
|
cli_reg.subcommands['my_cmd'].must_equal(plugin)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue