pathspec 0.1.1 → 1.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
- SHA1:
3
- metadata.gz: 326cb387706e8df95bce9c259781ab7101e94163
4
- data.tar.gz: 403d0e22353ce7efe78bd805c4b387813d548097
2
+ SHA256:
3
+ metadata.gz: 0ae83043af9e6984a10ace1624b0503945430ae4c5421537bb8f9213cc01b3a2
4
+ data.tar.gz: 9b2905b1fca91f0ce7ee38523aa02aff2f8b08f15c960e091538e0ddff403676
5
5
  SHA512:
6
- metadata.gz: 675179bbf0e44eef814732e015545c8ea27ae99eab0b572337e127ddb68124e7e903853081a8613d937055b557a0fc1d032899f908cc7a856b215e29e0044e81
7
- data.tar.gz: ef1446b84a159f3646802e61981ff84d61bf2b08311dcd214687977a062b5c6a30d6ed95eb4afbe1b052a08190460a0d1bdc147c792ca988760fbc9c8618e2d9
6
+ metadata.gz: a32f8a1bd4ccf9105ea69ac78a977a74ddea46cb49d6c414c4fbb7631fb7002d0d52fe6731bb8969a599b61f652a0ed37ba224da0415cbcf361abd54b53e7fe4
7
+ data.tar.gz: ce42052b1af7f4c26581068c9d43a407715f80276120fa9d8500def845e27d7d4013ed87db5ea4662155708e02fd32f3bc43f12c9349baa5a34d33661d9a4d43
data/CHANGELOG.md CHANGED
@@ -1,11 +1,31 @@
1
1
  # pathspec-ruby CHANGELOG
2
2
 
3
- ## 0.1.0
3
+ ## 1.1.0 (Minor Release)
4
+
5
+ - (Maint) Updated Supported Ruby Versions
6
+ - (Maint) Linting corrections
7
+
8
+ ## Undocumented Releases (Sorry!)
9
+
10
+ ## 0.2.0 (Minor Release)
11
+ - (Feature) A CLI tool, pathspec-rb, is now provided with the gem.
12
+ - (API Change) New namespace for gem: `PathSpec`: Everything is now namespaced under `PathSpec`, to prevent naming collisions with other libraries. Thanks @tenderlove!
13
+ - (License) License version updated to Apache 2. Thanks @kytrinyx!
14
+ - (Maint) Pruned Supported Ruby Versions. We now test: 2.2.9, 2.3.6 and 2.4.3.
15
+ - (Maint) Ruby 2.5.0 testing is blocked on Travis, but should work locally. Thanks @SumLare!
16
+ - (Maint) Added Rubocop and made some corrections
17
+
18
+ ## 0.1.2 (Patch/Bug Fix Release)
19
+ - Fix for regexp matching Thanks @incase! #16
20
+ - File handling cleanup Thanks @martinandert! #13
21
+ - `from_filename` actually works now! Thanks @martinandert! #12
22
+
23
+ ## 0.1.0 (Minor Release)
4
24
  - Port new edgecase handling from [python-path-specification](https://github.com/cpburnz/python-path-specification/pull/8). Many thanks to @jdpace! :)
5
25
  - Removed EOL Ruby support
6
26
  - Added current Ruby stable to Travis testing
7
27
 
8
- ## 0.0.2
28
+ ## 0.0.2 (Patch/Bug Fix Release)
9
29
  - Fixed issues with Ruby 1.8.7/2.1.1
10
30
  - Added more testing scripts
11
31
  - Fixed Windows path related issues
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
- pathspec-ruby
2
- =============
1
+ # pathspec-ruby
3
2
 
4
- [![Build Status](https://travis-ci.org/highb/pathspec-ruby.svg?branch=master)](https://travis-ci.org/highb/pathspec-ruby) [![codecov](https://codecov.io/gh/highb/pathspec-ruby/branch/master/graph/badge.svg)](https://codecov.io/gh/highb/pathspec-ruby)
3
+ [![Gem Version](https://badge.fury.io/rb/pathspec.svg)](https://badge.fury.io/rb/pathspec) [![Build Status](https://travis-ci.org/highb/pathspec-ruby.svg?branch=master)](https://travis-ci.org/highb/pathspec-ruby) [![Maintainability](https://api.codeclimate.com/v1/badges/4f3b5917e01fb34f790d/maintainability)](https://codeclimate.com/github/highb/pathspec-ruby/maintainability)
5
4
 
6
- Supported Rubies:
7
- - 2.2.7 (Maintenance)
8
- - 2.3.4 (Stable)
9
- - 2.4.1 (Stable)
5
+ [man Page as HTML](http://highb.github.io/pathspec-ruby/)
6
+
7
+ [Supported Rubies](https://www.ruby-lang.org/en/downloads/):
8
+
9
+ - 2.6 (Security Maintenance)
10
+ - 2.7 (Stable, Tested)
11
+ - 3.0 (Stable, Tested)
10
12
 
11
13
  Match Path Specifications, such as .gitignore, in Ruby!
12
14
 
@@ -15,18 +17,41 @@ Follows .gitignore syntax defined on [gitscm](http://git-scm.com/docs/gitignore)
15
17
  .gitignore functionality ported from [Python pathspec](https://pypi.python.org/pypi/pathspec/0.2.2) by [@cpburnz](https://github.com/cpburnz/python-path-specification)
16
18
 
17
19
  ## Build/Install from Rubygems
20
+
18
21
  ```shell
19
22
  gem install pathspec
20
23
  ```
21
24
 
25
+ ## CLI Usage
26
+
27
+ ```bash
28
+ ➜ cat .gitignore
29
+ *.swp
30
+ /coverage/
31
+ ➜ bundle exec pathspec-rb specs_match "coverage/foo"
32
+ /coverage/
33
+ ➜ bundle exec pathspec-rb specs_match "file.swp"
34
+ *.swp
35
+ ➜ bundle exec pathspec-rb match "file.swp"
36
+ ➜ echo $?
37
+ 0
38
+ ➜ ls
39
+ Gemfile Gemfile.lock coverage file.swp source.rb
40
+ ➜ bundle exec pathspec-rb tree .
41
+ ./coverage
42
+ ./coverage/index.html
43
+ ./file.swp
44
+ ```
45
+
22
46
  ## Usage
47
+
23
48
  ```ruby
24
49
  require 'pathspec'
25
50
 
26
51
  # Create a .gitignore-style Pathspec by giving it newline separated gitignore
27
52
  # lines, an array of gitignore lines, or any other enumable object that will
28
53
  # give strings matching the .gitignore-style (File, etc.)
29
- gitignore = Pathspec.new File.read('.gitignore', 'r')
54
+ gitignore = PathSpec.from_filename('spec/files/gitignore_readme')
30
55
 
31
56
  # Our .gitignore in this example contains:
32
57
  # !**/important.txt
@@ -34,25 +59,61 @@ gitignore = Pathspec.new File.read('.gitignore', 'r')
34
59
 
35
60
  # true, matches "abc/**"
36
61
  gitignore.match 'abc/def.rb'
62
+ # CLI equivalent: pathspec.rb -f spec/files/gitignore_readme match 'abc/def.rb'
37
63
 
38
64
  # false, because it has been negated using the line "!**/important.txt"
39
65
  gitignore.match 'abc/important.txt'
66
+ # CLI equivalent: pathspec.rb -f spec/files/gitignore_readme match 'abc/important.txt'
40
67
 
41
68
  # Give a path somewhere in the filesystem, and the Pathspec will return all
42
69
  # matching files underneath.
43
70
  # Returns ['/src/repo/abc/', '/src/repo/abc/123']
44
71
  gitignore.match_tree '/src/repo'
72
+ # CLI equivalent: pathspec.rb -f spec/files/gitignore_readme tree /src/repo
45
73
 
46
74
  # Give an enumerable of paths, and Pathspec will return the ones that match.
47
75
  # Returns ['/abc/123', '/abc/']
48
76
  gitignore.match_paths ['/abc/123', '/abc/important.txt', '/abc/']
77
+ # There is no CLI equivalent to this.
78
+ ```
79
+
80
+ ## Example Usage in Gemspec
81
+
82
+ ```
83
+ lib = File.expand_path("lib", __dir__)
84
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
85
+ require "gemspec_pathspec_test/version"
86
+ require 'pathspec'
87
+
88
+ Gem::Specification.new do |spec|
89
+ spec.name = "gemspec_pathspec_test"
90
+ spec.version = GemspecPathspecTest::VERSION
91
+ spec.authors = ["Brandon High"]
92
+ spec.email = ["highb@users.noreply.github.com"]
93
+
94
+ spec.summary = "whatever"
95
+
96
+ spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
97
+
98
+ ps = PathSpec.from_filename('.gitignore')
99
+ spec.files = Dir['lib/*.rb'].reject { |f| ps.match(f) }
100
+ spec.bindir = "exe"
101
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
102
+ spec.require_paths = ["lib"]
103
+
104
+ spec.add_development_dependency "bundler", "~> 2.0"
105
+ spec.add_development_dependency "rake", "~> 10.0"
106
+ spec.add_development_dependency "rspec", "~> 3.0"
107
+ end
49
108
  ```
50
109
 
51
110
  ## Building/Installing from Source
111
+
52
112
  ```shell
53
113
  git clone git@github.com:highb/pathspec-ruby.git
54
114
  cd pathspec-ruby && bash ./build_from_source.sh
55
115
  ```
56
116
 
57
117
  ## Contributing
118
+
58
119
  Pull requests, bug reports, and feature requests welcome! :smile: I've tried to write exhaustive tests but who knows what cases I've missed.
data/bin/pathspec-rb ADDED
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'optionparser'
5
+ require 'pathspec'
6
+ options = {
7
+ spec_type: :git,
8
+ spec_filename: '.gitignore'
9
+ }
10
+
11
+ optparser = OptionParser.new do |opts|
12
+ opts.banner = 'Usage: pathspec-rb [options] [subcommand] [path]
13
+ Subcommands:
14
+ specs_match: Finds all specs matching path.
15
+ tree: Finds all files under path matching the spec.
16
+ match: Checks if the path matches any spec.
17
+ EXIT STATUS:
18
+ 0 Matches found.
19
+ 1 No matches found.
20
+ >1 An error occured.
21
+ '
22
+ opts.on('-f', '--file FILENAME', String,
23
+ 'A spec file to load. Default: .gitignore') do |filename|
24
+ unless File.readable?(filename)
25
+ puts "Error: I couldn't read #{filename}"
26
+ exit 2
27
+ end
28
+
29
+ options[:spec_filename] = filename
30
+ end
31
+ opts.on('-t', '--type [git|regex]', %i[git regex],
32
+ 'Spec file type in FILENAME. Default: git. Available: git and regex.') do |type|
33
+ options[:spec_type] = type
34
+ end
35
+ opts.on('-v', '--verbose', 'Only output if there are matches.') do |_verbose|
36
+ options[:verbose] = true
37
+ end
38
+ end
39
+
40
+ optparser.parse!
41
+
42
+ command = ARGV[0]
43
+ path = ARGV[1]
44
+ if path
45
+ spec = PathSpec.from_filename(options[:spec_filename], options[:spec_type])
46
+ else
47
+ puts optparser.help
48
+ exit 2
49
+ end
50
+
51
+ case command
52
+ when 'specs_match'
53
+ if spec.match?(path)
54
+ puts "#{path} matches the following specs from #{options[:spec_filename]}:" if options[:verbose]
55
+ puts spec.specs_matching(path)
56
+ else
57
+ puts "#{path} does not match any specs from #{options[:spec_filename]}" if options[:verbose]
58
+ exit 1
59
+ end
60
+ when 'tree'
61
+ tree_matches = spec.match_tree(path)
62
+ if tree_matches.any?
63
+ puts "Files in #{path} that match #{options[:spec_filename]}" if options[:verbose]
64
+ puts tree_matches
65
+ else
66
+ puts "No file in #{path} matched #{options[:spec_filename]}" if options[:verbose]
67
+ exit 1
68
+ end
69
+ when 'match', ''
70
+ if spec.match?(path)
71
+ puts "#{path} matches a spec in #{options[:spec_filename]}" if options[:verbose]
72
+ else
73
+ puts "#{path} does not match any specs in #{options[:spec_filename]}" if options[:verbose]
74
+ exit 1
75
+ end
76
+ else
77
+ puts "Unknown sub-command #{command}."
78
+ puts optparser.help
79
+ exit 2
80
+ end
data/docs/index.html ADDED
@@ -0,0 +1,82 @@
1
+ <h1 id="pathspec-rb1">pathspec-rb(1)</h1>
2
+
3
+ <h2 data-date="2020/01/04" id="name">NAME</h2>
4
+
5
+ <p>pathspec - Test pathspecs against a specific path</p>
6
+
7
+ <h2 id="synopsis">SYNOPSIS</h2>
8
+
9
+ <p><code>pathspec-rb</code> [<code>OPTIONS</code>] [<code>SUBCOMMAND</code>] [<code>PATH</code>] NAME PATH</p>
10
+
11
+ <h2 id="description">DESCRIPTION</h2>
12
+
13
+ <p><code>pathspc-rb</code> is a tool that accompanies the pathspec-ruby library to help
14
+ you test what match results the library would find using path specs. You can
15
+ either find all specs matching a path, find all files matching specs, or
16
+ verify that a path would match any spec.</p>
17
+
18
+ <p>https://github.com/highb/pathspec-ruby</p>
19
+
20
+ <h2 id="sub-commands">SUB-COMMANDS</h2>
21
+
22
+ <table>
23
+ <thead>
24
+ <tr>
25
+ <th>Name</th>
26
+ <th>Description</th>
27
+ </tr>
28
+ </thead>
29
+ <tbody>
30
+ <tr>
31
+ <td><em>specs_match</em></td>
32
+ <td>Find all specs matching path</td>
33
+ </tr>
34
+ </tbody>
35
+ <tbody>
36
+ <tr>
37
+ <td><em>tree</em></td>
38
+ <td>Find all files under path matching the spec</td>
39
+ </tr>
40
+ </tbody>
41
+ <tbody>
42
+ <tr>
43
+ <td><em>match</em></td>
44
+ <td>Check if the path matches any spec</td>
45
+ </tr>
46
+ </tbody>
47
+ </table>
48
+
49
+ <h2 id="options">OPTIONS</h2>
50
+
51
+ <dl>
52
+ <dt><code>-f &lt;FILENAME&gt;</code>, <code>--file &lt;FILENAME&gt;</code></dt>
53
+ <dd>Load path specs from the file passed in as argument. If this option is not specified, <code>pathspec-rb</code> defaults to loading <code>.gitignore</code>.</dd>
54
+ <dt><code>-t [git|regex]</code>, <code>--type [git|regex]</code></dt>
55
+ <dd>Type of spec expected in the loaded specs file (see <code>-f</code> option). Defaults to <code>git</code>.</dd>
56
+ <dt><code>-v</code>, <code>--verbose</code></dt>
57
+ <dd>Only output if there are matches.</dd>
58
+ </dl>
59
+
60
+ <h2 id="example">EXAMPLE</h2>
61
+
62
+ <p>Find all files ignored by git under your source directory:</p>
63
+
64
+ <pre><code> $ pathspec-rb tree src/
65
+ </code></pre>
66
+
67
+ <p>List all spec rules that would match for the specified path:</p>
68
+
69
+ <pre><code> $ pathspec-rb specs_match build/
70
+ </code></pre>
71
+
72
+ <p>Check that a path matches at least one of the specs in a new version of a
73
+ gitignore file:</p>
74
+
75
+ <pre><code> $ pathspec-rb match -f .gitignore.new spec/fixtures/
76
+ </code></pre>
77
+
78
+ <h2 id="author">AUTHOR</h2>
79
+
80
+ <p>Brandon High highb@users.noreply.github.com</p>
81
+
82
+ <p>Gabriel Filion</p>
@@ -0,0 +1,64 @@
1
+ # pathspec-rb(1)
2
+
3
+ {:data-date="2020/01/04"}
4
+
5
+ ## NAME
6
+
7
+ pathspec - Test pathspecs against a specific path
8
+
9
+ ## SYNOPSIS
10
+
11
+ `pathspec-rb` [`OPTIONS`] [`SUBCOMMAND`] [`PATH`] NAME PATH
12
+
13
+ ## DESCRIPTION
14
+
15
+ `pathspc-rb` is a tool that accompanies the pathspec-ruby library to help
16
+ you test what match results the library would find using path specs. You can
17
+ either find all specs matching a path, find all files matching specs, or
18
+ verify that a path would match any spec.
19
+
20
+ https://github.com/highb/pathspec-ruby
21
+
22
+ ## SUB-COMMANDS
23
+
24
+ |-
25
+ | Name | Description
26
+ |-
27
+ | *specs_match* | Find all specs matching path
28
+ |-
29
+ | *tree* | Find all files under path matching the spec
30
+ |-
31
+ | *match* | Check if the path matches any spec
32
+ |-
33
+
34
+ ## OPTIONS
35
+
36
+ `-f <FILENAME>`, `--file <FILENAME>`
37
+ : Load path specs from the file passed in as argument. If this option is not specified, `pathspec-rb` defaults to loading `.gitignore`.
38
+
39
+ `-t [git|regex]`, `--type [git|regex]`
40
+ : Type of spec expected in the loaded specs file (see `-f` option). Defaults to `git`.
41
+
42
+ `-v`, `--verbose`
43
+ : Only output if there are matches.
44
+
45
+ ## EXAMPLE
46
+
47
+ Find all files ignored by git under your source directory:
48
+
49
+ $ pathspec-rb tree src/
50
+
51
+ List all spec rules that would match for the specified path:
52
+
53
+ $ pathspec-rb specs_match build/
54
+
55
+ Check that a path matches at least one of the specs in a new version of a
56
+ gitignore file:
57
+
58
+ $ pathspec-rb match -f .gitignore.new spec/fixtures/
59
+
60
+ ## AUTHOR
61
+
62
+ Brandon High highb@users.noreply.github.com
63
+
64
+ Gabriel Filion