Skip to content

Instantly share code, notes, and snippets.

@wingyplus
Last active April 18, 2022 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wingyplus/38111419ebc33e02df01d78cc8f1fa82 to your computer and use it in GitHub Desktop.
Save wingyplus/38111419ebc33e02df01d78cc8f1fa82 to your computer and use it in GitHub Desktop.
headver Elixir implementation
# 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