Skip to content

Commit 54723c5

Browse files
committed
Refactor module structure
1 parent 06a0683 commit 54723c5

File tree

6 files changed

+39
-16
lines changed

6 files changed

+39
-16
lines changed
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
defmodule ElixirScript.CLI do
1+
defmodule ElixirScript.CommandLine do
22
alias ElixirScript.Context
33
alias ElixirScript.Core
44
alias ElixirScript.CustomLogger, as: Logger
55

6-
def main(_args \\ []) do
6+
def main(args \\ []) do
77
Logger.debug("Running in debug mode")
8+
{opts, _, _} = OptionParser.parse(args, strict: [help: :boolean])
9+
10+
if opts[:help] do
11+
print_help()
12+
else
13+
run_script()
14+
end
15+
end
16+
17+
defp run_script do
818
Logger.debug("All Environment Variables: #{inspect(System.get_env(), limit: :infinity, printable_limit: :infinity)}")
919

1020
script = Core.get_env_input("script", required: true)
@@ -15,7 +25,16 @@ defmodule ElixirScript.CLI do
1525
Logger.debug("Result output: #{inspect(value, limit: :infinity, printable_limit: :infinity)}")
1626
end
1727

18-
defp log_debug(message) do
19-
if @debug_mode, do: Logger.debug(message)
28+
defp print_help do
29+
IO.puts("""
30+
Usage:
31+
script [OPTIONS]
32+
33+
Options:
34+
--help Show this help message and exit.
35+
36+
Example:
37+
INPUT_SCRIPT="IO.puts('Hello, world!')" script
38+
""")
2039
end
2140
end

lib/core.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule ElixirScript.Core do
2-
alias ElixirScript.Command
3-
alias ElixirScript.CommandUtils
4-
alias ElixirScript.FileCommand
2+
alias ElixirScript.GitHubActions.Command
3+
alias ElixirScript.GitHubActions.CommandUtils
4+
alias ElixirScript.GitHubActions.EnvironmentFileCommand
55

66
def parse_args(args) do
77
aliases = [script: :s, debug: :d]
@@ -34,9 +34,9 @@ defmodule ElixirScript.Core do
3434

3535
def set_output(name, value) do
3636
if System.get_env("GITHUB_OUTPUT") do
37-
FileCommand.issue_file_command(
37+
EnvironmentFileCommand.issue_file_command(
3838
"OUTPUT",
39-
FileCommand.prepare_key_value_message(name, CommandUtils.to_command_value(value))
39+
EnvironmentFileCommand.prepare_key_value_message(name, CommandUtils.to_command_value(value))
4040
)
4141
else
4242
Command.issue_command('set-output', name, CommandUtils.to_command_value(value))

lib/file_command.ex renamed to lib/github_actions/environment_file_command.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
defmodule ElixirScript.FileCommand do
2-
alias ElixirScript.CommandUtils
1+
defmodule ElixirScript.GitHubActions.EnvironmentFileCommand do
2+
@moduledoc """
3+
Handles GitHub Actions Workflow Commands Environment Files.
4+
5+
This module is designed to interact with GitHub Actions by issuing
6+
workflow commands to environment files as specified in the GitHub Actions documentation:
7+
[Workflow Commands for GitHub Actions](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#environment-files).
8+
"""
39

410
def issue_file_command(command, command_value) do
511
file_path = System.get_env("GITHUB_#{command}", "")

lib/command.ex renamed to lib/github_actions/workflow_command.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
defmodule ElixirScript.Command do
2-
alias ElixirScript.CommandUtils
3-
1+
defmodule ElixirScript.GitHubActions.Command do
42
def issue_command(command, name, command_value) do
53
IO.puts("::#{command} name=#{name}::#{command_value}")
64
end

lib/command_utils.ex renamed to lib/github_actions/workflow_command_utils.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule ElixirScript.CommandUtils do
1+
defmodule ElixirScript.GitHubActions.CommandUtils do
22

33
def to_command_value(nil), do: ""
44

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ defmodule ElixirScript.MixProject do
1313

1414
def escript do
1515
[
16-
main_module: ElixirScript.CLI
16+
main_module: ElixirScript.CommandLine
1717
]
1818
end
1919

0 commit comments

Comments
 (0)