Skip to content

Commit

Permalink
Merge pull request #107 from bethesque/master
Browse files Browse the repository at this point in the history
feat: support showing file and current without any descriptive text
  • Loading branch information
gregorym authored Oct 8, 2020
2 parents 63861f0 + d741a1a commit 9a84380
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions bin/bump
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ OptionParser.new do |opts|
opts.on("--replace-in FILE", String, "Replace old version with the new version additionally in this file") { |f| (options[:replace_in] ||= []) << f }
opts.on("--changelog", "Update CHANGELOG.md") { options[:changelog] = true }
opts.on("--edit-changelog", "Use $EDITOR to open changelog before committing, e.g. 'subl -n -w' or 'nano'.") { options[:changelog] = :editor }
opts.on("--value-only", "Do not prefix the output with any descriptive text") { options[:value_only] = true }
opts.on("-h", "--help", "Show this.") { puts opts; exit }
end.parse!

Expand Down
6 changes: 3 additions & 3 deletions lib/bump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ def run(bump, options = {})

bump_set(options[:version], options)
when "current"
["Current version: #{current}", 0]
[options[:value_only] ? current : "Current version: #{current}", 0]
when "show-next"
increment = options[:increment]
raise InvalidIncrementError unless BUMPS.include?(increment)

[next_version(increment), 0]
when "file"
["Version file path: #{file}", 0]
[options[:value_only] ? file : "Version file path: #{file}", 0]
else
raise InvalidOptionError
end
Expand Down Expand Up @@ -154,7 +154,7 @@ def bump(file, current, next_version, options)
commit next_version, options if options[:commit]

# tell user the result
["Bump version #{current} to #{next_version}", 0]
[options[:value_only] ? next_version : "Bump version #{current} to #{next_version}", 0]
end

def open_changelog(log)
Expand Down
21 changes: 20 additions & 1 deletion spec/bump_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,18 @@
end
end

context "when value_only is not specified" do
it "includes descriptive text" do
bump("current").should include("Current version:")
end
end

context "when value_only is specified" do
it "only returns the version" do
bump("current --value-only").should eq("4.2.3\n")
end
end

it "fails when asked to bump in missing additional files" do
bump("patch --replace-in Readme.md", fail: true)
end
Expand Down Expand Up @@ -240,7 +252,14 @@
end

it "show file path" do
bump("file").should include(version_file)
output = bump("file")
output.should include(version_file)
output.should include("Version file path:")
read(version_file).should include("VERSION = ")
end

it "show file path with --value-only" do
bump("file --value-only").should eq(version_file + "\n")
read(version_file).should include("VERSION = ")
end

Expand Down

0 comments on commit 9a84380

Please sign in to comment.