Class: Warp::Dir::Command::Install

Inherits:
Warp::Dir::Command show all
Defined in:
lib/warp/dir/command/install.rb

Instance Attribute Summary collapse

Attributes inherited from Warp::Dir::Command

#formatter, #point, #point_name, #point_path, #store

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Warp::Dir::Command

command_name, #config, help, inherited, #inspect, installed_commands, #needs_point?, #on, #puts

Constructor Details

#initialize(*args) ⇒ Install

Returns a new instance of Install.



25
26
27
28
29
30
31
# File 'lib/warp/dir/command/install.rb', line 25

def initialize(*args)
  self.installed        = []
  self.existing         = []
  self.wrapper          = File.read(::Warp::Dir::SHELL_WRAPPER)
  self.shell_init_files = ::Warp::Dir::DOTFILES
  super(*args)
end

Instance Attribute Details

#existingObject

Returns the value of attribute existing.



7
8
9
# File 'lib/warp/dir/command/install.rb', line 7

def existing
  @existing
end

#installedObject

Returns the value of attribute installed.



7
8
9
# File 'lib/warp/dir/command/install.rb', line 7

def installed
  @installed
end

#shell_init_filesObject

Returns the value of attribute shell_init_files.



7
8
9
# File 'lib/warp/dir/command/install.rb', line 7

def shell_init_files
  @shell_init_files
end

#wrapperObject

Returns the value of attribute wrapper.



7
8
9
# File 'lib/warp/dir/command/install.rb', line 7

def wrapper
  @wrapper
end

Class Method Details

.already_installed?(file_path) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
# File 'lib/warp/dir/command/install.rb', line 14

def already_installed?(file_path)
  path = ::Warp::Dir.absolute(file_path)
  matches = if File.exists?(path)
              File.open path do |file|
                file.find { |line| line =~ /warp-dir/ }
              end
            end
  matches
end

.wrapper_installed?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/warp/dir/command/install.rb', line 10

def wrapper_installed?
  ::Warp::Dir::DOTFILES.any?{ |file| already_installed?(file) }
end

Instance Method Details

#run(*args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/warp/dir/command/install.rb', line 33

def run(*args)
  self.shell_init_files = config[:dotfile].split(',') if config[:dotfile]
  self.shell_init_files.any? { |dotfile| append_wrapper_to(dotfile) }
  local_existing    = self.existing
  local_installed   = self.installed
  local_shell_files = self.shell_init_files
  if installed.empty?
    if existing.empty?
      on :error do
        if local_shell_files.size > 1 then
          message "Shell init files #{local_shell_files.join(', ').yellow.bold} were not found on the filesystem.".red
        else
          message "Shell init file #{local_shell_files.join(', ').yellow.bold} was not found on the filesystem.".red
        end
      end
    else
      on :error do
        message 'Looks like you already have shell support installed.'.red
        message "#{local_existing.join(', ').yellow.bold} already warp-dir definition. Use --force to override."
      end
    end
  else
    on :success do
      message 'Shell support is installed in the following files:'.green.bold
      message "#{local_installed.join(', ')}".bold.yellow
    end
  end
end