ripgrep 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -2
- data/README.md +59 -4
- data/lib/ripgrep.rb +6 -0
- data/lib/ripgrep/client.rb +26 -2
- data/lib/ripgrep/core.rb +3 -11
- data/lib/ripgrep/version.rb +1 -1
- data/ripgrep.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cafb81708017c1ce6aaa88f54211574a80d72c871061fa14204198a4132a2431
|
4
|
+
data.tar.gz: 47aeb2330a95c67ec6af3fffd0e80fda58e16708caad5e08303e678af9454110
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e075f5ba6d493db81d068696a724e8ddaaac311b22dcb368e86552f43cf77e1a2051f7d55e2215b999d3580b9877406b6f0fde465d82f1d06a4d4dc7b5b78f99
|
7
|
+
data.tar.gz: 76fff37ad3a3e68793356d38702ff3b156e95f1ab3bd80aaf6e040b0622cedc606e4ae5fcb8d6c6977153d7d531ca42b2f02a4fec5331e18a9cf539f9bba40be
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
**This is under development!**
|
2
|
-
|
3
1
|
# ripgrep-ruby
|
4
2
|
|
5
3
|
A Ruby wrapper around [ripgrep](https://github.com/BurntSushi/ripgrep)!
|
@@ -22,7 +20,64 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
```ruby
|
24
|
+
require 'ripgrep'
|
25
|
+
|
26
|
+
rg = Ripgrep::Client.new
|
27
|
+
|
28
|
+
### return the version like `rg --version`
|
29
|
+
puts rg.version
|
30
|
+
# =>
|
31
|
+
# ripgrep 11.0.1
|
32
|
+
# -SIMD -AVX (compiled)
|
33
|
+
# +SIMD +AVX (runtime)
|
34
|
+
|
35
|
+
### Search like `rg require lib`
|
36
|
+
result = rg.exec 'require', path: 'lib'
|
37
|
+
puts result
|
38
|
+
# =>
|
39
|
+
# lib/ripgrep.rb:require 'ripgrep/version'
|
40
|
+
# lib/ripgrep.rb:require 'ripgrep/core'
|
41
|
+
# lib/ripgrep.rb:require 'ripgrep/client'
|
42
|
+
# lib/ripgrep.rb:require 'ripgrep/result'
|
43
|
+
# lib/ripgrep/client.rb:require 'forwardable'
|
44
|
+
# lib/ripgrep/core.rb:require 'open3'
|
45
|
+
|
46
|
+
puts result.matches
|
47
|
+
# =>
|
48
|
+
# {:file=>"lib/ripgrep.rb", :body=>"require 'ripgrep/version'"}
|
49
|
+
# {:file=>"lib/ripgrep.rb", :body=>"require 'ripgrep/core'"}
|
50
|
+
# {:file=>"lib/ripgrep.rb", :body=>"require 'ripgrep/client'"}
|
51
|
+
# {:file=>"lib/ripgrep.rb", :body=>"require 'ripgrep/result'"}
|
52
|
+
# {:file=>"lib/ripgrep/client.rb", :body=>"require 'forwardable'"}
|
53
|
+
# {:file=>"lib/ripgrep/core.rb", :body=>"require 'open3'"}
|
54
|
+
|
55
|
+
### Search like `rg --ignore-case ruby ripgrep.gemspec`
|
56
|
+
result = rg.exec 'ruby', path: 'ripgrep.gemspec', options: { ignore_case: true }
|
57
|
+
puts result
|
58
|
+
# =>
|
59
|
+
# spec.summary = "A Ruby wrapper around ripgrep!"
|
60
|
+
# spec.description = "A Ruby wrapper around ripgrep!"
|
61
|
+
# spec.homepage = "https://github.com/shuuuuun/ripgrep-ruby"
|
62
|
+
# # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
63
|
+
|
64
|
+
### You can use `rg` method in run block.
|
65
|
+
rg.run do
|
66
|
+
result = rg '--ignore-case', 'ruby'
|
67
|
+
puts result
|
68
|
+
end
|
69
|
+
|
70
|
+
Ripgrep.run do
|
71
|
+
result = rg '--ignore-case', 'ruby'
|
72
|
+
puts result
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
## Links
|
77
|
+
|
78
|
+
* Original: https://github.com/BurntSushi/ripgrep
|
79
|
+
* GitHub: https://github.com/shuuuuun/ripgrep-ruby
|
80
|
+
* RubyGems: https://rubygems.org/gems/ripgrep
|
26
81
|
|
27
82
|
## Development
|
28
83
|
|
@@ -32,7 +87,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
87
|
|
33
88
|
## Contributing
|
34
89
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/shuuuuun/ripgrep.
|
90
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/shuuuuun/ripgrep-ruby.
|
36
91
|
|
37
92
|
## License
|
38
93
|
|
data/lib/ripgrep.rb
CHANGED
data/lib/ripgrep/client.rb
CHANGED
@@ -4,7 +4,31 @@ module Ripgrep
|
|
4
4
|
class Client
|
5
5
|
extend Forwardable
|
6
6
|
|
7
|
-
def_delegators Core, :
|
7
|
+
def_delegators Core, :version, :help
|
8
|
+
|
9
|
+
def initialize(verbose: false)
|
10
|
+
@verbose = verbose
|
11
|
+
end
|
12
|
+
|
13
|
+
def exec(*args, opts)
|
14
|
+
unless opts.is_a? Hash
|
15
|
+
args << opts
|
16
|
+
opts = {}
|
17
|
+
end
|
18
|
+
verbose = opts[:verbose].nil? ? @verbose : !!opts[:verbose]
|
19
|
+
cli_options = opts[:options]&.map do |key, val|
|
20
|
+
next unless val
|
21
|
+
val = '' if val.is_a? TrueClass
|
22
|
+
val = val.join if val.is_a? Array
|
23
|
+
key = key.to_s.tr('_', '-')
|
24
|
+
"--#{key} #{val}".strip
|
25
|
+
end&.compact || []
|
26
|
+
puts "cli_options: #{cli_options}" if verbose
|
27
|
+
cli_arguments = cli_options + args
|
28
|
+
cli_arguments << (opts[:path] || '.')
|
29
|
+
puts "cli_arguments: #{cli_arguments}" if verbose
|
30
|
+
Core.exec(*cli_arguments, verbose: verbose)
|
31
|
+
end
|
8
32
|
|
9
33
|
def run(&block)
|
10
34
|
instance_eval(&block)
|
@@ -14,7 +38,7 @@ module Ripgrep
|
|
14
38
|
|
15
39
|
def rg(*args)
|
16
40
|
return self if args.empty?
|
17
|
-
|
41
|
+
exec(*args, verbose: @verbose)
|
18
42
|
end
|
19
43
|
end
|
20
44
|
end
|
data/lib/ripgrep/core.rb
CHANGED
@@ -2,18 +2,10 @@ require 'open3'
|
|
2
2
|
|
3
3
|
module Ripgrep
|
4
4
|
class Core
|
5
|
-
def self.exec(*args,
|
6
|
-
|
7
|
-
|
8
|
-
opts = {}
|
9
|
-
end
|
10
|
-
# TODO: support cli options
|
11
|
-
opts = { path: '.' }.merge(opts)
|
12
|
-
# TODO: make debug logger
|
13
|
-
# puts "args: #{args}, opts: #{opts}"
|
14
|
-
stdout, stderr, status = Open3.capture3('rg', *args, opts[:path])
|
5
|
+
def self.exec(*args, verbose: false)
|
6
|
+
stdout, stderr, status = Open3.capture3('rg', *args)
|
7
|
+
puts "exit status: #{status.exitstatus}" if verbose
|
15
8
|
unless status.exited?
|
16
|
-
# puts "exit status: #{status.exitstatus}"
|
17
9
|
raise Ripgrep::CommandExecutionError, stderr
|
18
10
|
end
|
19
11
|
Result.new stdout, stderr, exit_status: status.exitstatus
|
data/lib/ripgrep/version.rb
CHANGED
data/ripgrep.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ripgrep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- motoki-shun
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: A Ruby wrapper around ripgrep!
|
56
70
|
email:
|
57
71
|
executables: []
|