Class: AppArchetype::Commands::OpenManifest

Inherits:
Object
  • Object
show all
Defined in:
lib/app_archetype/commands/open_manifest.rb

Overview

Opens manifest in configured editor

Instance Method Summary collapse

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, options = Hashie::Mash.new)
  @manager = manager
  @editor = editor
  @options = options
  @prompt = TTY::Prompt.new
end

Instance Method Details

#runObject

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