Class: AppArchetype::Commands::OpenManifest
- Inherits:
-
Object
- Object
- AppArchetype::Commands::OpenManifest
- Defined in:
- lib/app_archetype/commands/open_manifest.rb
Overview
Opens manifest in configured editor
Instance Method Summary collapse
-
#initialize(manager, editor, options = Hashie::Mash.new) ⇒ OpenManifest
constructor
A new instance of OpenManifest.
-
#run ⇒ Object
Opens a manifest in the chosen editor program.
Constructor Details
#initialize(manager, editor, options = Hashie::Mash.new) ⇒ OpenManifest
Returns a new instance of OpenManifest.
7 8 9 10 11 12 |
# File 'lib/app_archetype/commands/open_manifest.rb', line 7 def initialize(manager, editor, = Hashie::Mash.new) @manager = manager @editor = editor @options = @prompt = TTY::Prompt.new end |
Instance Method Details
#run ⇒ Object
Opens a manifest in the chosen editor program
First it looks to the options for the manifest name. If this is not provided the user will be given a list to select from.
The manager then attempts to find the manifest by name. If it cannot be found, a RuntimeError is raised and the command stops.
Otherwise a new editor subprocess is started with the manifest path given as an arg.
This process will wait until the conclusion of the editor process. It’s recommended that the editor be a command line editor like ‘vi`
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/app_archetype/commands/open_manifest.rb', line 32 def run name = @options.name name ||= @prompt.select('Please choose manifest', @manager.manifest_names) manifest = @manager.find_by_name(name) unless manifest puts "✖ No manifests with name `#{name}` found." return end pid = Process.spawn("#{@editor} #{manifest.path}") Process.waitpid(pid) end |