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.



31
32
33
34
35
36
37
# File 'lib/warp/dir/command/install.rb', line 31

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

Instance Attribute Details

#existingObject

Returns the value of attribute existing.



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

def existing
  @existing
end

#installedObject

Returns the value of attribute installed.



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

def installed
  @installed
end

#shell_init_filesObject

Returns the value of attribute shell_init_files.



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

def shell_init_files
  @shell_init_files
end

#wrapperObject

Returns the value of attribute wrapper.



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

def wrapper
  @wrapper
end

Class Method Details

.already_installed?(file_path) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
# File 'lib/warp/dir/command/install.rb', line 20

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::SHELL_WRAPPER_REGX }
              end
            end
  matches
end

.wrapper_installed?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/warp/dir/command/install.rb', line 16

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

Instance Method Details

#run(*args) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/warp/dir/command/install.rb', line 39

def run(*args)
  self.shell_init_files = config[:dotfile].split(',') if config[:dotfile]
  self.shell_init_files.any? { |dotfile| append_wrapper_to(dotfile) }

  # Overwrites if already there
  install_bash_wd

  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