Module: RipperTags
- Defined in:
- lib/ripper-tags.rb,
lib/ripper-tags/parser.rb,
lib/ripper-tags/data_reader.rb,
lib/ripper-tags/vim_formatter.rb,
lib/ripper-tags/json_formatter.rb,
lib/ripper-tags/emacs_formatter.rb,
lib/ripper-tags/default_formatter.rb
Defined Under Namespace
Classes: DataReader, DefaultFormatter, EmacsFormatter, FileFinder, JSONFormatter, Parser, VimFormatter, Visitor
Constant Summary collapse
- FatalError =
Class.new(RuntimeError)
- BrokenPipe =
Class.new(RuntimeError)
Class Method Summary collapse
- .default_options ⇒ Object
- .formatter_for(options) ⇒ Object
- .option_parser(options) ⇒ Object
- .process_args(argv, run = method(:run)) ⇒ Object
- .run(options) ⇒ Object
- .version ⇒ Object
Class Method Details
.default_options ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ripper-tags.rb', line 16 def self. OpenStruct.new \ :format => nil, :extra_flags => Set.new, :tag_file_name => "./tags", :tag_relative => nil, :debug => false, :verbose_debug => false, :verbose => false, :force => false, :files => %w[.], :recursive => false, :exclude => %w[.git], :all_files => false end |
.formatter_for(options) ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ripper-tags.rb', line 130 def self.formatter_for() .formatter || case .format when "vim" then RipperTags::VimFormatter when "emacs" then RipperTags::EmacsFormatter when "json" then RipperTags::JSONFormatter when "custom" then RipperTags::DefaultFormatter else raise FatalError, "unknown format: #{options.format.inspect}" end.new() end |
.option_parser(options) ⇒ Object
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ripper-tags.rb', line 32 def self.option_parser() OptionParser.new do |opts| opts. = "Usage: #{opts.program_name} [options] FILES..." opts.version = version opts.separator "" opts.on("-f", "--tag-file (FILE|-)", "File to write tags to (default: `#{options.tag_file_name}')", '"-" outputs to standard output') do |fname| .tag_file_name = fname end opts.on("--tag-relative[=OPTIONAL]", "Make file paths relative to the directory of the tag file") do |value| .tag_relative = value != "no" end opts.on("-R", "--recursive", "Descend recursively into subdirectories") do .recursive = true end opts.on("--exclude PATTERN", "Exclude a file, directory or pattern") do |pattern| if pattern.empty? .exclude.clear else .exclude << pattern end end opts.on("--all-files", "Parse all files as ruby files, not just `*.rb' ones") do .all_files = true end opts.separator " " opts.on("--format (emacs|json|custom)", "Set output format (default: vim)") do |fmt| .format = fmt end opts.on("-e", "--emacs", "Output Emacs format (default if `--tag-file' is `TAGS')") do .format = "emacs" end opts.on("--extra=FLAGS", "Specify extra flags for the formatter") do |flags| flags = flags.split("") operation = :add if flags[0] == "+" || flags[0] == "-" operation = :delete if flags.shift == "-" else .extra_flags.clear end flags.each { |f| .extra_flags.send(operation, f) } end opts.separator "" opts.on_tail("-d", "--debug", "Output parse tree") do .debug = true end opts.on_tail("--debug-verbose", "Output parse tree verbosely") do .verbose_debug = true end opts.on_tail("-V", "--verbose", "Print additional information on stderr") do .verbose = true end opts.on_tail("--force", "Skip files with parsing errors") do .force = true end opts.on_tail("--list-kinds=LANG", "Print tag kinds that this parser supports and exit") do |lang| if lang.downcase == "ruby" puts((" c classes\n f methods\n m modules\n F singleton methods\n C constants\n a aliases\n OUT\n exit\n else\n $stderr.puts \"Error: language %p is not supported\" % lang\n exit 1\n end\n end\n opts.on_tail(\"-v\", \"--version\", \"Print version information\") do\n puts opts.ver\n exit\n end\n\n yield(opts, options) if block_given?\n end\nend\n").gsub(/^ +/, '')) |
.process_args(argv, run = method(:run)) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ripper-tags.rb', line 118 def self.process_args(argv, run = method(:run)) option_parser() do |optparse, | file_list = optparse.parse(argv) if !file_list.empty? then .files = file_list elsif !.recursive then abort(optparse.) end .format ||= File.basename(.tag_file_name) == "TAGS" ? "emacs" : "vim" .tag_relative = .format == "emacs" if .tag_relative.nil? return run.call() end end |
.run(options) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/ripper-tags.rb', line 141 def self.run() reader = RipperTags::DataReader.new() formatter = formatter_for() formatter.with_output do |out| reader.each_tag do |tag| formatter.write(tag, out) end end rescue FatalError => err $stderr.puts "%s: %s" % [ File.basename($0), err. ] exit 1 end |
.version ⇒ Object
12 |
# File 'lib/ripper-tags.rb', line 12 def self.version() "0.3.2" end |