YAVM 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56bc64875e0c991017a57cd0b3e994ad36eb4c45
4
- data.tar.gz: 02d71dbe311990e921e68fc3b7e9f7129de18462
3
+ metadata.gz: facb897561d347c7ffc318e9487ee3c7e5adde5d
4
+ data.tar.gz: 54c812978d0f7ac5da5d9bc57653908cf31a5262
5
5
  SHA512:
6
- metadata.gz: 68751c151d42bcf8bf5bb3e423ccf219c32654743f72f227b89a29d7389dd4c83c6eab3d40aa3b73e2070ed9defa28acb865e7b4c89eaa9c93843630fdaf93bc
7
- data.tar.gz: 940bae764ac8ba2f4ff64908185547360384013c47b321301ea2d7c15e105a815a271d39cec0095c71c337f67f75c6c510634d1ba2c7f5d9c505a7a3bac65d46
6
+ metadata.gz: 6e0a066aecde80ba4f9a547b3d1d04d3056bd3af37df82147b0b4fe852f40a8c723fd0744e5fd1f0a30210c2cc9d29c40483dc426be752a1d533616ed232521e
7
+ data.tar.gz: 76d9eea472c53de52d227e5bf2a72908ba77467a493347035694a28476127059f7d9535e0aebaea09c22f4b2e32dd014d53bd3c42f8fd2d3ac5e7572ed12f70b
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # YAVM: Yet Another Version Manager
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/YAVM.svg)](http://badge.fury.io/rb/YAVM)
4
+ [![Build Status](https://travis-ci.org/lewiseason/yavm.svg?branch=master)](https://travis-ci.org/lewiseason/yavm)
5
+
3
6
  A tiny gem for managing project version numbers.
4
7
 
5
8
  Heavily inspired by the `semver` gem, this is a tiny utility for managing version numbers,
@@ -12,7 +15,8 @@ which includes support for multiple version format stores:
12
15
 
13
16
  With planned support for:
14
17
 
15
- * Python distutils package support
18
+ * Python distutils package
19
+ * Possibly gem `::Version`
16
20
 
17
21
  # Usage
18
22
 
@@ -84,10 +88,10 @@ Now on 1.0.3
84
88
  - [x] help
85
89
  - [x] package.json support
86
90
  - [x] bower.json support
87
- - [ ] when changing version, show new one
91
+ - [x] when changing version, show new one
88
92
  - [ ] programmatic interface
89
93
  - [ ] tests
90
94
  - [ ] handle invalid version info (see Version#parse)
91
- - [ ] 'version init'
95
+ - [x] 'version init'
92
96
  - [ ] quick mode (when finding versions - short circuit once one is found)
93
97
  - [ ] raise sensible exceptions
@@ -0,0 +1,24 @@
1
+ Feature: Command Line Initialization
2
+ The command line interface should support initializing version stores and
3
+ enforce consistency.
4
+
5
+ Background:
6
+ Given I have a project called "project"
7
+
8
+ Scenario: Project with no version number
9
+ Given I run `version`
10
+ Then the exit status should be 1
11
+
12
+ Scenario: Initialize versioning on a project
13
+ Given I run `version init`
14
+ Then the exit status should be 0
15
+
16
+ When I run `version`
17
+ Then the output should contain "0.0.0"
18
+
19
+ Scenario: Don't initialize if the project already contains version information
20
+ Given I run `version init`
21
+ Then the exit status should be 0
22
+
23
+ When I run `version init`
24
+ Then the exit status should be 1
@@ -0,0 +1,8 @@
1
+ require 'fileutils'
2
+
3
+ Given(/^I have a project called "(.*?)"$/) do |name|
4
+ @project_dir = "tmp/aruba/#{name}"
5
+
6
+ FileUtils.mkdir_p @project_dir
7
+ Dir.chdir @project_dir
8
+ end
@@ -0,0 +1,10 @@
1
+ require 'aruba/cucumber'
2
+
3
+ Before do |scenario|
4
+ @dirs = ['tmp/aruba']
5
+ @cwd = Dir.pwd
6
+ end
7
+
8
+ After do |scenario|
9
+ Dir.chdir @cwd
10
+ end
@@ -2,23 +2,27 @@ require 'docopt'
2
2
  require 'yavm/stores'
3
3
 
4
4
  module YAVM
5
+ #
6
+ # Command line interface for the `version` command.
7
+ #
5
8
  class CommandLine
6
-
7
9
  def initialize
8
- @invocation = File.basename($0)
10
+ @invocation = File.basename($PROGRAM_NAME)
9
11
  end
10
12
 
11
13
  def invoke!
12
- @args = Docopt::docopt(doc)
13
- command = @args.select { |a, v| commands.include?(a) && v }.keys.first
14
- command = 'show' if command.nil?
14
+ @args = Docopt.docopt(doc)
15
+ command = @args.select { |a, v| commands.include?(a) && v }.keys.first
16
+ command ||= 'show'
15
17
 
16
- versions = YAVM::Stores.locate_versions
18
+ versions = Stores.locate_versions
17
19
 
18
20
  if versions.empty? && !@args['init']
19
- puts "There doesn't seem to be any versioning information on this project."
20
- puts "Use native versioning tools (see docs for support), or run `#{@invocation} init`"
21
- puts "to use the default versioning method."
21
+ puts <<-MESSAGE.gsub(/^ {10}/, '').strip
22
+ There doesn't seem to be any versioning information on this project.
23
+ Use native versioning tools (see docs for support), or run `#{@invocation} init`
24
+ to use the built-in versioning method.
25
+ MESSAGE
22
26
  exit(1)
23
27
  end
24
28
 
@@ -33,34 +37,59 @@ module YAVM
33
37
  puts "#{version}"
34
38
 
35
39
  when 'inc'
36
- if @args['major']
37
- version.major += 1
38
- version.minor = version.patch = 0
39
- version.special = version.meta = nil
40
-
41
- elsif @args['minor']
42
- version.minor += 1
43
- version.patch = 0
44
- version.special = version.meta = nil
45
-
46
- elsif @args['patch']
47
- version.patch += 1
48
- version.special = version.meta = nil
49
-
50
- end
40
+ version.increment :major if @args['major']
41
+ version.increment :minor if @args['minor']
42
+ version.increment :patch if @args['patch']
51
43
 
52
44
  versions.set_all!(version)
53
45
 
46
+ puts "#{version}"
47
+
54
48
  when 'special'
55
49
  version.special = @args['<string>']
56
-
57
50
  versions.set_all!(version)
58
51
 
52
+ puts "#{version}"
53
+
59
54
  when 'meta'
60
55
  version.meta = @args['<string>']
61
-
62
56
  versions.set_all!(version)
63
57
 
58
+ puts "#{version}"
59
+
60
+ when 'init'
61
+ # Check if a Semver store is already defined - we should never attempt
62
+ # to initialize a new one if an existing one is found.
63
+ if versions.map { |v| v.store.class }.include? YAVM::Stores::Semver
64
+ message = <<-MESSAGE.gsub(/^ {12}/, '').strip
65
+ A .semver file already exists at version #{version}
66
+ See `#{@invocation} help` for details on working with
67
+ the existing version file.
68
+ MESSAGE
69
+
70
+ fail message
71
+ end
72
+
73
+ store = Stores::Semver.new
74
+ store.create!
75
+
76
+ semver = Version.new(store)
77
+ store.set!(semver)
78
+
79
+ versions = Stores.locate_versions
80
+
81
+ if version
82
+ puts <<-MESSAGE.gsub(/^ {12}/, '').strip
83
+ A version is already defined (#{version}),
84
+ I'll copy that to the new .semver file.
85
+
86
+ MESSAGE
87
+
88
+ versions.set_all!(version)
89
+ end
90
+
91
+ puts "#{version || semver}"
92
+
64
93
  when 'format'
65
94
  puts "#{version.format(@args['<string>'])}"
66
95
 
@@ -69,28 +98,28 @@ module YAVM
69
98
 
70
99
  when 'help'
71
100
  Docopt::Exit.set_usage(nil)
72
- raise Docopt::Exit, doc.strip
101
+ fail Docopt::Exit, doc.strip
73
102
  end
74
-
75
103
  end
76
104
 
77
105
  private
78
106
 
79
- def choose_authoritative!(versions)
80
- puts "Multiple version stores are in use, and aren't consistent."
81
- puts " Please select the authoritative version:\n\n"
82
- puts "WARNING: File munging is dangerous. A manual resolution might be safer.\n\n"
107
+ def choose_authoritative!(versions) # rubocop:disable Metrics/AbcSize
108
+ puts "Multiple version stores are available, and aren't consistent."
109
+ puts "Please select the authoritative version:\n\n"
110
+ puts "WARNING: Munging can be dangerous - a manual resolution might be safer.\n\n"
83
111
 
84
112
  selection = ''
85
113
 
86
114
  while selection.is_a? String
87
115
  versions.each_with_index do |version, index|
88
- puts " %3s: %-15s [%s]" % [index+1, version, version.store.name]
116
+ puts format(' %3s: %-15s [%s]', index + 1, version, version.store.name)
89
117
  end
90
118
 
91
119
  print "\nSelection: "
92
120
  selection = STDIN.gets.chomp
93
121
 
122
+ # rubocop:disable Style/CaseEquality
94
123
  if selection.to_i.to_s == selection && (1..versions.size) === selection.to_i
95
124
  selection = selection.to_i
96
125
  break
@@ -103,7 +132,6 @@ module YAVM
103
132
 
104
133
  puts "Now on #{authoritative_version}"
105
134
  exit(0)
106
-
107
135
  end
108
136
 
109
137
  def doc
@@ -112,6 +140,7 @@ module YAVM
112
140
 
113
141
  Usage:
114
142
  #{@invocation}
143
+ #{@invocation} init
115
144
  #{@invocation} inc (major|minor|patch)
116
145
  #{@invocation} special [<string>]
117
146
  #{@invocation} meta [<string>]
@@ -121,6 +150,7 @@ module YAVM
121
150
 
122
151
  Options:
123
152
  inc Increment a specific version number
153
+ init Create a .semver file for tracking versioning
124
154
  special Set a special (eg: pre-release) suffix
125
155
  meta Set a metadata version suffix
126
156
  format Display version in specific format (%M, %m, %p, %s, %t)
@@ -139,12 +169,11 @@ module YAVM
139
169
  end
140
170
 
141
171
  def version_commands
142
- ['show', 'inc', 'special', 'meta', 'format', 'tag']
172
+ %w(show inc special meta init format tag)
143
173
  end
144
174
 
145
175
  def support_commands
146
- ['help']
176
+ %w(help)
147
177
  end
148
-
149
178
  end
150
179
  end
@@ -1,3 +1,4 @@
1
+ require 'fileutils'
1
2
  require 'yaml'
2
3
  require 'yavm/stores/base'
3
4
 
@@ -13,6 +14,10 @@ module YAVM
13
14
  './.semver'
14
15
  end
15
16
 
17
+ def create!
18
+ FileUtils.touch '.semver'
19
+ end
20
+
16
21
  def data
17
22
  @data ||= YAML.load_file(filename)
18
23
  end
@@ -10,13 +10,13 @@ module YAVM
10
10
  def initialize(store, vobject = nil)
11
11
  self.store = store
12
12
 
13
- if vobject
14
- case vobject
15
- when String
16
- parse(vobject)
17
- when Hash
18
- load(vobject)
19
- end
13
+ case vobject
14
+ when String
15
+ parse(vobject)
16
+ when Hash
17
+ load(vobject)
18
+ when nil
19
+ empty
20
20
  end
21
21
  end
22
22
 
@@ -37,7 +37,7 @@ module YAVM
37
37
  dump[:special] ||= ''
38
38
  dump[:meta] ||= ''
39
39
 
40
- return dump
40
+ dump
41
41
  end
42
42
 
43
43
  def to_yaml
@@ -51,6 +51,7 @@ module YAVM
51
51
  def format(string = '')
52
52
  string = string.dup
53
53
 
54
+ # ? http://stackoverflow.com/a/8132638
54
55
  string.gsub!('%M', major.to_s)
55
56
  string.gsub!('%m', minor.to_s)
56
57
  string.gsub!('%p', patch.to_s)
@@ -58,14 +59,36 @@ module YAVM
58
59
  string.gsub!('%t', meta ? "+#{meta}" : '')
59
60
  string.gsub!('%%', '%')
60
61
 
61
- return string
62
+ string
62
63
  end
63
64
 
65
+ # rubocop:disable Style/RedundantSelf
64
66
  def ==(other)
65
67
  self.major == other.major &&
66
- self.minor == other.minor &&
67
- self.patch == other.patch &&
68
- self.special == other.special
68
+ self.minor == other.minor &&
69
+ self.patch == other.patch &&
70
+ self.special == other.special
71
+ end
72
+
73
+ def increment(what)
74
+ case what
75
+ when :major
76
+ self.major += 1
77
+ self.minor = 0
78
+ self.patch = 0
79
+ when :minor
80
+ self.minor += 1
81
+ self.patch = 0
82
+ when :patch
83
+ self.patch += 1
84
+ else
85
+ fail "Can't increment #{what}"
86
+ end
87
+
88
+ if [:major, :minor, :patch].include? what
89
+ self.special = nil
90
+ self.meta = nil
91
+ end
69
92
  end
70
93
 
71
94
  private
@@ -75,10 +98,16 @@ module YAVM
75
98
  value.empty? ? nil : value
76
99
  end
77
100
 
101
+ def empty
102
+ @_version = OpenStruct.new ({
103
+ major: 0, minor: 0, patch: 0, special: '', meta: ''
104
+ })
105
+ end
106
+
78
107
  def parse(string)
79
108
  match = string.match(/\A(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?:-(?<special>[a-z0-9]+))?(?:\+(?<meta>[a-z0-9]+))?\z/i)
80
109
 
81
- @_version = Hash[ match.names.zip( match.captures ) ]
110
+ @_version = Hash[match.names.zip(match.captures)]
82
111
  @_version = OpenStruct.new(@_version)
83
112
  integerize!
84
113
  end
@@ -98,8 +127,7 @@ module YAVM
98
127
  # Allows calling "version.minor" and the like on the Version instance
99
128
  #
100
129
  def_delegators :@_version,
101
- :major, :minor, :patch,
102
- :major=, :minor=, :patch=, :special=, :meta=
103
-
130
+ :major, :minor, :patch,
131
+ :major=, :minor=, :patch=, :special=, :meta=
104
132
  end
105
133
  end
@@ -24,7 +24,7 @@ module YAVM
24
24
  end
25
25
 
26
26
  def_delegators :versions, :<<, :length, :size, :[],
27
- :first, :each, :each_with_index, :empty?, :any?
27
+ :first, :each, :each_with_index, :empty?, :any?, :map
28
28
 
29
29
  private
30
30
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: YAVM
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lewis Eason
@@ -50,6 +50,66 @@ dependencies:
50
50
  - - "~>"
51
51
  - !ruby/object:Gem::Version
52
52
  version: 1.8.1
53
+ - !ruby/object:Gem::Dependency
54
+ name: rubocop
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.28.0
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 0.28.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 0.28.0
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: 0.28.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: cucumber
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 1.3.18
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.3.18
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.18
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: 1.3.18
93
+ - !ruby/object:Gem::Dependency
94
+ name: aruba
95
+ requirement: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 0.6.2
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.6.2
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 0.6.2
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: 0.6.2
53
113
  description: A tiny gem for managing project version numbers
54
114
  email: me@lewiseason.co.uk
55
115
  executables:
@@ -59,8 +119,10 @@ extra_rdoc_files: []
59
119
  files:
60
120
  - README.md
61
121
  - bin/version
122
+ - features/initialization.feature
123
+ - features/step_definitions/project.rb
124
+ - features/support/env.rb
62
125
  - lib/yavm.rb
63
- - lib/yavm/README.md
64
126
  - lib/yavm/command_line.rb
65
127
  - lib/yavm/stores.rb
66
128
  - lib/yavm/stores/base.rb
@@ -94,5 +156,8 @@ rubygems_version: 2.2.2
94
156
  signing_key:
95
157
  specification_version: 4
96
158
  summary: Yet Another Version Manager
97
- test_files: []
159
+ test_files:
160
+ - features/initialization.feature
161
+ - features/support/env.rb
162
+ - features/step_definitions/project.rb
98
163
  has_rdoc:
@@ -1,93 +0,0 @@
1
- # YAVM: Yet Another Version Manager
2
-
3
- A tiny gem for managing project version numbers.
4
-
5
- Heavily inspired by the `semver` gem, this is a tiny utility for managing version numbers,
6
- which includes support for multiple version format stores:
7
-
8
- * The `semver` gem's `.semver` file
9
- * node.js `package.json` files
10
- * bower `bower.json` files
11
- * ruby `.gemspec` files
12
-
13
- With planned support for:
14
-
15
- * Python distutils package support
16
-
17
- # Usage
18
-
19
- *Exhaustive usage patterns can be found at `version help`*
20
-
21
- ``` shell
22
- # Install
23
- $ gem install yavm
24
-
25
- # In a language/framework without a supported versioning system:
26
- $ version init
27
- $ version # => 0.0.0
28
-
29
- # In an existing project with supported versioning:
30
- version # => 0.2.0
31
-
32
- # Basic Usage
33
- $ version inc minor # => 0.3.0
34
- $ version inc major # => 1.0.0
35
- $ version special pre4 # => 1.0.0-pre4
36
- $ version special # => 1.0.0
37
- $ version meta 20141113 # => 1.0.0 (meta not displayed by default)
38
- $ version tag # => v1.0.0+20141113 (useful for version control)
39
- $ version format "%M.%m" # => 1.0
40
- ```
41
-
42
- ## Available Format Tags
43
-
44
- Tag | Meaning
45
- ----|---------------------
46
- %M | **M**ajor
47
- %m | **M**inor
48
- %p | **P**atch
49
- %s | **S**pecial
50
- %t | Me**t**a
51
- %% | Literal % Character
52
-
53
- ## Conflict Resolution
54
-
55
- If your project contains multiple supported version "stores", YAVM will keep them in sync.
56
- If they go out of sync outside of YAVM, you will be prompted to pick the canonical/authoritative
57
- version, and all other stores will be updated.
58
-
59
- ``` text
60
- $ version
61
- Multiple version stores are in use, and aren't consistent.
62
- Please select the authoritative version:
63
-
64
- WARNING: File munging is dangerous. A manual resolution might be safer.
65
-
66
- 1: 1.0.0 [.semver file]
67
- 2: 1.0.3 [bower.json file]
68
- 3: 0.0.0 [gemspec: ./yavm.gemspec]
69
-
70
- Selection: 2
71
- Now on 1.0.3
72
- ```
73
-
74
- # Roadmap
75
-
76
- ## Features
77
-
78
- - [x] show version
79
- - [x] increment
80
- - [x] set special
81
- - [x] set meta
82
- - [x] formatting
83
- - [x] tags
84
- - [x] help
85
- - [x] package.json support
86
- - [x] bower.json support
87
- - [ ] when changing version, show new one
88
- - [ ] programmatic interface
89
- - [ ] tests
90
- - [ ] handle invalid version info (see Version#parse)
91
- - [ ] 'version init'
92
- - [ ] quick mode (when finding versions - short circuit once one is found)
93
- - [ ] raise sensible exceptions