-module(birdie@internal@cli). -compile([no_auto_import, nowarn_ignored, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -export([parse/1, all_commands/0, similar_command/1, main_help_text/0, unknown_command_error/2, help_text/3, unknown_subcommand_error/3, unknown_option_error/3, missing_subcommand_error/2, unexpected_argument_error/3]). -export_type([command/0, stale_subcommand/0, explained/0, error/0, arguments_kind/0]). -moduledoc(false). -type command() :: review | accept | reject | help | {stale, stale_subcommand()} | {with_help_option, command(), explained()}. -type stale_subcommand() :: check_stale | delete_stale. -type explained() :: full_command | top_level_command. -type error() :: {unknown_command, binary()} | {unknown_subcommand, command(), binary()} | {unexpected_argument, command(), binary()} | {unknown_option, command(), binary()} | {missing_subcommand, command()}. -type arguments_kind() :: command | subcommand. -file("src/birdie/internal/cli.gleam", 109). -spec is_help(binary()) -> boolean(). -doc(false). is_help(Option) -> case Option of ~"-h" -> true; ~"--help" -> true; _ -> false end. -file("src/birdie/internal/cli.gleam", 84). -spec or_help(command(), list(binary())) -> {ok, command()} | {error, error()}. -doc(false). or_help(Command, Options) -> case gleam@list:find(Options, fun(Option) -> not is_help(Option) end) of {ok, Option} -> {error, {unknown_option, Command, Option}}; {error, _} -> case gleam@list:any(Options, fun is_help/1) of true -> {ok, {with_help_option, Command, full_command}}; false -> {ok, Command} end end. -file("src/birdie/internal/cli.gleam", 95). -spec require_help(command(), list(binary())) -> {ok, command()} | {error, error()}. -doc(false). require_help(Command, Options) -> case gleam@list:find(Options, fun(Option) -> not is_help(Option) end) of {ok, Option} -> {error, {unknown_option, Command, Option}}; {error, _} -> case gleam@list:any(Options, fun is_help/1) of true -> {ok, {with_help_option, Command, top_level_command}}; false -> {error, {missing_subcommand, Command}} end end. -file("src/birdie/internal/cli.gleam", 44). -spec parse(list(binary())) -> {ok, command()} | {error, error()}. -doc(false). parse(Args) -> {Commands, Options} = gleam@list:partition(Args, fun(Arg) -> case Arg of <<"--"/utf8, _/binary>> -> false; <<"-"/utf8, _/binary>> -> false; _ -> true end end), case Commands of [] -> _pipe = review, or_help(_pipe, Options); [~"review"] -> _pipe@1 = review, or_help(_pipe@1, Options); [~"review", Subcommand | _] -> {error, {unknown_subcommand, review, Subcommand}}; [~"reject"] -> _pipe@2 = reject, or_help(_pipe@2, Options); [~"reject", Subcommand@1 | _] -> {error, {unknown_subcommand, reject, Subcommand@1}}; [~"accept"] -> _pipe@3 = accept, or_help(_pipe@3, Options); [~"accept", Subcommand@2 | _] -> {error, {unknown_subcommand, accept, Subcommand@2}}; [~"stale"] -> _pipe@4 = {stale, check_stale}, require_help(_pipe@4, Options); [~"stale", ~"check"] -> _pipe@5 = {stale, check_stale}, or_help(_pipe@5, Options); [~"stale", ~"check", Argument | _] -> {error, {unexpected_argument, {stale, check_stale}, Argument}}; [~"stale", ~"delete"] -> _pipe@6 = {stale, delete_stale}, or_help(_pipe@6, Options); [~"stale", ~"delete", Argument@1 | _] -> {error, {unexpected_argument, {stale, delete_stale}, Argument@1}}; [~"stale", Subcommand@3 | _] -> {error, {unknown_subcommand, {stale, check_stale}, Subcommand@3}}; [~"help" | _] -> {ok, help}; [Command | _] -> {error, {unknown_command, Command}} end. -file("src/birdie/internal/cli.gleam", 131). -spec all_commands() -> list(binary()). -doc(false). all_commands() -> [~"accept", ~"help", ~"reject", ~"review", ~"stale"]. -file("src/birdie/internal/cli.gleam", 119). -spec similar_command(binary()) -> {ok, binary()} | {error, nil}. -doc(false). similar_command(Command) -> _pipe = gleam@list:filter_map(all_commands(), fun(Valid_command) -> case edit_distance:levenshtein(Command, Valid_command) of Distance when Distance =< 3 -> {ok, {Valid_command, Distance}}; _ -> {error, nil} end end), _pipe@1 = gleam@list:sort(_pipe, fun(One, Other) -> gleam@int:compare(erlang:element(2, One), erlang:element(2, Other)) end), _pipe@2 = gleam@list:first(_pipe@1), gleam@result:map(_pipe@2, fun(Pair) -> erlang:element(1, Pair) end). -file("src/birdie/internal/cli.gleam", 346). -spec options() -> binary(). -doc(false). options() -> Help_option = <<<<(gleam_community@ansi:green(~"-h"))/binary, ", "/utf8>>/binary, (gleam_community@ansi:green(~"--help"))/binary>>, <<<<<<(gleam_community@ansi:yellow(~"Options:"))/binary, "\n "/utf8>>/binary, Help_option/binary>>/binary, " print this help text"/utf8>>. -file("src/birdie/internal/cli.gleam", 305). -spec command_menu() -> binary(). -doc(false). command_menu() -> <<<<<<<<<<<<<<<<<<<<(gleam_community@ansi:yellow(~"Commands:\n"))/binary, (gleam_community@ansi:green(~" review "))/binary>>/binary, "review all new snapshots one by one\n"/utf8>>/binary, (gleam_community@ansi:green(~" accept "))/binary>>/binary, "accept all new snapshots\n"/utf8>>/binary, (gleam_community@ansi:green(~" reject "))/binary>>/binary, "reject all new snapshots\n"/utf8>>/binary, (gleam_community@ansi:green(~" stale "))/binary>>/binary, "find and remove stale snapshots\n"/utf8>>/binary, (gleam_community@ansi:green(~" help "))/binary>>/binary, "print this help text"/utf8>>. -file("src/birdie/internal/cli.gleam", 324). -spec usage(list(binary()), gleam@option:option(arguments_kind())) -> binary(). -doc(false). usage(Commands, Arguments_kind) -> Command_placeholder = case Arguments_kind of none -> ~" "; {some, command} -> gleam_community@ansi:dim(~" "); {some, subcommand} -> gleam_community@ansi:dim(~" ") end, Commands@1 = case Commands of [] -> ~""; [_ | _] -> <<" "/utf8, (gleam_community@ansi:green(gleam@string:join(Commands, ~" ")))/binary>> end, <<<<<<<<<<(gleam_community@ansi:yellow(~"Usage: "))/binary, "gleam run -m"/utf8>>/binary, (gleam_community@ansi:green(~" birdie"))/binary>>/binary, Commands@1/binary>>/binary, Command_placeholder/binary>>/binary, (gleam_community@ansi:dim(~"[OPTIONS]"))/binary>>. -file("src/birdie/internal/cli.gleam", 301). -spec main_help_text() -> binary(). -doc(false). main_help_text() -> <<<<<<<<(usage([], {some, command}))/binary, "\n\n"/utf8>>/binary, (command_menu())/binary>>/binary, "\n\n"/utf8>>/binary, (options())/binary>>. -file("src/birdie/internal/cli.gleam", 204). -spec style_invalid_value(binary()) -> binary(). -doc(false). style_invalid_value(Value) -> gleam_community@ansi:yellow(<<<<"'"/utf8, Value/binary>>/binary, "'"/utf8>>). -file("src/birdie/internal/cli.gleam", 137). -spec unknown_command_error(binary(), boolean()) -> binary(). -doc(false). unknown_command_error(Command, Show_help_text) -> Message = <<<<(gleam_community@ansi:red(~"Error: "))/binary, (style_invalid_value(Command))/binary>>/binary, " is not a valid command"/utf8>>, case Show_help_text of false -> Message; true -> <<<>/binary, (main_help_text())/binary>> end. -file("src/birdie/internal/cli.gleam", 235). -spec stale_help_text(gleam@option:option(stale_subcommand())) -> binary(). -doc(false). stale_help_text(Subcommand) -> case Subcommand of none -> Stale_subcommands = <<<<<<<<(gleam_community@ansi:yellow(~"Subcommands:\n"))/binary, (gleam_community@ansi:green(~" check "))/binary>>/binary, "check if there's any stale snapshot\n"/utf8>>/binary, (gleam_community@ansi:green(~" delete "))/binary>>/binary, "delete all stale snapshots"/utf8>>, <<<<<<<<<<<<(usage([~"stale"], {some, subcommand}))/binary, "\n\n"/utf8>>/binary, "Find and remove stale snapshots."/utf8>>/binary, "\n\n"/utf8>>/binary, Stale_subcommands/binary>>/binary, "\n\n"/utf8>>/binary, (options())/binary>>; {some, check_stale} -> <<<<<<<<<<(usage([~"stale", ~"check"], none))/binary, "\n\n"/utf8>>/binary, "Check if there's any snapshot that is no longer used by any test.\n"/utf8>>/binary, "This exits with an error status code if any stale snapshot is found."/utf8>>/binary, "\n\n"/utf8>>/binary, (options())/binary>>; {some, delete_stale} -> <<<<<<<<(usage([~"stale", ~"delete"], none))/binary, "\n\n"/utf8>>/binary, "Removes any snapshot that is no longer used by any test."/utf8>>/binary, "\n\n"/utf8>>/binary, (options())/binary>> end. -file("src/birdie/internal/cli.gleam", 271). -spec review_help_text() -> binary(). -doc(false). review_help_text() -> <<<<<<<<(usage([~"review"], none))/binary, "\n\n"/utf8>>/binary, "Review all new snapshots one by one"/utf8>>/binary, "\n\n"/utf8>>/binary, (options())/binary>>. -file("src/birdie/internal/cli.gleam", 279). -spec reject_help_text() -> binary(). -doc(false). reject_help_text() -> <<<<<<<<(usage([~"reject"], none))/binary, "\n\n"/utf8>>/binary, "Reject all new snapshots"/utf8>>/binary, "\n\n"/utf8>>/binary, (options())/binary>>. -file("src/birdie/internal/cli.gleam", 287). -spec accept_help_text() -> binary(). -doc(false). accept_help_text() -> <<<<<<<<(usage([~"accept"], none))/binary, "\n\n"/utf8>>/binary, "Accept all new snapshots"/utf8>>/binary, "\n\n"/utf8>>/binary, (options())/binary>>. -file("src/birdie/internal/cli.gleam", 295). -spec help_help_text(binary()) -> binary(). -doc(false). help_help_text(Birdie_version) -> <<<<<<<<(gleam_community@ansi:green(~"🐦‍⬛ birdie "))/binary, "v"/utf8>>/binary, Birdie_version/binary>>/binary, "\n\n"/utf8>>/binary, (main_help_text())/binary>>. -file("src/birdie/internal/cli.gleam", 212). -spec help_text(binary(), command(), explained()) -> binary(). -doc(false). help_text(Birdie_version, Command, Explained) -> case {Command, Explained} of {help, _} -> help_help_text(Birdie_version); {accept, _} -> accept_help_text(); {reject, _} -> reject_help_text(); {review, _} -> review_help_text(); {{stale, Subcommand}, full_command} -> stale_help_text({some, Subcommand}); {{stale, _}, top_level_command} -> stale_help_text(none); {{with_help_option, Command@1, Explained@1}, _} -> help_text(Birdie_version, Command@1, Explained@1) end. -file("src/birdie/internal/cli.gleam", 149). -spec unknown_subcommand_error(binary(), command(), binary()) -> binary(). -doc(false). unknown_subcommand_error(Birdie_version, Command, Subcommand) -> <<<<<<(gleam_community@ansi:red(~"Error: "))/binary, (style_invalid_value(Subcommand))/binary>>/binary, " is not a valid subcommand\n\n"/utf8>>/binary, (help_text(Birdie_version, Command, top_level_command))/binary>>. -file("src/birdie/internal/cli.gleam", 160). -spec unknown_option_error(binary(), command(), binary()) -> binary(). -doc(false). unknown_option_error(Birdie_version, Command, Option) -> <<<<<<(gleam_community@ansi:red(~"Error: "))/binary, (style_invalid_value(Option))/binary>>/binary, " is not a valid option\n\n"/utf8>>/binary, (help_text(Birdie_version, Command, full_command))/binary>>. -file("src/birdie/internal/cli.gleam", 193). -spec command_to_string(command()) -> binary(). -doc(false). command_to_string(Command) -> case Command of {with_help_option, Command@1, _} -> command_to_string(Command@1); {stale, _} -> ~"stale"; review -> ~"review"; accept -> ~"accept"; reject -> ~"reject"; help -> ~"help" end. -file("src/birdie/internal/cli.gleam", 171). -spec missing_subcommand_error(binary(), command()) -> binary(). -doc(false). missing_subcommand_error(Birdie_version, Command) -> <<<<<<(gleam_community@ansi:red(~"Error: "))/binary, (style_invalid_value(command_to_string(Command)))/binary>>/binary, " is missing a required subcommand\n\n"/utf8>>/binary, (help_text(Birdie_version, Command, top_level_command))/binary>>. -file("src/birdie/internal/cli.gleam", 181). -spec unexpected_argument_error(binary(), command(), binary()) -> binary(). -doc(false). unexpected_argument_error(Birdie_version, Command, Argument) -> <<<<<<<<(gleam_community@ansi:red(~"Error: "))/binary, " unexpected argument "/utf8>>/binary, (style_invalid_value(Argument))/binary>>/binary, "\n\n"/utf8>>/binary, (help_text(Birdie_version, Command, full_command))/binary>>.