Class: Sloc::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/sloc/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



6
7
8
# File 'lib/sloc/cli.rb', line 6

def initialize
  @options = {}
end

Instance Attribute Details

#optionsObject (readonly) Also known as: help

Returns the value of attribute options.



46
47
48
# File 'lib/sloc/cli.rb', line 46

def options
  @options
end

Instance Method Details

#help?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/sloc/cli.rb', line 49

def help?
  @paths.empty? || @options[:help]
end

#parse_options(args) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/sloc/cli.rb', line 35

def parse_options(args)
  opts = Slop.parse!(args) do |o|
    o.on('-h', '--help', 'Display this help message.')
    o.on('-o', '--order=', 'Specify key to order by.')
    o.on('--desc', 'Reverse order if specified')
    o.on('-l', '--limit=', 'Specify key to set limitation of displaying file number.')
  end

  [opts, args]
end

#report(args = ARGV) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/sloc/cli.rb', line 19

def report(args = ARGV)
  setup(args)
  if help?
    help
  else
    @runner.report(@paths)
  end
end

#run(args = ARGV) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/sloc/cli.rb', line 10

def run(args = ARGV)
  setup(args)
  if help?
    puts help
  else
    puts @runner.run(@paths)
  end
end

#setup(args) ⇒ Object



28
29
30
31
32
33
# File 'lib/sloc/cli.rb', line 28

def setup(args)
  @options, @paths = parse_options(args)
  @runner = Runner.new(@options)

  nil
end