pathspec 0.1.2 → 1.1.3

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: f259b8f0d32109d62b9bbc1a0f6a96c34f607cf9
4
- data.tar.gz: 551a347443c3e6017eccee1b3ce7ca9cf1e51339
2
+ SHA256:
3
+ metadata.gz: f4a1cfa48aaf8c4d91ccb2aff3b5c937f453309e77077e4fd3300dcc7d82aba1
4
+ data.tar.gz: 8b8a4d02f71b140bbbc6a88571e67d1fd04e2f5840361ee0b65d3a41ab87117b
5
5
  SHA512:
6
- metadata.gz: df440335455b0deea4f7ca6f8b3566868d7d58f62be038217413628931b68acc3feb8899b38bd83b219676fa70aa8ad25d2e7e57d8ba65a6e56cc1bb908a0986
7
- data.tar.gz: 1f20ff703cf2b7f725cf744139ec26c73e60a496014a929b8ff06dceb8794dea03a73e3884036be57c4dd0d04fc122f23701c7545a160a9756d9e89c7858ced0
6
+ metadata.gz: e08a0a2db398cd63b0033dfe32bd8da04bd5dbca8ef23a07273f3b9c773ce46e9e65f8fcb83680609171722cfaaad029008011ee8519f7fcf39080c35fc88073
7
+ data.tar.gz: 2834ced5a39cf995df9e21f3c0afbece56ae5a1eff03438d6ae0e1db42e20805dce9a1dfa9198cd1048d4c84454252b62e164ca385225f2e6abfc64f0a0aaedd
data/CHANGELOG.md CHANGED
@@ -1,16 +1,31 @@
1
1
  # pathspec-ruby CHANGELOG
2
2
 
3
- ## 0.1.2
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)
4
19
  - Fix for regexp matching Thanks @incase! #16
5
20
  - File handling cleanup Thanks @martinandert! #13
6
21
  - `from_filename` actually works now! Thanks @martinandert! #12
7
22
 
8
- ## 0.1.0
23
+ ## 0.1.0 (Minor Release)
9
24
  - Port new edgecase handling from [python-path-specification](https://github.com/cpburnz/python-path-specification/pull/8). Many thanks to @jdpace! :)
10
25
  - Removed EOL Ruby support
11
26
  - Added current Ruby stable to Travis testing
12
27
 
13
- ## 0.0.2
28
+ ## 0.0.2 (Patch/Bug Fix Release)
14
29
  - Fixed issues with Ruby 1.8.7/2.1.1
15
30
  - Added more testing scripts
16
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) [![Ruby](https://github.com/highb/pathspec-ruby/actions/workflows/ruby.yml/badge.svg)](https://github.com/highb/pathspec-ruby/actions/workflows/ruby.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/4f3b5917e01fb34f790d/maintainability)](https://codeclimate.com/github/highb/pathspec-ruby/maintainability) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=highb_pathspec-ruby&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=highb_pathspec-ruby)
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,69 @@ 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.
120
+
121
+ ## Releasing
122
+
123
+ This is mainly a reminder to myself but the release process is:
124
+ 1. Make sure CI is passing
125
+ 2. Update the CHANGELOG with relevant changes to Gem consumers
126
+ 3. Update version in gemspec with correct SemVer bump for scope of changes
127
+ 4. Tag/release using GitHub UI and the Build & Push workflow should do the rest.
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,67 @@
1
+ .\" generated by kramdown
2
+ .TH "PATHSPEC\-RB" "1"
3
+ .SH "NAME"
4
+ pathspec \- Test pathspecs against a specific path
5
+ .SH "SYNOPSIS"
6
+ \fBpathspec\-rb\fP [\fBOPTIONS\fP] [\fBSUBCOMMAND\fP] [\fBPATH\fP] NAME PATH
7
+ .SH "DESCRIPTION"
8
+ \fBpathspc\-rb\fP is a tool that accompanies the pathspec\-ruby library to help you test what match results the library would find using path specs\. You can either find all specs matching a path, find all files matching specs, or verify that a path would match any spec\.
9
+ .P
10
+ https://github\.com/highb/pathspec\-ruby
11
+ .SH "SUB\-COMMANDS"
12
+ .TS
13
+ box ;
14
+ lb lb .
15
+ Name Description
16
+ =
17
+ .T&
18
+ l l .
19
+ \fIspecs_match\fP Find all specs matching path
20
+ _
21
+ .T&
22
+ l l .
23
+ \fItree\fP Find all files under path matching the spec
24
+ _
25
+ .T&
26
+ l l .
27
+ \fImatch\fP Check if the path matches any spec
28
+ .TE
29
+ .sp
30
+ .SH "OPTIONS"
31
+ .TP
32
+ \fB\-f <FILENAME>\fP, \fB\-\-file <FILENAME>\fP
33
+ Load path specs from the file passed in as argument\. If this option is not specified, \fBpathspec\-rb\fP defaults to loading \fB\&\.gitignore\fP\&\.
34
+ .TP
35
+ \fB\-t [git|regex]\fP, \fB\-\-type [git|regex]\fP
36
+ Type of spec expected in the loaded specs file (see \fB\-f\fP option)\. Defaults to \fBgit\fP\&\.
37
+ .TP
38
+ \fB\-v\fP, \fB\-\-verbose\fP
39
+ Only output if there are matches\.
40
+ .SH "EXAMPLE"
41
+ Find all files ignored by git under your source directory:
42
+ .sp
43
+ .RS 4
44
+ .EX
45
+ $ pathspec\-rb tree src/
46
+ .EE
47
+ .RE
48
+ .P
49
+ List all spec rules that would match for the specified path:
50
+ .sp
51
+ .RS 4
52
+ .EX
53
+ $ pathspec\-rb specs_match build/
54
+ .EE
55
+ .RE
56
+ .P
57
+ Check that a path matches at least one of the specs in a new version of a gitignore file:
58
+ .sp
59
+ .RS 4
60
+ .EX
61
+ $ pathspec\-rb match \-f \.gitignore\.new spec/fixtures/
62
+ .EE
63
+ .RE
64
+ .SH "AUTHOR"
65
+ Brandon High highb@users\.noreply\.github\.com
66
+ .P
67
+ Gabriel Filion
@@ -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