diff --git a/lib/plugin/plugin.rb b/lib/plugin/plugin.rb index 8a01e31..1dbabb9 100644 --- a/lib/plugin/plugin.rb +++ b/lib/plugin/plugin.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'yaml' +require_relative 'plugin_exposer' module RubyRaider module Plugin @@ -12,6 +13,7 @@ def add_plugin(plugin_name) pp "Adding #{plugin_name}..." add_plugin_to_gemfile(plugin_name) system('bundle install') + PluginExposer.expose_commands(plugin_name) pp "The plugin #{plugin_name} is added" end @@ -20,6 +22,7 @@ def delete_plugin(plugin_name) pp "Deleting #{plugin_name}..." remove_plugin_from_gemfile(plugin_name) + PluginExposer.remove_command(plugin_name) system('bundle install') pp "The plugin #{plugin_name} is deleted" end diff --git a/lib/plugin/plugin_exposer.rb b/lib/plugin/plugin_exposer.rb new file mode 100644 index 0000000..b296c17 --- /dev/null +++ b/lib/plugin/plugin_exposer.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'thor' + +module RubyRaider + module PluginExposer + def self.expose_commands(plugin_name) + File.new('lib/commands/loaded_commands.rb', 'w') unless File.exist?('lib/commands/loaded_commands.rb') + File.open('lib/commands/loaded_commands.rb', 'w') do |file| + file.puts '# frozen_string_literal: true' + file.puts + file.puts 'require \'thor\'' + file.puts "require \'#{plugin_name}\'" + file.puts 'require_relative \'../plugin/plugin\'' + file.puts + file.puts 'module RubyRaider' + file.puts ' class LoadedCommands < Thor' + file.puts " desc \'#{plugin_name} [COMMAND] [NAME]\', \'Plugin commands\'" + file.puts + file.puts ' subcommand \'great_axe\', GreatAxe::PluginCommands' + file.puts ' end' + file.puts 'end' + end + end + + def self.remove_command(plugin_name) + File.open('lib/commands/loaded_commands.rb', 'w') do |file| + file.puts '# frozen_string_literal: true' + file.puts + file.puts 'require \'thor\'' + file.puts 'require_relative \'../plugin/plugin\'' + file.puts + file.puts 'module RubyRaider' + file.puts ' class LoadedCommands < Thor' + file.puts ' end' + file.puts 'end' + end + end + end +end diff --git a/lib/ruby_raider.rb b/lib/ruby_raider.rb index 33b487f..dfa5dc2 100644 --- a/lib/ruby_raider.rb +++ b/lib/ruby_raider.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -require 'great_axe' require_relative '../lib/plugin/plugin' require_relative '../lib/commands/plugin_commands' +require_relative '../lib/commands/loaded_commands' require_relative '../lib/commands/scaffolding_commands' require_relative '../lib/commands/utility_commands' @@ -47,6 +47,12 @@ def version subcommand 'plugin', PluginCommands map 'pl' => 'plugin' + if File.readlines(File.expand_path('/Users/apeque01/Desktop/main_folder/Projects/open_source/ruby_raider/lib/commands/loaded_commands.rb')).any? do |line| + line.include?('subcommand') + end + RubyRaider::LoadedCommands.start + end + no_commands do def current_version = File.read(File.expand_path('version', __dir__)).strip end