Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 43 additions & 18 deletions mixbump
Original file line number Diff line number Diff line change
@@ -1,33 +1,53 @@
#!/usr/local/bin/elixir

# get mix.exs path
{command, mix_exs_path} =
if length(System.argv) > 0 do

if length(System.argv) == 1 do
# No command specified, just bump
[mix_exs_path | _] = System.argv
command = nil
[path | _] = System.argv
{ nil, path}
else
[command, mix_exs_path | _] = System.argv
if command == "a", do: command = "add"
if command == "c", do: command = "commit"
[command, path | _] = System.argv
command =
case command do
"d" -> "diff"
"a" -> "add"
"c" -> "commit"
end
{command, path}
end

# Allow specifying path without mix.exs if it contains it.
if !Regex.match?(~r/mix.exs$/, mix_exs_path) && File.exists?("#{mix_exs_path}/mix.exs") do
mix_exs_path = Path.join [mix_exs_path, "mix.exs"]
end
else
mix_exs_path = nil
{nil, nil}
end

# default to current directory, if no path specified
mix_exs_path =
if is_nil(mix_exs_path), do: ".", else: mix_exs_path

# Allow specifying path without mix.exs if it contains it.
mix_exs_path =
if !Regex.match?(~r/mix.exs$/, mix_exs_path) do
Path.join [mix_exs_path, "mix.exs"]
else
mix_exs_path
end

if command && command != "add" && command != "commit" do
mix_exs_path = nil
IO.puts "Unrecognized command #{command}; \"add\" and \"commit\" are supported"
mix_exs_path =
if File.exists?(mix_exs_path), do: mix_exs_path, else: nil

mix_exs_path =
if command && command != "diff" && command != "add" && command != "commit" do
IO.puts "Unrecognized command #{command}; \"diff\", \"add\" and \"commit\" are supported"
nil
else
mix_exs_path
end

if mix_exs_path && File.exists?(mix_exs_path) do
if !is_nil(mix_exs_path) do
# Update mix.exs in-place.
IO.puts "Bumping #{mix_exs_path}"
File.write mix_exs_path, (
File.read!(mix_exs_path)
|> String.split("\n")
Expand All @@ -36,14 +56,17 @@ if mix_exs_path && File.exists?(mix_exs_path) do
{sub, _} = Integer.parse(sub)
old_version = "#{major}.#{minor}.#{sub}"
new_version = "#{major}.#{minor}.#{sub + 1}"
IO.puts "Bumping from #{old_version} to #{new_version}"
IO.puts "Bumping \"#{mix_exs_path}\", from #{old_version} to #{new_version}"
"version: \"#{major}.#{minor}.#{sub + 1}\""
end)
end)
|> Enum.join("\n")
)

case command do
"diff" ->
{output, _} = System.cmd "git", ~w[diff mix.exs], cd: Path.dirname(mix_exs_path)
IO.puts output
"add" ->
System.cmd "git", ~w[add mix.exs], cd: Path.dirname(mix_exs_path)
{output, _} = System.cmd "git", ~w[diff --cached], cd: Path.dirname(mix_exs_path)
Expand All @@ -54,13 +77,15 @@ if mix_exs_path && File.exists?(mix_exs_path) do
{output, _} = System.cmd "git", ~w[diff HEAD~], cd: Path.dirname(mix_exs_path)
IO.puts output
_ ->
{output, _} = System.cmd "git", ~w[diff mix.exs], cd: Path.dirname(mix_exs_path)
IO.puts output
nil
end

else
IO.puts """
Please specify the path to a valid mix.exs file.
Usage: mixbump path/to/mix.exs
mixbump d path/to/mix.exs (git diff)
mixbump a path/to/mix.exs (git add mix.exs)
mixbump c path/to/mix.exs (git add mix.exs; git commit -m "Version bump")
"""
end