From ce331133bbaa9b5e31a750b286aac585d474818e Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Sat, 9 Mar 2024 13:08:18 -0500 Subject: [PATCH 1/3] Add Burrito.Util.running_standalone --- lib/util/util.ex | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/util/util.ex b/lib/util/util.ex index 2c54bb5..417ca6b 100644 --- a/lib/util/util.ex +++ b/lib/util/util.ex @@ -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 From f7d49bc5eca0681131e3e9db2a0d488dafc1fda4 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Sat, 9 Mar 2024 13:15:26 -0500 Subject: [PATCH 2/3] Add Burrito.Util.Args.argv to get arguments universally --- lib/util/args.ex | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/util/args.ex b/lib/util/args.ex index aa521b9..45f28e3 100644 --- a/lib/util/args.ex +++ b/lib/util/args.ex @@ -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 From 14e356c69ae0f28556bf91b646bf926177981742 Mon Sep 17 00:00:00 2001 From: Nick Krichevsky Date: Sat, 9 Mar 2024 13:19:56 -0500 Subject: [PATCH 3/3] Update README to document argv --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b29511e..34a265a 100644 --- a/README.md +++ b/README.md @@ -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