module Alterpath::CLI

Public Class Methods

append(opts, args) click to toggle source
# 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) click to toggle source
# File lib/alterpath/cli.rb, line 98
def get(opts, args)
  puts path.get
  exit
end
get_addition_options(opts) click to toggle source
# File lib/alterpath/cli.rb, line 62
def get_addition_options(opts)
  opts[:force] ? { duplication_filter: :none } : {}
end
list(opts, args) click to toggle source
# File lib/alterpath/cli.rb, line 93
def list(opts, args)
  puts *path.get_array
  exit
end
path() click to toggle source
# File lib/alterpath/cli.rb, line 58
def path
  @path ||= WinPathUtils::Path.new
end
prepend(opts, args) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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