vclog 1.5.0 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/HISTORY.rdoc +12 -0
  2. data/README.rdoc +5 -5
  3. data/REQUIRE +1 -0
  4. data/VERSION +2 -2
  5. data/bin/vclog +1 -1
  6. data/features/git.feature +8 -8
  7. data/features/hg.feature +8 -8
  8. data/features/svn.feature +8 -8
  9. data/lib/plugins/syckle/vclog.rb +19 -9
  10. data/lib/vclog/adapters/abstract.rb +78 -9
  11. data/lib/vclog/adapters/darcs.rb +5 -5
  12. data/lib/vclog/adapters.rb +3 -4
  13. data/lib/vclog/change.rb +14 -28
  14. data/lib/vclog/changelog.rb +8 -12
  15. data/lib/vclog/cli/abstract.rb +99 -0
  16. data/lib/vclog/cli/bump.rb +30 -0
  17. data/lib/vclog/cli/changelog.rb +33 -0
  18. data/lib/vclog/cli/help.rb +37 -0
  19. data/lib/vclog/cli/history.rb +40 -0
  20. data/lib/vclog/cli/list.rb +28 -0
  21. data/lib/vclog/cli/version.rb +30 -0
  22. data/lib/vclog/cli.rb +70 -51
  23. data/lib/vclog/config.rb +65 -0
  24. data/lib/vclog/formatter.rb +27 -10
  25. data/lib/vclog/heuristics/default.rb +20 -0
  26. data/lib/vclog/heuristics.rb +86 -8
  27. data/lib/vclog/history.rb +26 -191
  28. data/lib/vclog/kernel.rb +12 -0
  29. data/lib/vclog/metadata.rb +1 -0
  30. data/lib/vclog/release.rb +25 -10
  31. data/lib/vclog/tag.rb +14 -4
  32. data/lib/vclog/templates/changelog.ansi.rb +52 -0
  33. data/lib/vclog/templates/{changelog.atom → changelog.atom.erb} +0 -0
  34. data/lib/vclog/templates/changelog.gnu.rb +31 -0
  35. data/lib/vclog/templates/{changelog.html → changelog.html.erb} +0 -0
  36. data/lib/vclog/templates/changelog.json.rb +1 -0
  37. data/lib/vclog/templates/changelog.markdown.rb +30 -0
  38. data/lib/vclog/templates/changelog.rdoc.rb +30 -0
  39. data/lib/vclog/templates/{changelog.xml → changelog.xml.erb} +0 -0
  40. data/lib/vclog/templates/changelog.yaml.rb +1 -0
  41. data/lib/vclog/templates/history.ansi.rb +59 -0
  42. data/lib/vclog/templates/{history.atom → history.atom.erb} +1 -1
  43. data/lib/vclog/templates/history.gnu.rb +41 -0
  44. data/lib/vclog/templates/history.html.erb +52 -0
  45. data/lib/vclog/templates/history.json.rb +1 -0
  46. data/lib/vclog/templates/history.markdown.rb +40 -0
  47. data/lib/vclog/templates/history.rdoc.rb +40 -0
  48. data/lib/vclog/templates/{history.xml → history.xml.erb} +1 -1
  49. data/lib/vclog/templates/history.yaml.rb +1 -0
  50. data/lib/vclog.rb +6 -1
  51. metadata +95 -21
  52. data/ROADMAP.rdoc +0 -31
  53. data/lib/vclog/templates/changelog.gnu +0 -6
  54. data/lib/vclog/templates/changelog.json +0 -1
  55. data/lib/vclog/templates/changelog.markdown +0 -6
  56. data/lib/vclog/templates/changelog.rdoc +0 -6
  57. data/lib/vclog/templates/changelog.yaml +0 -1
  58. data/lib/vclog/templates/history.gnu +0 -12
  59. data/lib/vclog/templates/history.html +0 -47
  60. data/lib/vclog/templates/history.json +0 -1
  61. data/lib/vclog/templates/history.markdown +0 -12
  62. data/lib/vclog/templates/history.rdoc +0 -12
  63. data/lib/vclog/templates/history.yaml +0 -1
@@ -0,0 +1,99 @@
1
+ require 'ostruct'
2
+ require 'optparse'
3
+
4
+ module VCLog
5
+ module CLI
6
+
7
+ #
8
+ def self.register
9
+ @register ||= []
10
+ end
11
+
12
+ #
13
+ class Abstract
14
+
15
+ #
16
+ def self.inherited(subclass)
17
+ CLI.register << subclass
18
+ end
19
+
20
+ #
21
+ def self.terms
22
+ [name.split('::').last.downcase]
23
+ end
24
+
25
+ #
26
+ def initialize
27
+ @options = OpenStruct.new
28
+ end
29
+
30
+ #
31
+ def options
32
+ @options
33
+ end
34
+
35
+ #
36
+ def parser(&block)
37
+ parser = OptionParser.new(&block)
38
+
39
+ parser.separator " "
40
+ parser.separator "SYSTEM OPTIONS:"
41
+ parser.on('--debug', 'show debugging information') do
42
+ $DEBUG = true
43
+ end
44
+ parser.on('--help' , '-h', 'display this help information') do
45
+ puts parser
46
+ exit
47
+ end
48
+ parser
49
+ end
50
+
51
+ # Setup options common to templating commands.
52
+ #
53
+ # parser - instance of options parser
54
+ #
55
+ # Returns a instance of OptionParser.
56
+ def template_options(parser)
57
+ parser.separator(" ")
58
+ parser.separator("OUTPUT OPTIONS: (use varies with format)")
59
+ parser.on('--format', '-f FORMAT', "output format") do |format|
60
+ options.format = format.to_sym
61
+ end
62
+ parser.on('--style <URI>', "provide a stylesheet URI (css or xsl) for HTML or XML format") do |uri|
63
+ options.stylesheet = uri
64
+ end
65
+ parser.on('--title', '-t TITLE', "document title") do |string|
66
+ options.title = string
67
+ end
68
+ parser.on('--detail', '-d', "provide details") do
69
+ options.extra = true
70
+ end
71
+ parser.on('--id', "include revision id") do
72
+ options.revision = true
73
+ end
74
+ parser.on('--level', '-l NUMBER', "lowest level of commit to display [0]") do |num|
75
+ options.level = num.to_i
76
+ end
77
+ parser
78
+ end
79
+
80
+ # Run the command.
81
+ def run(argv=nil)
82
+ argv ||= ARGV.dup
83
+
84
+ parser.parse!(argv)
85
+
86
+ @root = Dir.pwd # TODO: find root
87
+
88
+ @conf = VCLog::Config.new(@root)
89
+ @conf.level = options.level if options.level
90
+
91
+ @vcs = VCLog::Adapters.factory(@conf)
92
+
93
+ execute
94
+ end
95
+
96
+ end
97
+
98
+ end
99
+ end
@@ -0,0 +1,30 @@
1
+ require 'vclog/cli/abstract'
2
+
3
+ module VCLog
4
+ module CLI
5
+
6
+ class Bump < Abstract
7
+
8
+ #
9
+ def self.terms
10
+ ['bump']
11
+ end
12
+
13
+ #
14
+ def parser
15
+ super do |opt|
16
+ opt.banner = "Usage: vclog bump"
17
+ opt.separator(" ")
18
+ opt.separator("Display a bumped version number.")
19
+ end
20
+ end
21
+
22
+ #
23
+ def execute
24
+ puts @vcs.bump #(version)
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ require 'vclog/cli/abstract'
2
+
3
+ module VCLog
4
+ module CLI
5
+
6
+ class Changelog < Abstract
7
+
8
+ #
9
+ def self.terms
10
+ ['log', 'changelog']
11
+ end
12
+
13
+ #
14
+ def parser
15
+ super do |opt|
16
+ opt.banner = "Usage: vclog [changelog | log] [options]"
17
+ opt.separator(" ")
18
+ opt.separator("Print a Change Log.")
19
+ template_options(opt)
20
+ end
21
+ end
22
+
23
+ #
24
+ def execute
25
+ format = options.format || 'ansi'
26
+ output = @vcs.display(:changelog, format, options)
27
+ puts output
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ require 'vclog/cli/abstract'
2
+
3
+ module VCLog
4
+ module CLI
5
+
6
+ class Help < Abstract
7
+
8
+ #
9
+ def self.terms
10
+ ['help']
11
+ end
12
+
13
+ #
14
+ def parser
15
+ super do |opt|
16
+ opt.banner = "Usage: vclog help"
17
+ end
18
+ end
19
+
20
+ #
21
+ def execute
22
+ puts "Usage: vclog [command] [options]"
23
+ puts
24
+ puts "COMMANDS:"
25
+ puts " changelog display a Change Log"
26
+ puts " history display a Release History"
27
+ puts " version display the current tag version"
28
+ puts " bump display next reasonable version"
29
+ puts " list display format options"
30
+ puts " help show help information"
31
+ puts
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,40 @@
1
+ require 'vclog/cli/abstract'
2
+
3
+ module VCLog
4
+ module CLI
5
+
6
+ class History < Abstract
7
+
8
+ #
9
+ def self.terms
10
+ ['history', 'release']
11
+ end
12
+
13
+ #
14
+ def parser
15
+ super do |opt|
16
+ opt.banner = "Usage: vclog history [options]\n" +
17
+ " vclog release [options]"
18
+ opt.separator " "
19
+ opt.separator("Print a Release History.")
20
+ opt.separator(" ")
21
+ opt.separator "SPECIAL OPTIONS:"
22
+ opt.on('--version', '-v NUM', "use as if current version number") do |num|
23
+ options.version = num
24
+ end
25
+
26
+ template_options(opt)
27
+ end
28
+ end
29
+
30
+ #
31
+ def execute
32
+ format = options.format || 'ansi'
33
+ output = @vcs.display(:history, format, options)
34
+ puts output
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,28 @@
1
+ require 'vclog/cli/abstract'
2
+
3
+ module VCLog
4
+ module CLI
5
+
6
+ class List < Abstract
7
+
8
+ #
9
+ def self.terms
10
+ ['list', 'templates']
11
+ end
12
+
13
+ #
14
+ def parser
15
+ super do |opt|
16
+ opt.banner = "Usage: vclog list"
17
+ end
18
+ end
19
+
20
+ #
21
+ def execute
22
+ puts " ansi gnu rdoc markdown xml html atom rss json yaml"
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ require 'vclog/cli/abstract'
2
+
3
+ module VCLog
4
+ module CLI
5
+
6
+ class Version < Abstract
7
+
8
+ #
9
+ def self.terms
10
+ ['version']
11
+ end
12
+
13
+ #
14
+ def parser
15
+ super do |opt|
16
+ opt.banner = "Usage: vclog version"
17
+ opt.separator(" ")
18
+ opt.separator("Display the current version number.")
19
+ end
20
+ end
21
+
22
+ #
23
+ def execute
24
+ puts @vcs.version
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
data/lib/vclog/cli.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  module VCLog
2
2
 
3
- require 'vclog/adapters'
4
- require 'optparse'
5
-
6
3
  # = vclog Command
7
4
  #
8
5
  # == SYNOPSIS
@@ -31,19 +28,53 @@ module VCLog
31
28
  #
32
29
  # To use the library programmatically, please see the API documentation.
33
30
 
34
- def self.run
35
- begin
36
- vclog
37
- rescue => err
38
- if $DEBUG
39
- raise err
40
- else
41
- puts err.message
42
- exit -1
31
+ module CLI
32
+
33
+ require 'vclog/config'
34
+ require 'vclog/adapters'
35
+
36
+ require 'vclog/cli/help'
37
+ require 'vclog/cli/changelog'
38
+ require 'vclog/cli/history'
39
+ require 'vclog/cli/list'
40
+ require 'vclog/cli/bump'
41
+ require 'vclog/cli/version'
42
+
43
+ def self.main(*argv)
44
+ argv ||= ARGV.dup
45
+ begin
46
+ #opt = global_parser.order!(argv)
47
+ cmd = argv.shift unless argv.first =~ /^-/
48
+ cmd = cmd || 'changelog'
49
+ cli = CLI.factory(cmd)
50
+ cli.run(argv)
51
+ rescue => err
52
+ if $DEBUG
53
+ raise err
54
+ else
55
+ puts err.message
56
+ exit -1
57
+ end
43
58
  end
44
59
  end
60
+
61
+ #
62
+ def self.factory(name)
63
+ # find the closet matching term
64
+ terms = register.map{ |cli| cli.terms }.flatten
65
+ term = terms.select{ |term| /^#{name}/ =~ term }.first
66
+ # get the class that goes with the term
67
+ cmdclass = register.find{ |cli| cli.terms.include?(term) }
68
+ raise "Unknown command -- #{name}" unless cmdclass
69
+ cmdclass.new
70
+ end
71
+
45
72
  end
73
+ end
46
74
 
75
+ # VCLog Copyright (c) 2008 Thomas Sawyer
76
+
77
+ =begin
47
78
  #
48
79
  def self.vclog
49
80
  type = :log
@@ -53,7 +84,7 @@ module VCLog
53
84
  output = nil
54
85
  title = nil
55
86
  version = nil
56
- extra = false
87
+ extra = false require 'vclog/cli/help'
57
88
  rev = false
58
89
  typed = false
59
90
 
@@ -61,17 +92,6 @@ module VCLog
61
92
 
62
93
  opt.banner = "Usage: vclog [--TYPE] [-f FORMAT] [OPTIONS] [DIR]"
63
94
 
64
- opt.separator(" ")
65
- opt.separator("OUTPUT TYPE (choose one):")
66
-
67
- opt.on('--log', '--changelog', '-l', "changelog (default)") do
68
- type = :log
69
- end
70
-
71
- opt.on('--rel', '--history', '-r', "release history") do
72
- type = :rel
73
- end
74
-
75
95
  opt.on('--current', '-c', "display current version number") do
76
96
  type = :curr
77
97
  end
@@ -85,63 +105,65 @@ module VCLog
85
105
  exit
86
106
  end
87
107
 
108
+ opt.on('--help' , '-h', 'display this help information') do
109
+ puts opt
110
+ exit
111
+ end
112
+
88
113
  opt.separator(" ")
89
- opt.separator("FORMAT OPTION:")
114
+ opt.separator("FORMAT OPTIONS: (use varies with format)")
90
115
 
91
- opt.on('--format', '-f <FORMAT>', "Output format") do |format|
116
+ opt.on('--format', '-f FORMAT', "output format") do |format|
92
117
  format = format.to_sym
93
118
  end
94
119
 
95
- opt.separator(" ")
96
- opt.separator("OTHER OPTIONS:")
120
+ opt.on('--style <URI>', "provide a stylesheet URI (css or xsl) for HTML or XML format") do |uri|
121
+ style = uri
122
+ end
123
+
124
+ opt.on('--version', '-v NUM', "current version number") do |num|
125
+ version = num
126
+ end
127
+
97
128
 
98
129
  #opt.on('--typed', "catagorize by commit type") do
99
130
  # typed = true
100
131
  #end
101
132
 
102
- opt.on('--title <TITLE>', "document title, used by some formats") do |string|
133
+ opt.on('--title', '-t TITLE', "document title") do |string|
103
134
  title = string
104
135
  end
105
136
 
106
- opt.on('--extra', '-e', "provide extra output (used by some formats)") do
137
+ opt.on('--detail', '-d', "provide details") do
107
138
  extra = true
108
139
  end
109
140
 
110
- opt.on('--version', '-v <NUM>', "current version to use for release history") do |num|
111
- version = num
141
+ opt.on('--id', "include revision id") do
142
+ rev = true
112
143
  end
113
144
 
114
- opt.on('--style <URI>', "provide a stylesheet URI (css or xsl) for HTML or XML format") do |uri|
145
+ opt.on('--style URI', "provide a stylesheet URI (css or xsl) for HTML or XML format") do |uri|
115
146
  style = uri
116
147
  end
117
148
 
118
- opt.on('--id', "include revision ids (in formats that normally do not)") do
119
- rev = true
120
- end
121
-
122
149
  # DEPRECATE
123
- opt.on('--output', '-o <FILE>', "send output to a file instead of stdout") do |out|
150
+ opt.on('--output', '-o FILE', "send output to a file instead of stdout") do |out|
124
151
  output = out
125
152
  end
126
153
 
127
154
  opt.separator(" ")
128
- opt.separator("STANDARD OPTIONS:")
155
+ opt.separator("SYSTEM OPTIONS:")
129
156
 
130
- opt.on('--debug', "show debugging infromation") do
157
+ opt.on('--debug', "show debugging information") do
131
158
  $DEBUG = true
132
159
  end
133
-
134
- opt.on_tail('--help' , '-h', 'display this help information') do
135
- puts opt
136
- exit
137
- end
138
160
  end
139
161
 
140
162
  optparse.parse!(ARGV)
141
163
 
142
164
  root = ARGV.shift || Dir.pwd
143
-
144
- vcs = VCLog::Adapters.factory #(root)
165
+ conf = VCLog::Config.new(root)
166
+ vcs = VCLog::Adapters.factory(conf)
145
167
 
146
168
  case type
147
169
  when :bump
@@ -210,8 +232,5 @@ module VCLog
210
232
  # Dir.glob('{history,changes,changelog}{,.*}', File::FNM_CASEFOLD).first
211
233
  # end
212
234
  #end
213
-
214
- end
215
-
216
- # VCLog Copyright (c) 2008 Thomas Sawyer
235
+ =end
217
236
 
@@ -0,0 +1,65 @@
1
+ require 'vclog/heuristics'
2
+
3
+ module VCLog
4
+
5
+ #
6
+ class Config
7
+
8
+ # File glob used to find the vclog configuration directory.
9
+ CONFIG_GLOB = '{.vclog,.config/vclog,config/vclog}/'
10
+
11
+ # File glob used to find project root directory.
12
+ ROOT_GLOB = '{.vclog/,.config/vclog/,config/vclog/,.git/,README*}/'
13
+
14
+ #
15
+ def initialize(root=nil)
16
+ @root = root || lookup_root || Dir.pwd
17
+ @dir = Dir[File.join(root, CONFIG_GLOB)]
18
+ @level = 0
19
+ end
20
+
21
+ # Project's root directory.
22
+ attr :root
23
+
24
+ # Configuration directory.
25
+ attr :dir
26
+
27
+ # Default change level.
28
+ #
29
+ # TODO: get from config file.
30
+ attr_accessor :level
31
+
32
+ #
33
+ def heuristics
34
+ @heuristics ||= Heuristics.load(heuristics_file)
35
+ end
36
+
37
+ #
38
+ def heuristics_file
39
+ @heuristics_file ||= Dir[File.join(dir, 'rules.rb')].first
40
+ end
41
+
42
+ # Find project root. This searches up from the current working
43
+ # directory for the following paths (in order):
44
+ #
45
+ # .vclog/
46
+ # .config/vclog/
47
+ # config/vclog/
48
+ # .git/
49
+ # README*
50
+ #
51
+ def lookup_root
52
+ root = nil
53
+ Dir.ascend(Dir.pwd) do |path|
54
+ check = Dir[ROOT_GLOB].first
55
+ if check
56
+ root = path
57
+ break
58
+ end
59
+ end
60
+ root || Dir.pwd
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -10,17 +10,20 @@ module VCLog
10
10
  #
11
11
  attr :vcs
12
12
 
13
+ # New Formmater.
14
+ #
15
+ # vcs - an instance of a subclass of VCS::Abstract
13
16
  #
14
17
  def initialize(vcs)
15
18
  @vcs = vcs
16
19
  end
17
20
 
18
- #
21
+ # Returns a Changelog object taken from the VCS.
19
22
  def changelog
20
23
  @vcs.changelog
21
24
  end
22
25
 
23
- #
26
+ # Returns a History object garnered form the VCS.
24
27
  def history
25
28
  @vcs.history
26
29
  end
@@ -50,20 +53,24 @@ module VCLog
50
53
  @options.homepage
51
54
  end
52
55
 
53
- #
56
+ # TODO: let be nil and let template make a default if wanted
54
57
  def title
55
58
  return @options.title if @options.title
56
59
  case @doctype
57
60
  when :history
58
- "Release History"
61
+ "RELEASE HISTORY"
59
62
  else
60
- "Change Log"
63
+ "CHANGELOG"
61
64
  end
62
65
  end
63
66
 
64
67
  #
65
- def display(doctype, format, options={})
66
- options = OpenStruct.new(options)
68
+ #--
69
+ # NOTE: ERBs trim_mode is broken --it removes an extra space.
70
+ # So we can't use it for plain text templates.
71
+ #++
72
+ def display(doctype, format, options)
73
+ options = OpenStruct.new(options) if Hash === options
67
74
 
68
75
  @doctype = doctype
69
76
  @format = format
@@ -71,9 +78,19 @@ module VCLog
71
78
 
72
79
  require_formatter(format)
73
80
 
74
- tmp = File.read(File.join(DIR, 'templates', "#{@doctype}.#{@format}"))
75
- erb = ERB.new(tmp)
76
- erb.result(binding)
81
+ tmp_file = Dir[File.join(DIR, 'templates', "#{@doctype}.#{@format}.{erb,rb}")].first
82
+
83
+ tmp = File.read(tmp_file)
84
+
85
+ case File.extname(tmp_file)
86
+ when '.rb'
87
+ eval(tmp, binding)
88
+ when '.erb'
89
+ erb = ERB.new(tmp, nil, '<>')
90
+ erb.result(binding)
91
+ else
92
+ raise "unrecognized template - #{tmp_file}"
93
+ end
77
94
  end
78
95
 
79
96
  private
@@ -0,0 +1,20 @@
1
+ set :major, 1, "Major Enhancements"
2
+ set :minor, -1, "Minor Enhancements"
3
+ set :admin, -2, "Administrative Changes"
4
+
5
+ on /updated? (README|PROFILE|PACKAGE|VERSION|MANIFEST)/ do
6
+ :admin
7
+ end
8
+
9
+ on /bump(ed)? version/ do
10
+ :admin
11
+ end
12
+
13
+ on /^(\w+):/ do |word|
14
+ word.to_sym
15
+ end
16
+
17
+ on /\[(\w+)\]\s*$/ do |word|
18
+ word.to_sym
19
+ end
20
+