www
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYestin L. Harrison <yestin@ylh.io>2022-06-19 18:11:08 -0700
committerYestin L. Harrison <yestin@ylh.io>2022-06-19 18:11:08 -0700
commit2a2e1b1967694bc26a4e49ace1745b51f3374e3e (patch)
tree3b49ccf76ea8794463c02e1b28602eec9c0fb627
parentf05250406522e58dcedd0109b3582265857a9cc5 (diff)
downloaddemoheader-2a2e1b1967694bc26a4e49ace1745b51f3374e3e.tar.gz
demoheader-2a2e1b1967694bc26a4e49ace1745b51f3374e3e.tar.xz
demoheader-2a2e1b1967694bc26a4e49ace1745b51f3374e3e.zip
better names and simpler print
-rw-r--r--src/demoheader.erl12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/demoheader.erl b/src/demoheader.erl
index b9ec948..41de517 100644
--- a/src/demoheader.erl
+++ b/src/demoheader.erl
@@ -33,13 +33,13 @@ args(Args, Opts) ->
usage(Opts, 1)
end,
Args =:= [] andalso DU("no arguments given"),
- {Options, NonOptionArgs} = case getopt:parse(Opts, Args) of
+ {OptArgs, ExtraArgs} = case getopt:parse(Opts, Args) of
{error, E} -> DU(getopt:format_error(Opts, E));
{ok, Res} -> Res
end,
- lists:member(help, Options) andalso usage(Opts, 0),
- Headers = lists:filter(fun(A) -> lists:member(A, [?FIELDS]) end, Options),
- Show = case lists:member(json, Options) of
+ lists:member(help, OptArgs) andalso usage(Opts, 0),
+ Headers = lists:filter(fun(A) -> lists:member(A, [?FIELDS]) end, OptArgs),
+ Show = case lists:member(json, OptArgs) of
true -> json_of(case Headers of [] -> [?FIELDS]; Else -> Else end);
_ -> case Headers of
[One] -> fun(#{One := V}) ->
@@ -48,7 +48,7 @@ args(Args, Opts) ->
_ -> DU("without -j, exactly one field must be requested")
end
end,
- Parsed = case NonOptionArgs of
+ Parsed = case ExtraArgs of
[Single] -> parse(Single);
_ -> DU("exactly one file must be specified")
end,
@@ -59,7 +59,7 @@ json_of(Keys) ->
fun(Map) ->
F = fun(Key, Acc) ->
#{Key := Value} = Map,
- [io_lib:format("\"~s\": ~0p", [atom_to_list(Key), Value])|Acc]
+ [io_lib:format("\"~s\": ~0p", [Key, Value])|Acc]
end,
"{\n\t" ++
lists:join(",\n\t", lists:foldl(F, [], lists:reverse(Keys))) ++