Last active
April 18, 2022 04:08
-
-
Save wingyplus/38111419ebc33e02df01d78cc8f1fa82 to your computer and use it in GitHub Desktop.
headver Elixir implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# headver.exs - a headver implementation in Elixir. See https://github.com/line/headver. | |
# | |
# Run | |
# $ elixir headver.exs --head=5 --build=23 --suffix=qa | |
# 5.2142.23+qa | |
Mix.install([ | |
{:timex, "~> 3.7"} | |
]) | |
{options, _, _} = | |
OptionParser.parse(System.argv(), | |
strict: [ | |
head: :integer, | |
build: :integer, | |
suffix: :string | |
] | |
) | |
head = Keyword.fetch!(options, :head) | |
build = Keyword.fetch!(options, :build) | |
suffix = Keyword.fetch!(options, :suffix) | |
{year, weeknumber} = Timex.iso_week(DateTime.utc_now()) | |
yearweek = "#{rem(year, 100)}#{weeknumber}" | |
version = "#{head}.#{yearweek}.#{build}" | |
version = | |
if String.length(suffix) != 0 do | |
"#{version}+#{suffix}" | |
else | |
version | |
end | |
IO.puts(version) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment