Current section
Files
Jump to
Current section
Files
src/cli@address_command.erl
-module(cli@address_command).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([run/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-file("src/cli/address_command.gleam", 6).
-spec format_flag() -> glint:flag(binary()).
format_flag() ->
_pipe = glint:string_flag(<<"format"/utf8>>),
_pipe@1 = glint:flag_default(_pipe, <<"user-friendly"/utf8>>),
_pipe@3 = glint:flag_constraint(
_pipe@1,
begin
_pipe@2 = [<<"user-friendly"/utf8>>,
<<"hex"/utf8>>,
<<"base64"/utf8>>,
<<"base64url"/utf8>>],
glint@constraint:one_of(_pipe@2)
end
),
glint:flag_help(
_pipe@3,
<<"Set the address format to convert to (user-friendly | hex | base64 | base64url). Default is user-friendly."/utf8>>
).
-file("src/cli/address_command.gleam", 18).
?DOC(" The glint command that will be executed\n").
-spec run() -> glint:command(nil).
run() ->
glint:command_help(
<<"Converts an address to another format."/utf8>>,
fun() ->
glint:named_arg(
<<"ADDRESS"/utf8>>,
fun(Addr) ->
glint:flag(
format_flag(),
fun(Format) ->
glint:command(
fun(Named, _, Flags) ->
Addr@1 = begin
_pipe = Addr(Named),
account@address:from_string(_pipe)
end,
Format@2 = case Format(Flags) of
{ok, Format@1} -> Format@1;
_assert_fail ->
erlang:error(
#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"cli/address_command"/utf8>>,
function => <<"run"/utf8>>,
line => 37}
)
end,
_pipe@1 = case Addr@1 of
{ok, Addr@2} ->
case Format@2 of
<<"user-friendly"/utf8>> ->
account@address:to_user_friendly_address(
Addr@2
);
<<"hex"/utf8>> ->
account@address:to_hex(
Addr@2
);
<<"base64"/utf8>> ->
account@address:to_base64(
Addr@2
);
<<"base64url"/utf8>> ->
account@address:to_base64_url(
Addr@2
);
_ ->
erlang:error(
#{gleam_error => panic,
message => <<"Invalid format"/utf8>>,
module => <<"cli/address_command"/utf8>>,
function => <<"run"/utf8>>,
line => 47}
)
end;
{error, Msg} ->
<<"Error: "/utf8, Msg/binary>>
end,
gleam_stdlib:println(_pipe@1)
end
)
end
)
end
)
end
).