Module: Alterpath::CLI

Defined in:
lib/alterpath/cli.rb

Class Method Summary collapse

Class Method Details

.append(opts, args) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/alterpath/cli.rb', line 66

def append(opts, args)
  args.each do |arg|
    puts "Appending \"#{arg}\" to PATH!"
    path.append(arg, get_addition_options(opts))
    path.commit!
    exit
  end
end

.get(opts, args) ⇒ Object



98
99
100
101
# File 'lib/alterpath/cli.rb', line 98

def get(opts, args)
  puts path.get
  exit
end

.get_addition_options(opts) ⇒ Object



62
63
64
# File 'lib/alterpath/cli.rb', line 62

def get_addition_options(opts)
  opts[:force] ? { duplication_filter: :none } : {}
end

.list(opts, args) ⇒ Object



93
94
95
96
# File 'lib/alterpath/cli.rb', line 93

def list(opts, args)
  puts *path.get_array
  exit
end

.pathObject



58
59
60
# File 'lib/alterpath/cli.rb', line 58

def path
  @path ||= WinPathUtils::Path.new
end

.prepend(opts, args) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/alterpath/cli.rb', line 75

def prepend(opts, args)
  args.each do |arg|
    puts "Prepending PATH with \"#{arg}\"!"
    path.prepend(arg, get_addition_options(opts))
    path.commit!
    exit
  end
end

.remove(opts, args) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/alterpath/cli.rb', line 84

def remove(opts, args)
  args.each do |arg|
    puts "Removing \"#{arg}\" from PATH!"
    path.remove(arg)
    path.commit!
    exit
  end        
end

.startObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/alterpath/cli.rb', line 7

def start
  appname = File.basename($0)
  opts = Slop.parse(strict: true, help: true) do
    banner "Usage: #{appname} command [options]"

    on :v, :version, 'Print the version.' do
      require 'win-path-utils/version'
      require 'alterpath/version'

      puts "Alterpath version: #{VERSION}"
      puts "WinPathUtils version: #{WinPathUtils::VERSION}"

      exit
    end

    command 'append' do
      description "Adds the specified path to the end of system PATH variable."
      banner "Usage: #{appname} append [-f] path"
      on :f, :force, "Add even if already found in PATH."
      run &Alterpath::CLI.method(:append)
    end

    command 'prepend' do
      description "Adds the specified path to the beginning of system PATH variable."
      banner "Usage: #{appname} prepend [-f] path"
      on :f, :force, "Add even if already found in PATH."
      run &Alterpath::CLI.method(:prepend)
    end

    command 'remove' do
      description "Removes the specified path from the system PATH variable."
      banner "Usage: #{appname} remove path"
      run &Alterpath::CLI.method(:remove)
    end

    command 'list' do
      description "Lists current system PATH variable, one entry per line."
      banner "Usage: #{appname} list"
      run &Alterpath::CLI.method(:list)
    end

    command 'get' do
      description "Prints current system PATH variable as is."
      banner "Usage: #{appname} get"
      run &Alterpath::CLI.method(:get)
    end
  end
  
  puts opts
end