Class: ARGV

Inherits:
Object show all
Defined in:
lib/epitools/core_ext/argv.rb

Class Method Summary collapse

Class Method Details

.argsObject



30
31
32
# File 'lib/epitools/core_ext/argv.rb', line 30

def args
  @args ? @args : opts && @args
end

.help?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/epitools/core_ext/argv.rb', line 21

def help?
  !!@opts["help"]
end

.on_help(&block) ⇒ Object



47
48
49
# File 'lib/epitools/core_ext/argv.rb', line 47

def on_help(&block)
  @help_handler = block
end

.optsObject



25
26
27
28
# File 'lib/epitools/core_ext/argv.rb', line 25

def opts
  parse! unless @opts
  @opts
end

.parseObject



16
17
18
19
# File 'lib/epitools/core_ext/argv.rb', line 16

def parse
  parse!
  [@opts, @args]
end

.parse!Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/epitools/core_ext/argv.rb', line 3

def parse!
  unless @opts or @args
    @opts, @args = partition { |arg| arg[/^--?\w{1,2}/].nil? }
    @opts = @opts.map { |opt| key, val = opt.strip(/^-+/).split("=") }.to_ostruct
    if @opts.help
      @help_handler.call
      exit
    end
  end

  [@opts, @args]
end

.pathsObject



34
35
36
# File 'lib/epitools/core_ext/argv.rb', line 34

def paths
  map(&:to_Path)
end

.paths_RObject Also known as: recursive_paths



38
39
40
41
42
43
44
# File 'lib/epitools/core_ext/argv.rb', line 38

def paths_R
  recursive_proc = proc do |paths|
    paths.map { |path| path.dir? ? the_expander.(path.ls_R) : path }
  end

  recursive_proc.(paths)
end

.regexes(escaped: true, case_sensitive: false) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/epitools/core_ext/argv.rb', line 51

def regexes(escaped: true, case_sensitive: false)
  if case_sensitive
    map { |arg| /#{escaped ? Regexp.escape(arg) : arg}/ } # NO 'i'
  else
    map { |arg| /#{escaped ? Regexp.escape(arg) : arg}/i }
  end
end