Module: Jdepp::CLI

Defined in:
lib/jdepp/cli.rb,
lib/jdepp/cli/feedback.rb

Defined Under Namespace

Classes: Feedback

Class Method Summary collapse

Class Method Details

.cli(argv) ⇒ Object



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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/jdepp/cli.rb', line 9

def self.cli(argv)

   opts = {:feedback => Feedback.new([:action]), :locations => {}}

   end_of_options = argv.index("--")
   opts[:stdout] = end_of_options.nil?
   if not opts[:stdout] then
      if argv.length > 0 then
         opts[:recipient] = argv[end_of_options + 1..-1].join(" ")
      end
      argv = ARGV.first(end_of_options)
   end

   OptionParser.new do 
      |o|
      o.banner = "usage: jdepp.rb [options] FILE [FILE ...] [-- COMMAND]"
      o.on("-v", "--[no-]verbose", "i will provide extra detail about my activity.") do
         |v|
         if (v) then
            opts[:feedback].add_tag(:verbose)
         end
      end
      o.on("-n", "--[no-]dry-run", "i will report what i would do if i were to perform the specified work.") do
         |flag|
         if (flag) then
            opts[:feedback].add_tag(:dry_run)
         end
      end
      o.on("-q", "--quiet", "i will suppress as much commentary as possible.") do
         |flag|
         if (flag) then
            opts[:feedback].quiet
         end
      end
      o.on("-D", "--define=LOCATION", 'if provided with a specification of the form "PREFIX=PATH", i will substitute PREFIX: for PATH if encountered.') do
         |s|
         name, path = s.split("=", 2)
         opts[:locations][name] = Pathname.new(path)
      end
      o.on("-F","--feedback-tags=TAGS", "i will provide feedback related to the specified tags") do
         |tag_list|
         tags = tag_list.split(",")
         tags.each {|t| opts[:feedback].add_tag(t.to_sym)}
      end
      o.on("-a","--[no-]append-dependents", "i will append the dependents to the list of dependencies") do
         |flag|
         opts[:append_dependents] = flag
      end
      o.on("--[no-]trace", "i will show the ruby callstack should an exception occur.") do
         |flag|
         opts[:trace] = flag
      end
   end.parse!(argv)

   if opts.fetch(:trace, false) then
      parse(argv, opts)
   else
      begin
         parse(argv, opts)
      rescue Exception => e
         opts[:feedback].puts_if([:error]) {e.message}
      end
   end

end