filecount 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/filecount +1 -10
- data/lib/filecount/args.rb +0 -0
- data/lib/filecount/counter.rb +51 -0
- data/lib/filecount/runner.rb +49 -0
- data/lib/filecount.rb +2 -18
- data/lib/run.rb +3 -0
- metadata +9 -5
data/bin/filecount
CHANGED
File without changes
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Filecount
|
2
|
+
class Counter
|
3
|
+
|
4
|
+
def initialize(options)
|
5
|
+
@options = options
|
6
|
+
@count = 0
|
7
|
+
@start_dir
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.execute(options)
|
11
|
+
new(options).execute
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute()
|
15
|
+
if ARGV[0] != nil and File.directory?(ARGV[0])
|
16
|
+
count(ARGV[0])
|
17
|
+
elsif ARGV[0] != nil
|
18
|
+
puts "Directory '#{ARGV[0]}' not found"
|
19
|
+
exit
|
20
|
+
else
|
21
|
+
count(".")
|
22
|
+
end
|
23
|
+
@count
|
24
|
+
end
|
25
|
+
|
26
|
+
def count (directory)
|
27
|
+
Dir.foreach(directory) do |file|
|
28
|
+
if file != '.' && file != '..' then
|
29
|
+
if @options[:dotfiles] == nil && file[0].chr == "." && file != '.git'
|
30
|
+
next
|
31
|
+
end
|
32
|
+
f = "#{directory}/#{file}"
|
33
|
+
|
34
|
+
if File.directory?(f)
|
35
|
+
if @options[:count_git_dir] == nil && file == '.git'
|
36
|
+
next
|
37
|
+
end
|
38
|
+
count(f)
|
39
|
+
else
|
40
|
+
if @options[:verbose]
|
41
|
+
puts f
|
42
|
+
end
|
43
|
+
@count += 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
module Filecount
|
3
|
+
class Runner
|
4
|
+
def initialize
|
5
|
+
@options = {}
|
6
|
+
parse_options
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.execute
|
10
|
+
new().execute
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute
|
14
|
+
count = Counter.execute(@options)
|
15
|
+
puts "-- #{count} files found"
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_options
|
19
|
+
optparse = OptionParser.new do |opts|
|
20
|
+
opts.banner = 'Usage: filecount [options] directory'
|
21
|
+
|
22
|
+
opts.on('-d', '--dotfiles', 'Follow dotfiles and directories') do
|
23
|
+
@options[:dotfiles] = true
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on('-g', '--count-git-dir', 'Count files in git directory') do
|
27
|
+
@options[:count_git_dir] = true
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on('-v', '--verbose', 'Display counted files') do
|
31
|
+
@options[:verbose] = true
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on('-h', '--help', 'Display this screen') do
|
35
|
+
puts opts
|
36
|
+
exit
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
begin
|
41
|
+
optparse.parse!
|
42
|
+
rescue
|
43
|
+
puts "Invalid options"
|
44
|
+
puts optparse
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/filecount.rb
CHANGED
@@ -1,19 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
def initialize
|
4
|
-
@filecount = 0
|
5
|
-
end
|
1
|
+
require 'filecount/runner'
|
2
|
+
require 'filecount/counter'
|
6
3
|
|
7
|
-
def run (directory)
|
8
|
-
Dir.foreach(directory) do |file|
|
9
|
-
if file != '.' && file != '..' then
|
10
|
-
f = "#{directory}/#{file}"
|
11
|
-
if File.directory?(f)
|
12
|
-
run(f)
|
13
|
-
else
|
14
|
-
@filecount += 1
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
data/lib/run.rb
ADDED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filecount
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Markus Nilsson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-30 00:00:00 +02:00
|
19
19
|
default_executable: filecount
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -43,6 +43,10 @@ extra_rdoc_files:
|
|
43
43
|
- README.rdoc
|
44
44
|
files:
|
45
45
|
- lib/filecount.rb
|
46
|
+
- lib/filecount/args.rb
|
47
|
+
- lib/filecount/counter.rb
|
48
|
+
- lib/filecount/runner.rb
|
49
|
+
- lib/run.rb
|
46
50
|
- LICENSE
|
47
51
|
- README.rdoc
|
48
52
|
- test/helper.rb
|