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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6dffb69b6d7ecbf40ff96f3460f4eba28e2a0ac0996e3511ed632b59de086cb
4
- data.tar.gz: de5085e51ba4ebc9663a310e43e8d7d4f08d84ef506b943478ee26d1b0ed8757
3
+ metadata.gz: cafb81708017c1ce6aaa88f54211574a80d72c871061fa14204198a4132a2431
4
+ data.tar.gz: 47aeb2330a95c67ec6af3fffd0e80fda58e16708caad5e08303e678af9454110
5
5
  SHA512:
6
- metadata.gz: babbc5fa1b3bf7a54393ae11bdaffda0615227cdb807cefe98bcfbc19048a34c632de37ccdc41a39249b17af1d1fb1c05cf6861704be74fb92e3d5691501b5d2
7
- data.tar.gz: 363d6a11aef37e65d6cf182b293762958124ccf1b1f2a3c5b9ade2e15cd554f93e4c8e8c5784fc12d881a81bc50eef2f80ffff1f4f1892d32b74294199e65884
6
+ metadata.gz: e075f5ba6d493db81d068696a724e8ddaaac311b22dcb368e86552f43cf77e1a2051f7d55e2215b999d3580b9877406b6f0fde465d82f1d06a4d4dc7b5b78f99
7
+ data.tar.gz: 76fff37ad3a3e68793356d38702ff3b156e95f1ab3bd80aaf6e040b0622cedc606e4ae5fcb8d6c6977153d7d531ca42b2f02a4fec5331e18a9cf539f9bba40be
data/Gemfile CHANGED
@@ -1,6 +1,4 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'pry'
4
-
5
3
  # Specify your gem's dependencies in ripgrep.gemspec
6
4
  gemspec
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
- TODO: Write usage instructions here
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
 
@@ -8,4 +8,10 @@ module Ripgrep
8
8
  class CommandExecutionError < Error; end
9
9
  class NoMatchError < Error; end
10
10
  class ResultError < Error; end
11
+
12
+ class << self
13
+ def run(&block)
14
+ Client.new.run(&block)
15
+ end
16
+ end
11
17
  end
@@ -4,7 +4,31 @@ module Ripgrep
4
4
  class Client
5
5
  extend Forwardable
6
6
 
7
- def_delegators Core, :exec, :version, :help
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
- Core.exec(*args)
41
+ exec(*args, verbose: @verbose)
18
42
  end
19
43
  end
20
44
  end
@@ -2,18 +2,10 @@ require 'open3'
2
2
 
3
3
  module Ripgrep
4
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])
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
@@ -1,3 +1,3 @@
1
1
  module Ripgrep
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.1'
3
3
  end
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "bundler", "~> 2.0"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
27
  spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "pry"
28
29
  end
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.0
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-06 00:00:00.000000000 Z
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: []