2016-02-14 10:59:02 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
2016-02-21 21:12:02 +00:00
|
|
|
require 'pathname'
|
2018-07-17 15:42:36 +00:00
|
|
|
require_relative 'renderer'
|
Plugins API v2: Loader, Base API, and Test Harness (#3278)
* Functional tests for userdir option
* Accepts --config-dir CLI option
* Actually loads a config file from the config dir, more cases to test
* Able to load config and verify contents from config-dir
* Functional tests to ensure precedence for config options
* Enable setting config dir via env var
* .inspec, not .inspec.d
* Begin converting PluginCtl to PluginLoader/Registry
* Able to load and partially validate the plugins.json file
* More work on the plugin loader
* Break the world, move next gen stuff to plugin/
* Be sure to require base cli in bundled plugins
* Move test file
* Revert changes to v1 plugin, so we can have a separate one
* Checkpoint commit
* Move v2 plugin work to v2 area
* Move plugins v1 code into an isolated directory
* rubocop fixes
* Rip out the stuff about a user-dir config file, just use a plugin file
* Two psuedocode test file
* Working base API, moock plugin type, and loader.
* Adjust load path to be more welcoming
* Silence circular depencency warning, which was breaking a unit test
* Linting
* Fix plugin type registry, add tests to cover
* Feedback from Jerry
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
2018-08-16 22:16:32 +00:00
|
|
|
require 'inspec/base_cli'
|
2016-02-21 21:12:02 +00:00
|
|
|
|
2016-02-14 20:26:37 +00:00
|
|
|
module Init
|
2016-02-14 10:59:02 +00:00
|
|
|
class CLI < Inspec::BaseCLI
|
2016-02-14 20:26:37 +00:00
|
|
|
namespace 'init'
|
2016-02-14 10:59:02 +00:00
|
|
|
|
2016-08-18 18:10:09 +00:00
|
|
|
# TODO: find another solution, once https://github.com/erikhuda/thor/issues/261 is fixed
|
|
|
|
def self.banner(command, _namespace = nil, _subcommand = false)
|
|
|
|
"#{basename} #{subcommand_prefix} #{command.usage}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.subcommand_prefix
|
|
|
|
namespace
|
|
|
|
end
|
|
|
|
|
2018-07-17 15:42:36 +00:00
|
|
|
# Look in the 'template' directory, and register a subcommand
|
|
|
|
# for each template directory found there.
|
2016-02-14 10:59:02 +00:00
|
|
|
template_dir = File.join(File.dirname(__FILE__), 'templates')
|
|
|
|
Dir.glob(File.join(template_dir, '*')) do |template|
|
2018-07-17 15:42:36 +00:00
|
|
|
template_name = Pathname.new(template).relative_path_from(Pathname.new(template_dir)).to_s
|
2016-02-14 10:59:02 +00:00
|
|
|
|
|
|
|
# register command for the template
|
2018-07-17 15:42:36 +00:00
|
|
|
desc "#{template_name} NAME", "Create a new #{template_name}"
|
2016-02-14 10:59:02 +00:00
|
|
|
option :overwrite, type: :boolean, default: false,
|
2018-07-17 15:42:36 +00:00
|
|
|
desc: 'Overwrites existing directory'
|
|
|
|
define_method template_name.to_sym do |name_for_new_structure|
|
|
|
|
renderer = Init::Renderer.new(self, options)
|
|
|
|
renderer.render_with_values(template_name, name: name_for_new_structure)
|
2016-02-14 10:59:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# register the subcommand to Inspec CLI registry
|
2016-02-14 20:26:37 +00:00
|
|
|
Inspec::Plugins::CLI.add_subcommand(Init::CLI, 'init', 'init TEMPLATE ...', 'Scaffolds a new project', {})
|
2016-02-14 10:59:02 +00:00
|
|
|
end
|