Class: ConfigmonkeyCli::Application::ManifestAction::Link

Inherits:
Base
  • Object
show all
Defined in:
lib/configmonkey_cli/application/manifest_actions/link.rb

Instance Attribute Summary

Attributes inherited from Base

#app, #args, #manifest, #opts, #thor

Instance Method Summary collapse

Methods inherited from Base

#args_and_opts, #exists?, #expand_dst, #expand_src, #initialize, #rel, #to_s

Constructor Details

This class inherits a constructor from ConfigmonkeyCli::Application::ManifestAction::Base

Instance Method Details

#destructiveObject



40
41
42
# File 'lib/configmonkey_cli/application/manifest_actions/link.rb', line 40

def destructive
  thor.create_link(@destination, @source, @opts)
end

#init(hargs_and_opts = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/configmonkey_cli/application/manifest_actions/link.rb', line 5

def init hargs_and_opts = {}
  @args, @opts = args_and_opts(hargs_and_opts)
  @opts = @opts.reverse_merge({
    prefix: nil,
    map: "d:d",
    hard: false,
  })
end

#prepareObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/configmonkey_cli/application/manifest_actions/link.rb', line 14

def prepare
  @opts[:force] = app.opts[:default_yes]
  @opts[:symbolic] = !@opts[:hard]
  @source = @args[0]
  @destination = @args[1]
  map = @opts[:map].split(":")

  # prefix source
  @source = File.join(map[0]["d"] ? thor.destination_root : manifest.directory, @source)
  @destination = File.join(map[1]["d"] ? thor.destination_root : manifest.directory, @destination)

  # prefix target link
  if(@opts[:prefix] && map[1].downcase["p"])
    prefix = "cm--#{manifest.checksum(@opts[:prefix], soft: !map[1]["H"])}--"
    @destination = File.join(File.dirname(@destination), "#{prefix}#{File.basename(@destination)}")
  end
end

#simulateObject



32
33
34
35
36
37
38
# File 'lib/configmonkey_cli/application/manifest_actions/link.rb', line 32

def simulate
  if thor.options[:pretend]
    destructive
  else
    status :fake, :black, rel(@destination)
  end
end