Skip to content

Commit c50045a

Browse files
committed
Move implementation to Bash script
1 parent 20665f7 commit c50045a

File tree

3 files changed

+17
-33
lines changed

3 files changed

+17
-33
lines changed

README.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,21 +130,13 @@ Run the linter to validate the error definitions in [`api-errors.json`](./api-er
130130

131131
## Export for use in `developer.kivra.com`
132132

133-
A helper function is made available to allow copy-pasting the entire list for
133+
A `util` script is made available to allow copy-pasting the entire list for
134134
acceptance in <https://developer.kivra.com>.
135135

136-
### Erlang
137-
138-
Boot up an Erlang shell
136+
For this you need to have [`jq`](https://github.com/jqlang/jq#installation) installed.
139137

140138
```console
141-
rebar3 shell
142-
```
143-
144-
Call the `kivra_api_errors:to_developer_kivra_com/0` function:
145-
146-
```erlang
147-
kivra_api_errors:to_developer_kivra_com().
139+
./util/to-developer.kivra.com.sh
148140
```
149141

150142
Whatever is between `<copy-paste>` and `</copy-paste>` is deemed usable

erlang/kivra_api_errors.erl

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
-export([
66
load/0,
77
load/1,
8-
from_code/1, from_code/2, from_code/3,
9-
to_developer_kivra_com/0
8+
from_code/1, from_code/2, from_code/3
109
]).
1110

1211
%%%_* Types ===================================================================
@@ -38,26 +37,6 @@ load(Config) ->
3837
Error
3938
end.
4039

41-
-spec to_developer_kivra_com() -> ok.
42-
to_developer_kivra_com() ->
43-
ErrorsFile = filename:join([code:priv_dir(?MODULE), <<"api-errors.json">>]),
44-
{ok, ErrorsAsJSON} = file:read_file(ErrorsFile),
45-
Errors = jiffy:decode(ErrorsAsJSON, [return_maps]),
46-
ErrorsList = maps:to_list(Errors),
47-
SortedErrorsList = lists:sort(fun ({CodeLeft, _}, {CodeRight, _}) -> CodeLeft < CodeRight end, ErrorsList),
48-
49-
io:format("Copy-paste to developer.kivra.com's swagger.yml~n"),
50-
io:format("<copy-paste>~n"),
51-
io:format(" | Code | Short Message | Long Message |~n"),
52-
io:format(" | ---- | ------------- | ------------ |~n"),
53-
lists:foreach(
54-
fun ({Code, #{<<"short_message">> := ShortMessage, <<"long_message">> := LongMessage}}) ->
55-
io:format(" | ~ts | ~ts | ~ts |~n", [Code, ShortMessage, LongMessage])
56-
end,
57-
SortedErrorsList
58-
),
59-
io:format("</copy-paste>~n").
60-
6140
-spec from_code(binary() | pos_integer()) -> {ok, {status_code(), payload_map() | payload_kv()}} | {error, notfound}.
6241
from_code(ErrorCode) when is_integer(ErrorCode) ->
6342
from_code(integer_to_binary(ErrorCode));

util/to-developer.kivra.com.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
if ! command -v jq &>/dev/null; then
4+
echo "You need 'jq' to run this script."
5+
exit 1
6+
fi
7+
8+
echo "Copy-paste to developer.kivra.com's swagger.yml"
9+
echo "<copy-paste>"
10+
echo " | Code | Short Message | Long Message |"
11+
echo " | ---- | ------------- | ------------ |"
12+
jq -r 'to_entries | sort_by(.key) | .[] | " | \(.key) | \(.value.short_message) | \(.value.long_message) |"' <api-errors.json
13+
echo "</copy-paste>"

0 commit comments

Comments
 (0)