Class: InspecPlugins::PluginManager::CliCommand
- Inherits:
-
Object
- Object
- InspecPlugins::PluginManager::CliCommand
- Includes:
- Term::ANSIColor
- Defined in:
- lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb
Instance Method Summary collapse
- #install(plugin_id_arg) ⇒ Object
- #list ⇒ Object
-
#search(search_term) ⇒ Object
Justification for disabling ABC: currently at 33.51/33.
- #uninstall(plugin_name) ⇒ Object
- #update(plugin_name) ⇒ Object
Instance Method Details
#install(plugin_id_arg) ⇒ Object
92 93 94 95 96 97 98 99 100 |
# File 'lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb', line 92 def install(plugin_id_arg) if plugin_id_arg =~ /\.gem$/ # Does it end in .gem? install_from_gemfile(plugin_id_arg) elsif plugin_id_arg =~ %r{[\/\\]} || Dir.exist?(plugin_id_arg) # Does the argument have a slash, or exist as dir in the local directory? install_from_path(plugin_id_arg) else install_from_remote_gem(plugin_id_arg) end end |
#list ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb', line 19 def list plugin_statuses = Inspec::Plugin::V2::Registry.instance.plugin_statuses plugin_statuses.reject! { |s| [:core, :bundle].include?(s.installation_type) } unless [:all] # TODO: ui object support puts puts(bold { format(' %-30s%-10s%-8s%-6s', 'Plugin Name', 'Version', 'Via', 'ApiVer') }) puts '-' * 55 plugin_statuses.sort_by(&:name).each do |status| puts(format(' %-30s%-10s%-8s%-6s', status.name, make_pretty_version(status), status.installation_type, status.api_generation.to_s)) end puts '-' * 55 puts(" #{plugin_statuses.count} plugin(s) total") puts end |
#search(search_term) ⇒ Object
Justification for disabling ABC: currently at 33.51/33
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb', line 49 def search(search_term) # rubocop: disable Metrics/AbcSize search_results = installer.search(search_term, exact: [:exact]) # The search results have already been filtered by the reject list. But the # RejectList doesn't filter {inspec, train}-test-fixture because we need those # for testing. We want to hide those from users, so unless we know we're in # test mode, remove them. unless [:'include-test-fixture'] search_results.delete('inspec-test-fixture') search_results.delete('train-test-fixture') end # TODO: ui object support puts puts(bold { format(' %-30s%-50s', 'Plugin Name', 'Versions Available') }) puts '-' * 55 search_results.keys.sort.each do |plugin_name| versions = [:all] ? search_results[plugin_name] : [search_results[plugin_name].first] versions = '(' + versions.join(', ') + ')' puts(format(' %-30s%-50s', plugin_name, versions)) end puts '-' * 55 puts(" #{search_results.count} plugin(s) found") puts exit 2 if search_results.empty? rescue Inspec::Plugin::V2::SearchError => ex Inspec::Log.error ex. exit 1 end |
#uninstall(plugin_name) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb', line 142 def uninstall(plugin_name) status = Inspec::Plugin::V2::Registry.instance[plugin_name.to_sym] unless status puts(red { 'No such plugin installed: ' } + "#{plugin_name} is not installed - uninstall failed") exit 1 end installer = Inspec::Plugin::V2::Installer.instance pre_uninstall_versions = installer.list_installed_plugin_gems.select { |spec| spec.name == plugin_name }.map { |spec| spec.version.to_s } old_version = pre_uninstall_versions.join(', ') installer.uninstall(plugin_name) if status.installation_type == :path puts(bold { plugin_name } + ' path-based plugin install has been uninstalled') else puts(bold { plugin_name } + " plugin, version #{old_version}, has been uninstalled") end exit 0 end |
#update(plugin_name) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb', line 111 def update(plugin_name) pre_update_versions = installer.list_installed_plugin_gems.select { |spec| spec.name == plugin_name }.map { |spec| spec.version.to_s } old_version = pre_update_versions.join(', ') update_preflight_check(plugin_name, pre_update_versions) begin installer.update(plugin_name) rescue Inspec::Plugin::V2::UpdateError => ex puts(red { 'Update error: ' } + ex. + ' - update failed') exit 1 end post_update_versions = installer.list_installed_plugin_gems.select { |spec| spec.name == plugin_name }.map { |spec| spec.version.to_s } new_version = (post_update_versions - pre_update_versions).first puts(bold { plugin_name } + " plugin, version #{old_version} -> #{new_version}, updated from rubygems.org") end |