Skip to content

Commit

Permalink
Merge pull request #135 from ollien/check-if-wrapped
Browse files Browse the repository at this point in the history
  • Loading branch information
doawoo authored Apr 15, 2024
2 parents d94a9ad + 14e356c commit 8401598
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ end
If you wish you retrieve the argv passed to your program by Burrito use this snippet:
```elixir
args = Burrito.Util.Args.get_arguments() # this returns a list of strings
args = Burrito.Util.Args.argv() # this returns a list of strings
```
#### Maintenance Commands
Expand Down
21 changes: 19 additions & 2 deletions lib/util/args.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
defmodule Burrito.Util.Args do
@moduledoc """
This module provides a method to help fetch CLI arguments passed down
from the Zig wrapper binary.
This module provides a method to help fetch CLI arguments, whether passed down
from the Zig wrapper binary or from the the system.
"""

@doc """
Get CLI arguments passed down from the Zig wrapper binary. Do note that this will get OTP
runtime arguments when called outside of a Burrito-built context. You may consider
`argv/0` as a more general alternative.
"""
@spec get_arguments :: list(String.t())
def get_arguments do
:init.get_plain_arguments() |> Enum.map(&to_string/1)
end

@doc """
Get the arguments from the CLI, regardless if run under Burrito or not.
"""
@spec argv :: list(String.t())
def argv do
if Burrito.Util.running_standalone?() do
get_arguments()
else
System.argv()
end
end
end
9 changes: 9 additions & 0 deletions lib/util/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,13 @@ defmodule Burrito.Util do

String.trim(otp_version)
end

@doc """
Checks if the application is currently running as a standalone Burrito release, or via some other mechanism,
such as an `escript`.
"""
@spec running_standalone?() :: boolean()
def running_standalone?() do
System.get_env("__BURRITO") != nil
end
end

0 comments on commit 8401598

Please sign in to comment.