ripgrep 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/lib/ripgrep.rb +11 -0
- data/lib/ripgrep/client.rb +20 -0
- data/lib/ripgrep/core.rb +30 -0
- data/lib/ripgrep/result.rb +41 -0
- data/lib/ripgrep/version.rb +3 -0
- data/ripgrep.gemspec +28 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c6dffb69b6d7ecbf40ff96f3460f4eba28e2a0ac0996e3511ed632b59de086cb
|
4
|
+
data.tar.gz: de5085e51ba4ebc9663a310e43e8d7d4f08d84ef506b943478ee26d1b0ed8757
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: babbc5fa1b3bf7a54393ae11bdaffda0615227cdb807cefe98bcfbc19048a34c632de37ccdc41a39249b17af1d1fb1c05cf6861704be74fb92e3d5691501b5d2
|
7
|
+
data.tar.gz: 363d6a11aef37e65d6cf182b293762958124ccf1b1f2a3c5b9ade2e15cd554f93e4c8e8c5784fc12d881a81bc50eef2f80ffff1f4f1892d32b74294199e65884
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 motoki-shun
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
**This is under development!**
|
2
|
+
|
3
|
+
# ripgrep-ruby
|
4
|
+
|
5
|
+
A Ruby wrapper around [ripgrep](https://github.com/BurntSushi/ripgrep)!
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ripgrep'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ripgrep
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/shuuuuun/ripgrep.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/ripgrep.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'ripgrep/version'
|
2
|
+
require 'ripgrep/core'
|
3
|
+
require 'ripgrep/client'
|
4
|
+
require 'ripgrep/result'
|
5
|
+
|
6
|
+
module Ripgrep
|
7
|
+
class Error < StandardError; end
|
8
|
+
class CommandExecutionError < Error; end
|
9
|
+
class NoMatchError < Error; end
|
10
|
+
class ResultError < Error; end
|
11
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Ripgrep
|
4
|
+
class Client
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def_delegators Core, :exec, :version, :help
|
8
|
+
|
9
|
+
def run(&block)
|
10
|
+
instance_eval(&block)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def rg(*args)
|
16
|
+
return self if args.empty?
|
17
|
+
Core.exec(*args)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/ripgrep/core.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module Ripgrep
|
4
|
+
class Core
|
5
|
+
def self.exec(*args, opts)
|
6
|
+
unless opts.is_a? Hash
|
7
|
+
args << opts
|
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])
|
15
|
+
unless status.exited?
|
16
|
+
# puts "exit status: #{status.exitstatus}"
|
17
|
+
raise Ripgrep::CommandExecutionError, stderr
|
18
|
+
end
|
19
|
+
Result.new stdout, stderr, exit_status: status.exitstatus
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.version
|
23
|
+
self.exec('--version').to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.help
|
27
|
+
self.exec('--help').to_s
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Ripgrep
|
2
|
+
class Result
|
3
|
+
module Status
|
4
|
+
SUCCESS = 0
|
5
|
+
NO_MATCH = 1
|
6
|
+
ERROR = 2
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :raw_result, :raw_error, :exit_status, :matches
|
10
|
+
|
11
|
+
def initialize(result, error = '', exit_status: 0)
|
12
|
+
@raw_result = result
|
13
|
+
@raw_error = error
|
14
|
+
@exit_status = exit_status
|
15
|
+
|
16
|
+
# TODO: skip when not matching result. like a help or version.
|
17
|
+
@matches = result.split("\n").map do |line|
|
18
|
+
# TODO: implement Match class. make more rich and useful interface.
|
19
|
+
file, *body = line.split(':')
|
20
|
+
{ file: file, body: body.join(':') }
|
21
|
+
end
|
22
|
+
|
23
|
+
case exit_status
|
24
|
+
when Status::SUCCESS
|
25
|
+
when Status::NO_MATCH
|
26
|
+
when Status::ERROR
|
27
|
+
raise Ripgrep::ResultError, error
|
28
|
+
else
|
29
|
+
raise Ripgrep::ResultError, error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def lines
|
34
|
+
@raw_result.to_s.split("\n")
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
@raw_result.to_s
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/ripgrep.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "ripgrep/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ripgrep"
|
8
|
+
spec.version = Ripgrep::VERSION
|
9
|
+
spec.authors = ["motoki-shun"]
|
10
|
+
|
11
|
+
spec.summary = "A Ruby wrapper around ripgrep!"
|
12
|
+
spec.description = "A Ruby wrapper around ripgrep!"
|
13
|
+
spec.homepage = "https://github.com/shuuuuun/ripgrep-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ripgrep
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- motoki-shun
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: A Ruby wrapper around ripgrep!
|
56
|
+
email:
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- ".gitignore"
|
62
|
+
- ".rspec"
|
63
|
+
- ".ruby-version"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- lib/ripgrep.rb
|
72
|
+
- lib/ripgrep/client.rb
|
73
|
+
- lib/ripgrep/core.rb
|
74
|
+
- lib/ripgrep/result.rb
|
75
|
+
- lib/ripgrep/version.rb
|
76
|
+
- ripgrep.gemspec
|
77
|
+
homepage: https://github.com/shuuuuun/ripgrep-ruby
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubygems_version: 3.0.3
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: A Ruby wrapper around ripgrep!
|
100
|
+
test_files: []
|