Skip to content

Commit 1ea2037

Browse files
committed
Always have full path in path field and formatting
1 parent f24ba2f commit 1ea2037

10 files changed

Lines changed: 129 additions & 128 deletions

src/ecli.erl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
%%%-------------------------------------------------------------------
99
-module(ecli).
1010

11-
-include("ecli_internal.hrl").
1211
-include("../include/ecli.hrl").
1312

1413
%% API
@@ -161,17 +160,17 @@ format_table([#{} | _] = Maps, TitlesInOrder) ->
161160
TitleLengths = lists:map(fun(T) -> {T, key_size(T)} end, TitlesInOrder),
162161
Lengths = maps:from_list(TitleLengths),
163162
ColLengths = lists:foldl(
164-
fun(M, Ls) ->
165-
maps:fold(fun(K, V, L) ->
166-
maps:put(K, max(maps:get(K, L), printable_size(V)), L)
167-
end, Ls, M)
168-
end, Lengths, Maps),
163+
fun(M, Ls) ->
164+
maps:fold(fun(K, V, L) ->
165+
maps:put(K, max(maps:get(K, L), printable_size(V)), L)
166+
end, Ls, M)
167+
end, Lengths, Maps),
169168
OrderedColLengths = lists:map(fun(T) -> {T, maps:get(T, ColLengths)} end, TitlesInOrder),
170169
TitleRow = pad_row(OrderedColLengths),
171170
TitleUnderline = pad_row(lists:map(fun({T, L}) -> {list_to_binary(lists:duplicate(printable_size(T), $-)), L} end, OrderedColLengths)),
172171
Rows = lists:map(fun(Row) ->
173-
RowWithLengths = lists:map(fun(T) -> {maps:get(T, Row), maps:get(T, ColLengths)} end, TitlesInOrder),
174-
[pad_row(RowWithLengths), "\r\n"]
172+
RowWithLengths = lists:map(fun(T) -> {maps:get(T, Row), maps:get(T, ColLengths)} end, TitlesInOrder),
173+
[pad_row(RowWithLengths), "\r\n"]
175174
end, Maps),
176175
[TitleRow, "\r\n", TitleUnderline, "\r\n", Rows].
177176

@@ -200,4 +199,4 @@ pad_row([{Val, Len} | Vals]) ->
200199
[pad(Printable, Len + 1) | pad_row(Vals)].
201200

202201
spaces(Num) ->
203-
lists:duplicate(Num, $\s).
202+
lists:duplicate(Num, $\s).

src/ecli_edlin.erl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
-record(edlin,
1414
{
15-
line = {[], []}, % {Chars_before_cursor, Chars_after}
16-
state = none,
17-
prompt,
18-
requests = [],
19-
history = {[],[]} % {Before, After}
15+
line = {[], []}, % {Chars_before_cursor, Chars_after}
16+
state = none,
17+
prompt,
18+
requests = [],
19+
history = {[],[]} % {Before, After}
2020
}).
2121

2222
%%--------------------------------------------------------------------
@@ -101,7 +101,7 @@ insert([C|Cs], #edlin{state = State, line = {Bef, Aft},
101101
case do_op(Op, Bef, Aft, Rs0) of
102102
{Line, Rs, Mode} -> % allow custom modes from do_op
103103
insert(Cs, Ed#edlin{line = Line, state = Mode,
104-
requests = Rs});
104+
requests = Rs});
105105
{Line, Rs} ->
106106
insert(Cs, Ed#edlin{line = Line, state = none, requests = Rs})
107107
end

src/ecli_expand.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ parse([{token, Tok} | Ts], Tree, [#{node_type := NodeType} | _] = Acc, Txn, Cmd)
7676
{ok, #{node_type := container} = Item} ->
7777
NewCmd = maps:get(cmd_type, Item, Cmd),
7878
Children = menu_item_children(Item, Txn, NewCmd),
79-
?DBG("Adding Container Item in container = ~p~n", [Item]),
79+
?DBG("Adding Container Item in container = ~p children ~p~n", [Item, Children]),
8080
parse(Ts, Children, [Item | Acc], Txn, NewCmd);
8181
{ok, #{node_type := Leaf, type := Type} = Item} when Leaf == leaf; Leaf == leaf_list ->
8282
%% Expecting a leaf value, possibly followed by more entries in the same
@@ -211,7 +211,7 @@ parse_list_keys([{token, Tok} | Ts], #{key_names := KeyNames, key_values := KeyV
211211
%% Got the list keys, carry on in the main parser
212212
Children = menu_item_children(Item1, Txn, Cmd),
213213
parse(Ts, Children, [Item1 | Acc], Txn, Cmd);
214-
true ->
214+
true ->
215215
parse_list_keys(Ts, Item1, Acc, Txn, Cmd)
216216
end.
217217

@@ -251,7 +251,7 @@ expand_after_space([], [#{node_type := leaf, value := _Val} | _Acc], _Txn, _Cmd)
251251
%% This leaf has a value, but no peer items. End of the command
252252
no;
253253
expand_after_space(Tree, [#{node_type := leaf, value := _Val} | _Acc], _Txn, _Cmd) ->
254-
%% This leaf has a value. Show the remaining Menu items
254+
%% This leaf has a value. Show the remaining Menu items
255255
Menu = ecli:format_menu(Tree),
256256
{yes, "", Menu};
257257
expand_after_space(_Menu, [#{node_type := leaf, desc := Desc, type := Type} | _Acc], _Txn, _Cmd) ->
@@ -332,7 +332,7 @@ remove(Tok, Tree) ->
332332
%% each key in sequence. Once we have all list keys children become
333333
%% the items inside the list item, minus the list key names.
334334
menu_item_children(Item, Txn, CmdType) ->
335-
ecli_util:children(Item, Txn, CmdType).
335+
ecli_util:children(Item, Txn, CmdType).
336336

337337
%% Find characters to add to fill up to where the node names diverge
338338
%% e.g. names configure and contain given an input of "c" should return "on"
@@ -342,7 +342,7 @@ expand_menus(Str, Menus) ->
342342
Suffixes = lists:map(fun(#{name := Name}) ->
343343
lists:nthtail(StrLen, Name);
344344
(#cmd{name = Name}) ->
345-
lists:nthtail(StrLen, Name)
345+
lists:nthtail(StrLen, Name)
346346
end, Menus),
347347
%% ?DBG("expand_menus ML = ~p~n",[Suffixes]),
348348
longest_common_prefix(Suffixes).

src/ecli_history.erl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
%%% @author Sean Hinde <sean@Seans-MacBook.local>
33
%%% @copyright (C) 2022, Sean Hinde
44
%%% @doc Implementation of cli history
5-
%%%
5+
%%%
66
%%% Expected Behaviour
77
%%% ==================
8-
%%%
9-
%%% Initially prev/1 should give us the previous line, prev/1 again the line
8+
%%%
9+
%%% Initially prev/1 should give us the previous line, prev/1 again the line
1010
%%% previous to that. Then next/1 should give us the first prev line and next/1
1111
%%% back to whatever the user had on the line before exploring the history.
12-
%%%
13-
%%% If any line in the history is edited it should still appear edited after
12+
%%%
13+
%%% If any line in the history is edited it should still appear edited after
1414
%%% moving away and back, but only until a command is executed. At that point
1515
%%% all the original history should be restored with the executed command as
1616
%%% the most recent
17-
%%%
17+
%%%
1818
%%% So during a single history session we don't need to care about the original
1919
%%% state. We can just track edited lines in the history. Immutability is a
2020
%%% superpower :)

src/ecli_lookup.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ parse_list_keys([{token, Tok} | Ts], #{key_names := KeyNames, key_values := KeyV
187187
%% Got the list keys, carry on in the main parser
188188
Children = ecli_util:children(Item1, Txn, undefined),
189189
parse(Ts, Children, [Item1 | Acc], Txn);
190-
true ->
190+
true ->
191191
parse_list_keys(Ts, Item1, Acc, Txn)
192192
end.
193193

@@ -246,4 +246,4 @@ lookup(_, []) ->
246246
false.
247247

248248
remove(Tok, Tree) ->
249-
lists:filter(fun(#{name := Name}) -> Name /= Tok end, Tree).
249+
lists:filter(fun(#{name := Name}) -> Name /= Tok end, Tree).

src/ecli_server.erl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@
2020

2121
-record(state,
2222
{
23-
socket,
24-
listen_pid,
25-
listen_socket,
26-
term, % #ecli_term{}
27-
edlin, % #ecli_edlin{}
28-
ecli_mod, % User defined CLI callback implementation
29-
ecli_state, % State threaded through cli callbacks
30-
history = [], % command line history for this session
31-
got_meta = false,
32-
buf = <<>> % Temp buf for UTF boundaries
33-
}).
23+
socket,
24+
listen_pid,
25+
listen_socket,
26+
term, % #ecli_term{}
27+
edlin, % #ecli_edlin{}
28+
ecli_mod, % User defined CLI callback implementation
29+
ecli_state, % State threaded through cli callbacks
30+
history = [], % command line history for this session
31+
got_meta = false,
32+
buf = <<>> % Temp buf for UTF boundaries
33+
}).
3434

3535
%%%===================================================================
3636
%%% API
@@ -220,7 +220,7 @@ process_sigwinch(Bin, Term) ->
220220
{SigWinch, Trailing} = erlang:split_binary(SigWinchPre, 12),
221221
{Rows, Cols} = parse_sigwinch(SigWinch),
222222
process_sigwinch(<<PreData/binary, Trailing/binary>>, ecli_term:sigwinch(Rows, Cols, Term));
223-
true ->
223+
true ->
224224
%% Partial Sigwinch update
225225
{PreData, PartSigWinch} = erlang:split_binary(Bin, Start),
226226
{PreData, Term, PartSigWinch}
@@ -267,15 +267,15 @@ get_chars_loop(CharList, #state{ecli_mod = CliMod} = State) ->
267267
Term = send_drv(Ops, State#state.socket, State#state.term),
268268
{ok, Prompt} = CliMod:prompt(CliState),
269269
History = case FullLine of
270-
"" -> State#state.history;
271-
_-> [FullLine | State#state.history]
270+
"" -> State#state.history;
271+
_-> [FullLine | State#state.history]
272272
end,
273273
{Edlin, InitialOps} = ecli_edlin:start(Prompt, History),
274274
Term1 = send_drv(InitialOps, State#state.socket, Term),
275275
get_chars_loop(Cs, State#state{term = Term1,
276-
edlin = Edlin,
277-
history = History,
278-
ecli_state = CliState});
276+
edlin = Edlin,
277+
history = History,
278+
ecli_state = CliState});
279279
stop ->
280280
gen_tcp:close(State#state.socket),
281281
stop
@@ -293,7 +293,7 @@ get_chars_loop(CharList, #state{ecli_mod = CliMod} = State) ->
293293
stop ->
294294
stop;
295295
CliState2 ->
296-
ok = send_raw("\r\n", State),
296+
ok = send_raw("\r\n\r\n[ok]\r\n", State),
297297
{ok, Prompt} = CliMod:prompt(CliState2),
298298
{Edlin, InitialOps} = ecli_edlin:start(Prompt, State#state.history),
299299
Term1 = send_drv(InitialOps, State#state.socket, State#state.term),

src/ecli_tokenise.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
%%% @author Sean Hinde <sean@Seans-MacBook.local>
33
%%% @copyright (C) 2022, Sean Hinde
44
%%% @doc CLI Command string tokeniser useful for completion and execution
5-
%%%
5+
%%%
66
%%% Created : 30 Apr 2022 by Sean Hinde <sean@Seans-MacBook.local>
77
%%%-------------------------------------------------------------------
88
-module(ecli_tokenise).
@@ -32,4 +32,4 @@ tokenise_string([$\" | Cs], Str, Acc) ->
3232
tokenise_string([C|Cs], Str, Acc) ->
3333
tokenise_string(Cs, [C|Str], Acc);
3434
tokenise_string([], Str, Acc) ->
35-
{ok, lists:reverse([{part_string, lists:reverse(Str)} | Acc])}.
35+
{ok, lists:reverse([{part_string, lists:reverse(Str)} | Acc])}.

src/ecli_types.erl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@
2929
%% xpath1.0
3030

3131
-type yang_type() :: counter32
32-
| 'zero-based-counter32'
33-
| counter64
34-
| 'zero-based-counter64'
35-
| gauge32
36-
| gauge64
37-
| 'object-identifier'
38-
| 'object-identifier-128'
39-
| 'date-and-time'
40-
| timeticks
41-
| timestamp
42-
| 'phys-address'
43-
| 'mac-address'
44-
| 'xpath1.0'.
32+
| 'zero-based-counter32'
33+
| counter64
34+
| 'zero-based-counter64'
35+
| gauge32
36+
| gauge64
37+
| 'object-identifier'
38+
| 'object-identifier-128'
39+
| 'date-and-time'
40+
| timeticks
41+
| timestamp
42+
| 'phys-address'
43+
| 'mac-address'
44+
| 'xpath1.0'.
4545

4646
-spec parse(yang_type(), string()) -> {ok, any()} | {error, string()}.
4747
parse(counter32, Value) ->
@@ -70,4 +70,4 @@ parse(counter32, Value) ->
7070
%% ipv6-prefix
7171
%% domain-name
7272
%% host
73-
%% uri
73+
%% uri

src/ecli_unixdom_listen.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
-record(state,
2222
{
23-
listen_socket,
24-
path,
25-
ecli_mod,
26-
acceptor_pid
23+
listen_socket,
24+
path,
25+
ecli_mod,
26+
acceptor_pid
2727
}).
2828

2929
%%%===================================================================

0 commit comments

Comments
 (0)