Module: Alterpath::CLI
- Defined in:
- lib/alterpath/cli.rb
Class Method Summary collapse
- .append(opts, args) ⇒ Object
- .get(opts, args) ⇒ Object
- .get_addition_options(opts) ⇒ Object
- .list(opts, args) ⇒ Object
- .path ⇒ Object
- .prepend(opts, args) ⇒ Object
- .remove(opts, args) ⇒ Object
- .start ⇒ Object
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, (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 (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 |
.path ⇒ Object
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, (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 |
.start ⇒ Object
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 "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." "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." "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." "Usage: #{appname} remove path" run &Alterpath::CLI.method(:remove) end command 'list' do description "Lists current system PATH variable, one entry per line." "Usage: #{appname} list" run &Alterpath::CLI.method(:list) end command 'get' do description "Prints current system PATH variable as is." "Usage: #{appname} get" run &Alterpath::CLI.method(:get) end end puts opts end |