code_lister 0.0.5 → 0.0.6

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
  SHA1:
3
- metadata.gz: dd7f9ad0380a230d4dccd591b283d0fed360832b
4
- data.tar.gz: b4165437330aff861d9af903ec77e15d4e1ad3dc
3
+ metadata.gz: fde9576db239d5b1600c135b1e50e98d37f92312
4
+ data.tar.gz: 7bab4d02375dadea47e1d5eeae5f98df730e5fcf
5
5
  SHA512:
6
- metadata.gz: bf2527f11af7c5b6d9f2363c2a52f859db786a2c74776db90f561bb0b680ee1596623056a6f72de5d65e597b418c4942bb919a266117f9293f04ef042b733c58
7
- data.tar.gz: bae0153c61986aa011960c60552a60b91e2a75d9edad2f2f12bc3b8e3a9f767c164dcdb260b66c86e0bd73c4ab29b4e9f698963e49a0e88da8613f315bc2e67f
6
+ metadata.gz: 1c0bae4f7989747ce15cff9164364d3ae99e232b1b8fd42de026e6c7a2d41015931f135e2f346236bd23358e22b24d5d76c17d847ab588ab99f13a3cbc203b97
7
+ data.tar.gz: 7d93e8b9eb2aa048ed821368effe50f33cc232e2e91db7f2fc6a11012c0dc58d4ecd0e5df089c3944fb2abcc99322bdbf5bb6185b0201e55bf450aeef5e0e32b
data/README.md CHANGED
@@ -123,6 +123,7 @@ new_list = CodeLister.filter(file_list, inc_words: %w(some list of word),
123
123
 
124
124
  ```sh
125
125
  git clone https://github.com/agilecreativity/code_lister.git
126
+ cd code_lister
126
127
  bundle
127
128
  rake -T
128
129
 
@@ -154,6 +155,10 @@ always welcome.
154
155
 
155
156
  ### Changelogs
156
157
 
158
+ #### 0.0.6
159
+
160
+ - Add `--non-exts` option that make it possible to include files without extension.
161
+
157
162
  #### 0.0.5
158
163
 
159
164
  - Refactoring the CLI options to make it easy for re-use in other library.
@@ -3,7 +3,9 @@ require_relative 'core_ext/hash'
3
3
 
4
4
  module CodeLister
5
5
  class BaseCLI < Thor
6
+
6
7
  def self.shared_options
8
+
7
9
  method_option :base_dir,
8
10
  aliases: "-b",
9
11
  desc: "Base directory",
@@ -15,6 +17,12 @@ module CodeLister
15
17
  type: :array,
16
18
  default: []
17
19
 
20
+ method_option :non_exts,
21
+ aliases: "-f",
22
+ desc: "List of files without extension to search for",
23
+ type: :array,
24
+ default: []
25
+
18
26
  method_option :inc_words,
19
27
  aliases: "-n",
20
28
  desc: "List of words to be included in the result if any",
@@ -52,7 +60,9 @@ module CodeLister
52
60
  class CLI < CodeLister::BaseCLI
53
61
 
54
62
  desc "find", "List files by extensions, patterns, and simple criteria"
63
+
55
64
  shared_options
65
+
56
66
  def find
57
67
  if options[:version]
58
68
  puts "You are using CodeLister Version #{CodeLister::VERSION}"
@@ -67,12 +77,13 @@ module CodeLister
67
77
  def usage
68
78
  puts <<-EOS
69
79
  Usage:
70
- code_lister find
80
+ code_lister find [OPTIONS]
71
81
 
72
82
  Options:
73
83
  -b, [--base-dir=BASE_DIR] # Base directory
74
- # Default: . (current directory)
84
+ # Default: /home/bchoomnuan/Dropbox/spikes/code_lister
75
85
  -e, [--exts=one two three] # List of extensions to search for
86
+ -f, [--non-exts=one two three] # List of files without extension to search for
76
87
  -n, [--inc-words=one two three] # List of words to be included in the result if any
77
88
  -x, [--exc-words=one two three] # List of words to be excluded from the result if any
78
89
  -i, [--ignore-case], [--no-ignore-case] # Match case insensitively
@@ -10,15 +10,21 @@ module CodeLister
10
10
  base_dir: Dir.pwd,
11
11
  recursive: false,
12
12
  exts: [],
13
+ non_exts: []
13
14
  }.merge(args)
14
15
 
15
16
  base_dir = opts[:base_dir]
16
17
  raise CustomError, "The directory #{base_dir} is not valid or or not readable!" unless File.exists?(base_dir)
18
+
17
19
  wildcard = opts[:recursive] ? '**' : ''
18
- exts = opts[:exts]
19
- patterns = File.join(base_dir, wildcard, "*.{#{exts.join(",")}}")
20
+ exts = opts[:exts]
21
+ non_exts = opts[:non_exts]
22
+
23
+ file_with_extension = Dir.glob(File.join(base_dir, wildcard, "*.{#{exts.join(",")}}"))
24
+ file_with_no_extension = no_extension_files(base_dir, wildcard, non_exts)
20
25
 
21
- Dir.glob(patterns).sort
26
+ # combine the result
27
+ (file_with_extension + file_with_no_extension).sort
22
28
  end
23
29
 
24
30
  # Filter out the list based on given list of words
@@ -39,7 +45,18 @@ module CodeLister
39
45
  file_list
40
46
  end
41
47
 
42
- protected
48
+ private
49
+
50
+ # List files that do not have the extension
51
+ #
52
+ # @return list of files that does not have any extension
53
+ def no_extension_files(base_dir, wildcard, non_exts = [])
54
+ list = []
55
+ unless non_exts.empty?
56
+ list = Dir.glob(File.join(base_dir, wildcard, "{#{non_exts.join(',')}}"))
57
+ end
58
+ list
59
+ end
43
60
 
44
61
  def take_any!(file_list, args = {})
45
62
  words = args[:inc_words]
@@ -4,6 +4,7 @@ module CodeLister
4
4
 
5
5
  def run(options = {})
6
6
  args = default_options.merge(options)
7
+
7
8
  files = CodeLister.files(args)
8
9
 
9
10
  # Now filter out the list if any
@@ -28,7 +29,8 @@ module CodeLister
28
29
  ignore_case: true,
29
30
  inc_words: [],
30
31
  exc_words: [],
31
- exts: []
32
+ exts: [],
33
+ non_exts: []
32
34
  }
33
35
  end
34
36
  end
@@ -1,3 +1,3 @@
1
1
  module CodeLister
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -52,6 +52,6 @@ describe CodeLister do
52
52
  "spec/fixtures/demo2.xxx.rb" ]
53
53
  end
54
54
  end
55
- end
56
55
 
56
+ end
57
57
  end
@@ -0,0 +1,12 @@
1
+ require_relative '../spec_helper'
2
+ describe CodeLister do
3
+ context "#files" do
4
+ it 'works with non_exts option' do
5
+ list = CodeLister::Main.run base_dir: 'spec/fixtures/',
6
+ recursive: true,
7
+ non_exts: %w(noexts1_zzz noexts2_zzz)
8
+ expect(list).to eq [ "spec/fixtures/noexts1_zzz",
9
+ "spec/fixtures/noexts2_zzz" ]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1 @@
1
+ # file: spec/fixtures/noexts1_zzz
@@ -0,0 +1 @@
1
+ # file: spec/fixtures/noexts2_zzz
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_lister
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burin Choomnuan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-14 00:00:00.000000000 Z
11
+ date: 2014-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -148,6 +148,7 @@ files:
148
148
  - lib/code_lister/main.rb
149
149
  - lib/code_lister/version.rb
150
150
  - spec/code_lister/code_lister_spec.rb
151
+ - spec/code_lister/main_spec.rb
151
152
  - spec/fixtures/demo1.xxx.rb
152
153
  - spec/fixtures/demo1.yyy.rb
153
154
  - spec/fixtures/demo2.xxx.rb
@@ -156,6 +157,8 @@ files:
156
157
  - spec/fixtures/java/demo3.yyy.java
157
158
  - spec/fixtures/java/demo4.xxx.java
158
159
  - spec/fixtures/java/demo4.yyy.java
160
+ - spec/fixtures/noexts1_zzz
161
+ - spec/fixtures/noexts2_zzz
159
162
  - spec/spec_helper.rb
160
163
  homepage: https://github.com/agilecreativity/code_lister
161
164
  licenses:
@@ -183,6 +186,7 @@ specification_version: 4
183
186
  summary: Search, filter files easily using the power of ruby
184
187
  test_files:
185
188
  - spec/code_lister/code_lister_spec.rb
189
+ - spec/code_lister/main_spec.rb
186
190
  - spec/fixtures/demo1.xxx.rb
187
191
  - spec/fixtures/demo1.yyy.rb
188
192
  - spec/fixtures/demo2.xxx.rb
@@ -191,5 +195,7 @@ test_files:
191
195
  - spec/fixtures/java/demo3.yyy.java
192
196
  - spec/fixtures/java/demo4.xxx.java
193
197
  - spec/fixtures/java/demo4.yyy.java
198
+ - spec/fixtures/noexts1_zzz
199
+ - spec/fixtures/noexts2_zzz
194
200
  - spec/spec_helper.rb
195
201
  has_rdoc: