starscope 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,18 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
- v0.1.4 (trunk)
4
+ v0.1.5 (trunk)
5
+ -------------------
6
+
7
+ New Features:
8
+ * Add --no-progress option to hide progress-bar.
9
+
10
+ Misc:
11
+ * Explicitly print "No results found" to avoid mysterious empty output.
12
+ * Recognize ruby files with a #!ruby line but no .rb suffix.
13
+ * Help output now fits in 80-column terminal.
14
+
15
+ v0.1.4 (2014-01-05)
5
16
  -------------------
6
17
 
7
18
  New Features:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- starscope (0.1.4)
4
+ starscope (0.1.5)
5
5
  oj (~> 2.5)
6
6
  parser (~> 2.1)
7
7
  ruby-progressbar (~> 1.4)
data/README.md CHANGED
@@ -1,15 +1,16 @@
1
1
  StarScope
2
2
  =========
3
3
 
4
- https://rubygems.org/gems/starscope
4
+ [![Gem Version](https://badge.fury.io/rb/starscope.png)](http://badge.fury.io/rb/starscope)
5
5
 
6
6
  Anyone who has done much programming in C (or C++) on a unix-based OS has come
7
- across the fantastic Cscope tool [1]. Sadly, it only works for C (and sort of
8
- works for C++).
7
+ across the fantastic [Cscope](http://cscope.sourceforge.net/) tool. Sadly, it
8
+ only works for C (and sort of works for C++).
9
9
 
10
- StarScope is a similar tool for Ruby and Go, with a design intended to make it
11
- easy to add support for other languages at some point within the same framework
12
- (thus the name StarScope, ie \*scope).
10
+ StarScope is a similar tool for [Ruby](https://www.ruby-lang.org/) and
11
+ [Golang](http://golang.org/), with a design intended to make it easy to add
12
+ support for other languages at some point within the same framework (thus the
13
+ name StarScope, ie \*scope).
13
14
 
14
15
  Install it as a gem:
15
16
  ```
@@ -35,5 +36,3 @@ or
35
36
  ```
36
37
  $ starscope -e cscope
37
38
  ```
38
-
39
- [1] http://cscope.sourceforge.net/
data/TODO.md CHANGED
@@ -1,7 +1,6 @@
1
1
  TODO
2
2
  =========
3
3
 
4
- * Add --quiet to hide progress bar and --verbose to print each file
5
4
  * Parallelization, perhaps via https://github.com/grosser/parallel
6
5
  * Fuzzy matching, perhaps via https://github.com/seamusabshere/fuzzy_match
7
6
  * Export advanced ctags annotations
@@ -7,15 +7,15 @@ require 'optparse'
7
7
  require 'readline'
8
8
  require 'starscope'
9
9
 
10
- options = {auto: true}
10
+ options = {auto: true, progress: true}
11
11
  DEFAULT_DB=".starscope.db"
12
12
 
13
13
  # Options Parsing
14
14
  OptionParser.new do |opts|
15
15
  opts.banner = <<END
16
- Usage: starscope.rb [options] [PATHS]
16
+ Usage: starscope [options] [PATHS]
17
17
 
18
- If you don't pass any of -n, -r, -w or PATHS the default behaviour is to recurse
18
+ If you don't pass any of -n, -r, -w or PATHS, default behaviour is to recurse
19
19
  in the current directory and build or update the database `#{DEFAULT_DB}`.
20
20
 
21
21
  Query scopes must be specified with `::`, for example -q calls,File::mtime.
@@ -36,16 +36,16 @@ END
36
36
  end
37
37
 
38
38
  opts.separator "\nDatabase Management"
39
- opts.on("-e", "--export FORMAT[,PATH]", "Export in FORMAT to PATH, see EXPORTING below") do |export|
39
+ opts.on("-e", "--export FORMAT[,PATH]", "Export in FORMAT to PATH, (see EXPORTING)") do |export|
40
40
  options[:export] = export
41
41
  end
42
- opts.on("-n", "--no-auto", "Don't automatically update/create the database") do
42
+ opts.on("-n", "--no-auto", "Don't automatically update/create the DB") do
43
43
  options[:auto] = false
44
44
  end
45
- opts.on("-r", "--read-db PATH", "Reads the DB from PATH instead of the default") do |path|
45
+ opts.on("-r", "--read-db PATH", "Reads the DB from PATH instead of default") do |path|
46
46
  options[:read] = path
47
47
  end
48
- opts.on("-w", "--write-db PATH", "Writes the DB to PATH instead of the default") do |path|
48
+ opts.on("-w", "--write-db PATH", "Writes the DB to PATH instead of default") do |path|
49
49
  options[:write] = path
50
50
  end
51
51
 
@@ -54,12 +54,15 @@ END
54
54
  puts StarScope::VERSION
55
55
  exit
56
56
  end
57
+ opts.on("--no-progress", "Don't show progress-bar when updating DB") do
58
+ options[:progress] = false
59
+ end
57
60
 
58
61
  opts.separator <<END
59
62
  \nEXPORTING
60
- At the moment two export formats are supported: 'ctags' and 'cscope'. If you
61
- don't specify a path, the output is written to the files 'tags' (for ctags)
62
- or 'cscope.out' (for cscope) in the current directory.
63
+ At the moment two export formats are supported: 'ctags' and 'cscope'. If
64
+ you don't specify a path, the output is written to the files 'tags' (for
65
+ ctags) or 'cscope.out' (for cscope) in the current directory.
63
66
  END
64
67
 
65
68
  end.parse!
@@ -76,7 +79,11 @@ def run_query(db, table, value)
76
79
  return false
77
80
  end
78
81
  key, results = db.query(table.to_sym, value)
79
- puts results.map {|val| StarScope::Datum.to_s(val)} if results
82
+ if results
83
+ puts results.map {|val| StarScope::Datum.to_s(val)}
84
+ else
85
+ puts "No results found."
86
+ end
80
87
  return true
81
88
  rescue StarScope::DB::NoTableError
82
89
  $stderr.puts "Table '#{table}' doesn't exist."
@@ -104,7 +111,7 @@ if File.exists?(DEFAULT_DB) and not options[:read]
104
111
  options[:read] = DEFAULT_DB
105
112
  end
106
113
 
107
- db = StarScope::DB.new
114
+ db = StarScope::DB.new(options[:progress])
108
115
 
109
116
  if options[:read]
110
117
  db.load(options[:read])
@@ -19,7 +19,8 @@ class StarScope::DB
19
19
  class NoTableError < StandardError; end
20
20
  class UnknownDBFormatError < StandardError; end
21
21
 
22
- def initialize
22
+ def initialize(progress)
23
+ @progress = progress
23
24
  @paths = []
24
25
  @files = {}
25
26
  @tables = {}
@@ -64,24 +65,28 @@ class StarScope::DB
64
65
  @paths += paths
65
66
  files = paths.map {|p| self.class.files_from_path(p)}.flatten
66
67
  return if files.empty?
67
- pbar = ProgressBar.create(title: "Building", total: files.length, format: PBAR_FORMAT, length: 80)
68
+ if @progress
69
+ pbar = ProgressBar.create(title: "Building", total: files.length, format: PBAR_FORMAT, length: 80)
70
+ end
68
71
  files.each do |f|
69
72
  add_file(f)
70
- pbar.increment
73
+ pbar.increment if @progress
71
74
  end
72
75
  end
73
76
 
74
77
  def update
75
78
  new_files = (@paths.map {|p| self.class.files_from_path(p)}.flatten) - @files.keys
76
- pbar = ProgressBar.create(title: "Updating", total: new_files.length + @files.length, format: PBAR_FORMAT, length: 80)
79
+ if @progress
80
+ pbar = ProgressBar.create(title: "Updating", total: new_files.length + @files.length, format: PBAR_FORMAT, length: 80)
81
+ end
77
82
  changed = @files.keys.map do |f|
78
83
  changed = update_file(f)
79
- pbar.increment
84
+ pbar.increment if @progress
80
85
  changed
81
86
  end
82
87
  new_files.each do |f|
83
88
  add_file(f)
84
- pbar.increment
89
+ pbar.increment if @progress
85
90
  end
86
91
  changed.any? || !new_files.empty?
87
92
  end
@@ -3,7 +3,10 @@ require "parser/current"
3
3
  module StarScope::Lang
4
4
  module Ruby
5
5
  def self.match_file(name)
6
- name =~ /.*\.rb$/
6
+ return true if name =~ /.*\.rb$/
7
+ return File.open(name) {|f| f.readline} =~ /^#!.*ruby/
8
+ rescue ArgumentError # may occur if file is binary (invalid UTF)
9
+ false
7
10
  end
8
11
 
9
12
  def self.extract(file, &block)
@@ -1,3 +1,3 @@
1
1
  module StarScope
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -4,7 +4,7 @@ Gem::Specification.new do |gem|
4
4
  gem.name = 'starscope'
5
5
  gem.version = StarScope::VERSION
6
6
  gem.summary = "A code indexer and analyzer"
7
- gem.description = "A tool like the venerable cscope, but for ruby, go and other languages"
7
+ gem.description = "A tool like the venerable cscope, but for ruby, golang and other languages"
8
8
  gem.authors = ["Evan Huus"]
9
9
  gem.homepage = 'https://github.com/eapache/starscope'
10
10
  gem.email = 'eapache@gmail.com'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: starscope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -123,7 +123,7 @@ dependencies:
123
123
  - - ! '>='
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
- description: A tool like the venerable cscope, but for ruby, go and other languages
126
+ description: A tool like the venerable cscope, but for ruby, golang and other languages
127
127
  email: eapache@gmail.com
128
128
  executables:
129
129
  - starscope
@@ -144,7 +144,6 @@ files:
144
144
  - lib/starscope/db.rb
145
145
  - lib/starscope/langs/go.rb
146
146
  - lib/starscope/langs/ruby.rb
147
- - lib/starscope/value.rb
148
147
  - lib/starscope/version.rb
149
148
  - starscope.gemspec
150
149
  homepage: https://github.com/eapache/starscope
@@ -1,7 +0,0 @@
1
- class StarScope::Value
2
- attr_reader :simple
3
-
4
- def initialize(simple)
5
- @simple = simple
6
- end
7
- end