Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 12 additions & 2 deletions lib/mix/tasks/git_ops.project_info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Mix.Tasks.GitOps.ProjectInfo do
## Switches:

* `--format|-f` selects the output format. Currently suported output formats
are `json`, `toml`, `github-actions` and `shell`.
are `json`, `toml`, `github-actions`, `shell` and `dotenv`.
"""

alias GitOps.Config
Expand All @@ -30,6 +30,7 @@ defmodule Mix.Tasks.GitOps.ProjectInfo do

opts
|> Keyword.get(:format)
|> String.downcase()
|> case do
"toml" ->
format_toml(project, opts)
Expand All @@ -43,8 +44,11 @@ defmodule Mix.Tasks.GitOps.ProjectInfo do
"shell" ->
format_shell(project, opts)

"dotenv" ->
format_dotenv(project, opts)

format ->
raise "Invalid format `#{inspect(format)}`. Valid formats are `json`, `toml`, `github-actions` and `shell`."
raise "Invalid format `#{inspect(format)}`. Valid formats are `json`, `toml`, `github-actions`, `shell` and `dotenv`."
end
end

Expand Down Expand Up @@ -81,6 +85,12 @@ defmodule Mix.Tasks.GitOps.ProjectInfo do
IO.write(~s|export APP_NAME="#{name}"\nexport APP_VERSION="#{version}"\n|)
end

defp format_dotenv(project, _opts) do
{name, version} = extract_name_and_version_from_project(project)

IO.write(~s|APP_NAME="#{name}"\nAPP_VERSION="#{version}"\n|)
end

defp extract_name_and_version_from_project(project) do
%{app: name, version: version} =
project
Expand Down
17 changes: 15 additions & 2 deletions test/project_info_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ defmodule GitOps.Mix.Tasks.Test.ProjectInfoTest do
end
end

describe "Github Actions actual format" do
describe "Github Actions format" do
test "it is correctly formatted", %{name: name, version: version} do
actual = run(["--format", "github-actions"])

Expand All @@ -60,7 +60,7 @@ defmodule GitOps.Mix.Tasks.Test.ProjectInfoTest do
end
end

describe "Shell actual format" do
describe "Shell format" do
test "it is correctly formatted", %{name: name, version: version} do
actual = run(["--format", "shell"])

Expand All @@ -73,6 +73,19 @@ defmodule GitOps.Mix.Tasks.Test.ProjectInfoTest do
end
end

describe "Dotenv format" do
test "it is correctly formatted", %{name: name, version: version} do
actual = run(["--format", "dotenv"])

expected = """
APP_NAME="#{name}"
APP_VERSION="#{version}"
"""

assert actual == expected
end
end

def run(args) do
capture_io(fn ->
ProjectInfo.run(args)
Expand Down