Metastatic.CLI
(Metastatic v0.10.4)
View Source
Shared utilities for Metastatic CLI commands.
Provides common functionality for Mix tasks including:
- Adapter lookup by language or file extension
- File path handling
- Error formatting
- Success/error reporting
Summary
Functions
Detect language from file extension.
Print error and exit with status code 1.
Format error message for CLI output.
Format info message for CLI output.
Format success message for CLI output.
Get adapter for a given language.
Read file contents.
Write file contents, creating directories if needed.
Types
Functions
Detect language from file extension.
Examples
iex> Metastatic.CLI.detect_language("foo.py")
{:ok, :python}
iex> Metastatic.CLI.detect_language("foo.ex")
{:ok, :elixir}
iex> Metastatic.CLI.detect_language("foo.erl")
{:ok, :erlang}
iex> Metastatic.CLI.detect_language("foo.txt")
{:error, "Cannot detect language from extension: .txt"}
Print error and exit with status code 1.
Format error message for CLI output.
Prefixes with red "Error: " for terminal output.
Format info message for CLI output.
Prefixes with blue info icon for terminal output.
Format success message for CLI output.
Prefixes with green checkmark for terminal output.
Get adapter for a given language.
Examples
iex> Metastatic.CLI.get_adapter(:python)
{:ok, Metastatic.Adapters.Python}
iex> Metastatic.CLI.get_adapter(:unknown)
{:error, "Unsupported language: unknown"}
Read file contents.
Examples
iex> Metastatic.CLI.read_file("test.py")
{:ok, "print('hello')"}
iex> Metastatic.CLI.read_file("nonexistent.py")
{:error, "Cannot read file test.py: enoent"}
Write file contents, creating directories if needed.
Examples
iex> Metastatic.CLI.write_file("output/test.py", "print('hello')")
:ok