dircat 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/Rakefile CHANGED
@@ -4,6 +4,6 @@ require 'rake'
4
4
  # Load tasks
5
5
  Dir.glob('tasks/**/*.rake').each { |r| Rake.application.add_import r }
6
6
 
7
- task :test => :check_dependencies
7
+ task :test => :spec
8
8
  task :default => :spec
9
9
 
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 1
4
- :patch: 8
4
+ :patch: 9
5
5
  :build:
data/bin/dircat CHANGED
@@ -3,5 +3,4 @@ cwd = File.expand_path(File.join(File.dirname(__FILE__), %w{ .. lib}))
3
3
  $:.unshift(cwd) unless $:.include?(cwd)
4
4
 
5
5
  require 'dircat'
6
- include DirCat
7
- exit CliDirCat.run
6
+ DirCat::CliDirCat.run!
data/dircat.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dircat}
8
- s.version = "0.1.8"
8
+ s.version = "0.1.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tokiro"]
12
- s.date = %q{2011-02-08}
12
+ s.date = %q{2011-02-14}
13
13
  s.default_executable = %q{dircat}
14
14
  s.description = %q{
15
15
  command line utilites to manage catalogs of directory
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  "README.md"
22
22
  ]
23
23
  s.files = [
24
+ ".gemtest",
24
25
  "LICENSE.txt",
25
26
  "README.md",
26
27
  "Rakefile",
@@ -70,7 +71,7 @@ Gem::Specification.new do |s|
70
71
 
71
72
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
72
73
  s.add_runtime_dependency(%q<treevisitor>, ["= 0.2.1"])
73
- s.add_runtime_dependency(%q<optparse-command>, ["= 0.1.4"])
74
+ s.add_runtime_dependency(%q<optparse-command>, ["= 0.1.5"])
74
75
  s.add_development_dependency(%q<jeweler>, [">= 0"])
75
76
  s.add_development_dependency(%q<rake>, [">= 0"])
76
77
  s.add_development_dependency(%q<yard>, [">= 0"])
@@ -78,7 +79,7 @@ Gem::Specification.new do |s|
78
79
  s.add_development_dependency(%q<rspec>, [">= 0"])
79
80
  else
80
81
  s.add_dependency(%q<treevisitor>, ["= 0.2.1"])
81
- s.add_dependency(%q<optparse-command>, ["= 0.1.4"])
82
+ s.add_dependency(%q<optparse-command>, ["= 0.1.5"])
82
83
  s.add_dependency(%q<jeweler>, [">= 0"])
83
84
  s.add_dependency(%q<rake>, [">= 0"])
84
85
  s.add_dependency(%q<yard>, [">= 0"])
@@ -87,7 +88,7 @@ Gem::Specification.new do |s|
87
88
  end
88
89
  else
89
90
  s.add_dependency(%q<treevisitor>, ["= 0.2.1"])
90
- s.add_dependency(%q<optparse-command>, ["= 0.1.4"])
91
+ s.add_dependency(%q<optparse-command>, ["= 0.1.5"])
91
92
  s.add_dependency(%q<jeweler>, [">= 0"])
92
93
  s.add_dependency(%q<rake>, [">= 0"])
93
94
  s.add_dependency(%q<yard>, [">= 0"])
@@ -1,29 +1,28 @@
1
1
  # -*- coding: utf-8 -*-
2
- class CliDirCat < OptParseCommand::CliMain
2
+ module DirCat
3
3
 
4
- def self.command
5
- "dircat"
6
- end
4
+ class CliDirCat < OptParseCommand::CliMain
7
5
 
8
- def self.description
9
- "Simple set of command to build catalogs of files.\n" +
10
- "Code https://github.com/tokiro/dircat. Feedback to tokiro.oyama@gmail.com"
11
- end
6
+ def self.command
7
+ "dircat"
8
+ end
12
9
 
13
- def self.version
14
- DirCat::version
15
- end
10
+ def self.description
11
+ "Simple set of command to build catalogs of files.\n" +
12
+ "Code https://github.com/tokiro/dircat. Feedback to tokiro.oyama@gmail.com"
13
+ end
16
14
 
17
- def defaults
18
- OpenStruct.new(
19
- :verbose => true,
20
- :force => false
21
- )
22
- end
15
+ def self.version
16
+ DirCat::version
17
+ end
18
+
19
+ def defaults
20
+ OpenStruct.new(
21
+ :verbose => true,
22
+ :force => false
23
+ )
24
+ end
23
25
 
24
- def opt_parser(options)
25
- opt_parser = super(options)
26
- opt_parser
27
26
  end
28
27
 
29
28
  end
@@ -1,95 +1,97 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
+ module DirCat
3
4
  #
4
5
  # Build a catalogue starting from a directory
5
6
  #
6
- class CommandBuild < OptParseCommand::CliCommand
7
+ class CommandBuild < OptParseCommand::CliCommand
7
8
 
8
- def self.command
9
- "build"
10
- end
11
-
12
- def self.description
13
- "Build a catalogue starting from a directory"
14
- end
9
+ def self.command
10
+ "build"
11
+ end
15
12
 
16
- def self.usage
17
- "Usage: dircat build [options]"
18
- end
13
+ def self.description
14
+ "Build a catalogue starting from a directory"
15
+ end
19
16
 
20
- def defaults(options)
21
- options.force = false
22
- end
17
+ def self.usage
18
+ "Usage: dircat build [options]"
19
+ end
23
20
 
24
- def option_parser(options)
25
- parser = super(options)
26
- parser.on("-f", "--force", "force write on existent file") do |v|
27
- options.force = true
21
+ def defaults(options)
22
+ options.force = false
28
23
  end
29
24
 
30
- parser.on("-o [FILE]", "--output [FILE]", String) do |v|
31
- if options.output
32
- puts "only one file of output can be used"
33
- options.exit = true
25
+ def option_parser(options)
26
+ parser = super(options)
27
+ parser.on("-f", "--force", "force write on existent file") do |v|
28
+ options.force = true
34
29
  end
35
- options.output = v
36
- end
37
30
 
38
- parser
39
- end
31
+ parser.on("-o [FILE]", "--output [FILE]", String) do |v|
32
+ if options.output
33
+ puts "only one file of output can be used"
34
+ options.exit = true
35
+ end
36
+ options.output = v
37
+ end
40
38
 
41
- def exec(main, options, rest)
42
- if rest.length < 1
43
- $stderr.puts "directory (from which build catalog) is missing"
44
- $stderr.puts "-h to print help"
45
- return false
39
+ parser
46
40
  end
47
41
 
48
- dirname = rest[0]
49
- dirname = File.expand_path(dirname)
50
- cat_opts = {}
42
+ def exec(main, options, rest)
43
+ if rest.length < 1
44
+ $stderr.puts "directory (from which build catalog) is missing"
45
+ $stderr.puts "-h to print help"
46
+ return false
47
+ end
48
+
49
+ dirname = rest[0]
50
+ dirname = File.expand_path(dirname)
51
+ cat_opts = {}
51
52
 
52
- if not FileTest.directory?(dirname)
53
- $stderr.puts "'#{dirname}' not exists or is not a directory"
54
- return 0
55
- end
53
+ if not FileTest.directory?(dirname)
54
+ $stderr.puts "'#{dirname}' not exists or is not a directory"
55
+ return 0
56
+ end
56
57
 
57
- #
58
- # option verbose
59
- #
58
+ #
59
+ # option verbose
60
+ #
60
61
 
61
- if options.verbose
62
- cat_opts[:verbose_level] = 1
63
- end
62
+ if options.verbose
63
+ cat_opts[:verbose_level] = 1
64
+ end
64
65
 
65
- #
66
- # option: output, force
67
- #
68
- output = $stdout
69
- if options.output
70
- filename = options.output
71
- else
72
- filename = "cat_" + File.basename(dirname) + "_" + Date.today.strftime("%Y%m%d") + ".yaml"
73
- end
74
- if File.exist?(filename) and not options.force
75
- $stderr.puts "catalog '#{filename}' exists use --force or -f to overwrite"
76
- return 0
77
- end
66
+ #
67
+ # option: output, force
68
+ #
69
+ output = $stdout
70
+ if options.output
71
+ filename = options.output
72
+ else
73
+ filename = "cat_" + File.basename(dirname) + "_" + Date.today.strftime("%Y%m%d") + ".yaml"
74
+ end
75
+ if File.exist?(filename) and not options.force
76
+ $stderr.puts "catalog '#{filename}' exists use --force or -f to overwrite"
77
+ return 0
78
+ end
78
79
 
79
- output = File.open(filename, "w")
80
- start_time = Time.now
81
- s = Cat.from_dir(dirname)
82
- end_time = Time.now
83
- s.save_to(output)
80
+ output = File.open(filename, "w")
81
+ start_time = Time.now
82
+ s = Cat.from_dir(dirname)
83
+ end_time = Time.now
84
+ s.save_to(output)
84
85
 
85
- if output != $stdout
86
- output.close
86
+ if output != $stdout
87
+ output.close
88
+ end
89
+ $stderr.puts s.report
90
+ $stderr.puts "elapsed: #{end_time - start_time}"
91
+ $stderr.puts "written to #{filename}" if output != $stdout
92
+
93
+ true
87
94
  end
88
- $stderr.puts s.report
89
- $stderr.puts "elapsed: #{end_time - start_time}"
90
- $stderr.puts "written to #{filename}" if output != $stdout
91
95
 
92
- true
93
96
  end
94
-
95
- end
97
+ end
@@ -1,85 +1,86 @@
1
1
  # -*- coding: utf-8 -*-
2
+ module DirCat
3
+ class CommandDiff < OptParseCommand::CliCommand
2
4
 
3
- class CommandDiff < OptParseCommand::CliCommand
4
-
5
- def self.command
6
- "diff"
7
- end
5
+ def self.command
6
+ "diff"
7
+ end
8
8
 
9
- def self.description
10
- "Show diff from two catalogs"
11
- end
9
+ def self.description
10
+ "Show diff from two catalogs"
11
+ end
12
12
 
13
- def self.usage
14
- <<-EOS
13
+ def self.usage
14
+ <<-EOS
15
15
  Usage: dircat diff [options] <filedircat1> <filedircat2>
16
16
  diff first catalog from second (<filedircat1> - <filedircat2>)
17
17
  and then print the difference with the format specified on output
18
- EOS
19
- end
20
-
21
- def option_parser(options)
22
- parser = super(options)
23
- parser.on("-f FORMAT", "--fmt FORMAT", "format (simple, ruby)") do |v|
24
- options.format = v
18
+ EOS
25
19
  end
26
- parser
27
- end
28
20
 
29
- def exec(options, rest)
30
- if rest.length < 2
31
- puts "you must provide two args (catalogs or directory)"
32
- puts "-h to print help"
33
- return false
21
+ def option_parser(options)
22
+ parser = super(options)
23
+ parser.on("-f FORMAT", "--fmt FORMAT", "format (simple, ruby)") do |v|
24
+ options.format = v
25
+ end
26
+ parser
34
27
  end
35
28
 
36
- cat_filename1 = rest[0]
37
- cat_filename2 = rest[1]
29
+ def exec(main, options, rest)
30
+ if rest.length < 2
31
+ puts "you must provide two args (catalogs or directory)"
32
+ puts "-h to print help"
33
+ return false
34
+ end
38
35
 
39
- #
40
- # process first argument
41
- #
42
- if File.directory?(cat_filename1)
43
- puts "build first set from directory #{cat_filename1}"
44
- s1 = Cat.from_dir(cat_filename1)
45
- elsif File.exists?(cat_filename1)
46
- puts "load catalog #{cat_filename1}"
47
- s1 = Cat.from_file(cat_filename1)
48
- else
49
- puts "#{cat_filename1} is not a catalog file or directory"
50
- return 1
51
- end
36
+ cat_filename1 = rest[0]
37
+ cat_filename2 = rest[1]
52
38
 
53
- #
54
- # process second argument
55
- #
56
- if File.directory?(cat_filename2)
57
- puts "build first set from directory #{cat_filename2}"
58
- s2 = Cat.from_dir(cat_filename2)
59
- elsif File.exists?(cat_filename2)
60
- puts "load catalog #{cat_filename2}"
61
- s2 = Cat.from_file(cat_filename2)
62
- else
63
- puts "#{cat_filename2} is not a catalog file or directory"
64
- return 1
65
- end
39
+ #
40
+ # process first argument
41
+ #
42
+ if File.directory?(cat_filename1)
43
+ puts "build first set from directory #{cat_filename1}"
44
+ s1 = Cat.from_dir(cat_filename1)
45
+ elsif File.exists?(cat_filename1)
46
+ puts "load catalog #{cat_filename1}"
47
+ s1 = Cat.from_file(cat_filename1)
48
+ else
49
+ puts "#{cat_filename1} is not a catalog file or directory"
50
+ return 1
51
+ end
66
52
 
67
- s3 = s1 - s2
53
+ #
54
+ # process second argument
55
+ #
56
+ if File.directory?(cat_filename2)
57
+ puts "build first set from directory #{cat_filename2}"
58
+ s2 = Cat.from_dir(cat_filename2)
59
+ elsif File.exists?(cat_filename2)
60
+ puts "load catalog #{cat_filename2}"
61
+ s2 = Cat.from_file(cat_filename2)
62
+ else
63
+ puts "#{cat_filename2} is not a catalog file or directory"
64
+ return 1
65
+ end
66
+
67
+ s3 = s1 - s2
68
68
 
69
- if s3.empty?
70
- puts "no difference (first catalog contains all file of second catalog)"
71
- else
72
- puts "differences (file in first catalog not contained in the second catalog)"
73
- case options.format
74
- when "simple"
75
- s3.fmt_simple
76
- when "ruby"
77
- s3.fmt_ruby(".")
78
- else
79
- s3.fmt_simple
69
+ if s3.empty?
70
+ puts "no difference (first catalog contains all file of second catalog)"
71
+ else
72
+ puts "differences (file in first catalog not contained in the second catalog)"
73
+ case options.format
74
+ when "simple"
75
+ s3.fmt_simple
76
+ when "ruby"
77
+ s3.fmt_ruby(".")
78
+ else
79
+ s3.fmt_simple
80
+ end
80
81
  end
82
+ true
81
83
  end
82
- true
83
- end
84
84
 
85
- end
85
+ end
86
+ end
@@ -1,50 +1,56 @@
1
1
  # -*- coding: utf-8 -*-
2
+ module DirCat
3
+ class CommandQuery < OptParseCommand::CliCommand
2
4
 
3
- class CommandQuery < OptParseCommand::CliCommand
4
-
5
- def self.command
6
- "query"
7
- end
8
-
9
- def self.description
10
- "show info about dircat catalogs"
11
- end
12
-
13
- def self.usage
14
- "Usage: query [options] <catalog> [<method>]"
15
- end
16
-
17
- def exec(main, options, rest)
18
- if rest.length < 1
19
- puts "missing catalog!"
20
- puts "-h to print help"
21
- return 0
5
+ def self.command
6
+ "query"
22
7
  end
23
8
 
24
- cat_opts = {}
25
- cat_filename = rest[0]
26
- if !File.exists?(cat_filename) or File.directory?(cat_filename)
27
- puts "first args must be a catalogue"
28
- return 1
9
+ def self.description
10
+ "show info about dircat catalogs"
29
11
  end
30
12
 
31
- if rest.length > 1
32
- command = rest[1]
33
- else
34
- command = "report"
13
+ def self.usage
14
+ "Usage: query [options] <catalog> [<method>]"
35
15
  end
36
16
 
37
- #
38
- # option verbose
39
- #
40
- if options.verbose
41
- cat_opts[:verbose_level] = 1
17
+ def exec(main, options, rest)
18
+ if rest.length < 1
19
+ puts "missing catalog!"
20
+ puts "-h to print help"
21
+ return 0
22
+ end
23
+
24
+ cat_opts = {}
25
+ cat_filename = rest[0]
26
+ if !File.exists?(cat_filename) or File.directory?(cat_filename)
27
+ puts "first args must be a catalogue"
28
+ return 1
29
+ end
30
+
31
+ if rest.length > 1
32
+ command = rest[1]
33
+ else
34
+ command = "report"
35
+ end
36
+
37
+ #
38
+ # option verbose
39
+ #
40
+ if options.verbose
41
+ cat_opts[:verbose_level] = 1
42
+ end
43
+
44
+ s = Cat.from_file(cat_filename, cat_opts)
45
+
46
+ if s.respond_to? command.to_sym
47
+ puts s.send(command.to_sym)
48
+ true
49
+ else
50
+ puts "unknow methods '#{command}'"
51
+ false
52
+ end
42
53
  end
43
54
 
44
- s = Cat.from_file(cat_filename, cat_opts)
45
-
46
- puts s.send(command.to_sym)
47
- true
48
55
  end
49
-
50
- end
56
+ end
data/lib/dircat.rb CHANGED
@@ -12,7 +12,7 @@ require 'pp'
12
12
  #
13
13
  # rubygems
14
14
  #
15
- gem "optparse-command", "0.1.4"
15
+ gem "optparse-command", "0.1.5"
16
16
  require 'optparse-command'
17
17
 
18
18
  gem "treevisitor", "0.2.1"
@@ -12,18 +12,12 @@ describe CliDirCat do
12
12
 
13
13
  context "common args" do
14
14
  it "should accept -h (-help) option" do
15
- out = with_stdout_captured do
16
- args = %w{-h}
17
- CliDirCat.new.parse_and_execute(args)
18
- end
15
+ out = capture_out { CliDirCat.run(%w{-h}) }.out
19
16
  out.should match /Usage:/
20
17
  end
21
18
 
22
19
  it "should accept --version option" do
23
- out = with_stdout_captured do
24
- args = %w{--version}
25
- CliDirCat.new.parse_and_execute(args)
26
- end
20
+ out = capture_out { CliDirCat.run(%w{--version}) }.out
27
21
  out.should match /#{DirCat::version}/
28
22
  end
29
23
  end
@@ -11,18 +11,12 @@ describe CommandBuild do
11
11
  end
12
12
 
13
13
  it "should accept -h (-help) option" do
14
- out = with_stdout_captured do
15
- args = %w{build -h}
16
- CliDirCat.new.parse_and_execute(args)
17
- end
14
+ out = capture_out { CliDirCat.run(%w{build -h}) }.out
18
15
  out.should match /Usage:/
19
16
  end
20
17
 
21
18
  it "should not accept more then -o options" do
22
- out = with_stdout_captured do
23
- args = "build -f -o filename -o filename1"
24
- CliDirCat.new.parse_and_execute(args.split)
25
- end
19
+ out = capture_out { CliDirCat.run("build -f -o filename -o filename1".split) }.out
26
20
  out.should match /only one file/
27
21
  end
28
22
 
@@ -31,10 +25,7 @@ describe CommandBuild do
31
25
  expect_filename = File.join(@certified_output_dirname, "dircat1.yaml")
32
26
  result_filename = File.join(@tmp_output_dirname, "dircat1.yaml")
33
27
 
34
- capture_out do
35
- args = "build -f -o #{result_filename} #{@dir1_dirname}"
36
- CliDirCat.new.parse_and_execute(args.split)
37
- end
28
+ capture_out { CliDirCat.run("build -f -o #{result_filename} #{@dir1_dirname}".split) }
38
29
 
39
30
  cat_expect = Cat.from_file(expect_filename)
40
31
  cat_result = Cat.from_file(result_filename)
@@ -4,10 +4,7 @@ require File.expand_path( File.join(File.dirname(__FILE__), "..", "..", "spec_he
4
4
  describe CommandDiff do
5
5
 
6
6
  it "should accept -h (help) option" do
7
- out = with_stdout_captured do
8
- args = %w{diff -h}
9
- CliDirCat.new.parse_and_execute(args)
10
- end
7
+ out = capture_out { CliDirCat.run %w{diff -h} }.out
11
8
  out.should match /Usage:/
12
9
  end
13
10
 
@@ -8,19 +8,13 @@ describe CommandQuery do
8
8
  end
9
9
 
10
10
  it "should accept -h (help) option" do
11
- out = with_stdout_captured do
12
- args = %w{query -h}
13
- CliDirCat.new.parse_and_execute(args)
14
- end
11
+ out = capture_out { CliDirCat.run %w{query -h} }.out
15
12
  out.should match /Usage:/
16
13
  end
17
14
 
18
15
  it "should show catalogs info" do
19
16
  cat_filename = File.join( @certified_output_dirname, "dircat1.yaml" )
20
- out = with_stdout_captured do
21
- args = "query #{cat_filename}"
22
- CliDirCat.new.parse_and_execute(args.split)
23
- end
17
+ out = capture_out { CliDirCat.run "query #{cat_filename}".split }.out
24
18
  out.should match /file: 2/
25
19
  out.should match /Bytes: 4/
26
20
  end
data/spec/spec_helper.rb CHANGED
@@ -21,14 +21,14 @@ def capture_out
21
21
  OpenStruct.new(:out => out.string, :err => err.string)
22
22
  end
23
23
 
24
- def with_stdout_captured
25
- old_stdout = $stdout
26
- out = StringIO.new
27
- $stdout = out
28
- begin
29
- yield
30
- ensure
31
- $stdout = old_stdout
32
- end
33
- out.string
34
- end
24
+ #def with_stdout_captured
25
+ # old_stdout = $stdout
26
+ # out = StringIO.new
27
+ # $stdout = out
28
+ # begin
29
+ # yield
30
+ # ensure
31
+ # $stdout = old_stdout
32
+ # end
33
+ # out.string
34
+ #end
data/tasks/jeweler.rake CHANGED
@@ -25,7 +25,7 @@ begin
25
25
  #
26
26
  # files
27
27
  #
28
- gem.files = %w{LICENSE.txt README.md Rakefile VERSION.yml dircat.gemspec}
28
+ gem.files = %w{LICENSE.txt README.md Rakefile VERSION.yml dircat.gemspec .gemtest}
29
29
  gem.files.concat Dir['lib/**/*.rb']
30
30
  gem.files.concat Dir['examples/*.rb']
31
31
  gem.files.concat Dir['tasks/*.rake']
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: dircat
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.8
5
+ version: 0.1.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tokiro
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-08 00:00:00 +01:00
13
+ date: 2011-02-14 00:00:00 +01:00
14
14
  default_executable: dircat
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -31,7 +31,7 @@ dependencies:
31
31
  requirements:
32
32
  - - "="
33
33
  - !ruby/object:Gem::Version
34
- version: 0.1.4
34
+ version: 0.1.5
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: *id002
@@ -100,6 +100,7 @@ extra_rdoc_files:
100
100
  - LICENSE.txt
101
101
  - README.md
102
102
  files:
103
+ - .gemtest
103
104
  - LICENSE.txt
104
105
  - README.md
105
106
  - Rakefile