Module: Drakkon::Gems::Configure
- Defined in:
- lib/drakkon/gem/configure.rb
Overview
Run Command for CLI
Class Method Summary collapse
- .gem_select ⇒ Object
- .modify_options(gem_name) ⇒ Object
- .opts ⇒ Object
- .prompt ⇒ Object
- .start(args) ⇒ Object
Class Method Details
.gem_select ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/drakkon/gem/configure.rb', line 48 def self.gem_select prompt.select('Which gem do you want to edit?:', filter: true) do || Settings.gems.each_key do |gem| .choice name: gem, value: gem end end end |
.modify_options(gem_name) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/drakkon/gem/configure.rb', line 56 def self.(gem_name) prompt.select("Editing #{gem_name.pastel(:bright_blue)}. What do you want to do?", filter: true) do || .choice name: 'Edit Modules', value: :modules .choice name: 'Edit Files', value: :files .choice name: 'Refresh Modules', value: :refresh .choice name: 'Remove', value: :remove end end |
.opts ⇒ Object
5 6 7 |
# File 'lib/drakkon/gem/configure.rb', line 5 def self.opts @opts end |
.prompt ⇒ Object
65 66 67 |
# File 'lib/drakkon/gem/configure.rb', line 65 def self.prompt TTY::Prompt.new(active_color: :cyan, interrupt: :exit) end |
.start(args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/drakkon/gem/configure.rb', line 9 def self.start(args) if Settings.gems.empty? LogBot.fatal('Gem Configure', 'No gems! Install one first!') return end # Allow CLI/Gem Edit # TODO: Refactor # This feels pretty icky, would probably be good to refactor when my brain is working gem_name = args.shift&.to_sym gem_name = nil if !gem_name.nil? && !Settings.gems.keys.include?(gem_name) gem_name = gem_select if gem_name.nil? # ====================================================================== # Initial Opts initial_opt = args.shift&.to_sym case initial_opt || (gem_name) when :modules gem = Gem.new gem.edit(gem_name, Settings.gems[gem_name], :modules) when :files gem = Gem.new gem.edit(gem_name, Settings.gems[gem_name], :files) when :delete LogBot.info('Gem', "Removing #{gem_name.pastel(:bright_blue)}") Settings.gems.delete gem_name Settings.write when :refresh LogBot.info('Gem', "Refreshing #{gem_name.pastel(:bright_blue)} Modules") gem = Gem.new gem.edit(gem_name, Settings.gems[gem_name], :refresh) end rescue TTY::Reader::InputInterrupt exit 0 end |