Skip to content

Commit

Permalink
Merge pull request #8573 from richcarl/shell-help-cleanup
Browse files Browse the repository at this point in the history
Fix up the built-in help text in the shell
OTP-19161
  • Loading branch information
frazze-jobb authored Jul 8, 2024
2 parents 20e6c48 + 83b8f12 commit 14bbc87
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 70 deletions.
60 changes: 33 additions & 27 deletions lib/stdlib/src/c.erl
Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,42 @@ this module.

help() ->
io:put_chars(<<"bt(Pid) -- stack backtrace for a process\n"
"c(Mod) -- compile and load module or file <Mod>\n"
"cd(Dir) -- change working directory\n"
"flush() -- flush any messages sent to the shell\n"
"help() -- help info\n"
"c(Mod) -- compile and load module or file <Mod>\n"
"cd(Dir) -- change working directory\n"
"flush() -- flush any messages sent to the shell\n"
"h(M) -- module documentation\n"
"h(M,F) -- module function documentation\n"
"h(M,F,A) -- module function arity documentation\n"
"i() -- information about the system\n"
"ni() -- information about the networked system\n"
"i(X,Y,Z) -- information about pid <X,Y,Z>\n"
"l(Module) -- load or reload module\n"
"lm() -- load all modified modules\n"
"lc([File]) -- compile a list of Erlang modules\n"
"ls() -- list files in the current directory\n"
"ls(Dir) -- list files in directory <Dir>\n"
"m() -- which modules are loaded\n"
"m(Mod) -- information about module <Mod>\n"
"mm() -- list all modified modules\n"
"memory() -- memory allocation information\n"
"memory(T) -- memory allocation information of type <T>\n"
"nc(File) -- compile and load code in <File> on all nodes\n"
"nl(Module) -- load module on all nodes\n"
"pid(X,Y,Z) -- convert X,Y,Z to a Pid\n"
"pwd() -- print working directory\n"
"q() -- quit - shorthand for init:stop()\n"
"regs() -- information about registered processes\n"
"nregs() -- information about all registered processes\n"
"uptime() -- print node uptime\n"
"xm(M) -- cross reference check a module\n"
"y(File) -- generate a Yecc parser\n">>).
"hcb(Mod) -- help about a module's callbacks\n"
"hcb(Mod,CB) -- help about callback in module\n"
"hcb(Mod,CB,Arity) -- help about callback with arity in module\n"
"ht(Mod) -- help about a module's types\n"
"ht(Mod,Type) -- help about type in module\n"
"ht(Mod,Type,Arity) -- help about type with arity in module\n"
"help() -- help info\n"
"i() -- information about the system\n"
"i(X,Y,Z) -- information about pid <X,Y,Z>\n"
"l(Module) -- load or reload module\n"
"lc([File]) -- compile a list of Erlang modules\n"
"lm() -- load all modified modules\n"
"ls() -- list files in the current directory\n"
"ls(Dir) -- list files in directory <Dir>\n"
"m() -- which modules are loaded\n"
"m(Mod) -- information about module <Mod>\n"
"memory() -- memory allocation information\n"
"memory(T) -- memory allocation information of type <T>\n"
"mm() -- list all modified modules\n"
"nc(File) -- compile and load code in <File> on all nodes\n"
"ni() -- information about the networked system\n"
"nl(Module) -- load module on all nodes\n"
"nregs() -- information about all registered processes\n"
"pid(X,Y,Z) -- convert X,Y,Z to a Pid\n"
"pwd() -- print working directory\n"
"q() -- quit - shorthand for init:stop()\n"
"regs() -- information about registered processes\n"
"uptime() -- print node uptime\n"
"xm(M) -- cross reference check a module\n"
"y(File) -- generate a Yecc parser\n">>).

%% c(Module)
%% Compile a module/file.
Expand Down
45 changes: 44 additions & 1 deletion lib/stdlib/src/shell.erl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
-export([read_and_add_records/5]).
-export([default_multiline_prompt/1, inverted_space_prompt/1]).
-export([prompt_width/1, prompt_width/2]).
-export([whereis/0]).
-export([help/0,whereis/0]).

-define(LINEMAX, 30).
-define(CHAR_MAX, 60).
Expand Down Expand Up @@ -1166,6 +1166,49 @@ init_dict([{K,V}|Ds]) ->
init_dict(Ds);
init_dict([]) -> true.


-doc "Print the help for all shell internal commands.".
-spec help() -> true.
help() ->
S = ~"""
** shell internal commands **
b() -- display all variable bindings
e(N) -- repeat the expression in query <N>
exit() -- terminate the shell instance
f() -- forget all variable bindings
f(X) -- forget the binding of variable X
ff() -- forget all locally defined functions
ff(F,A) -- forget locally defined function named as atom F and arity A
fl() -- forget all locally defined functions, types and records
h() -- history
h(Mod) -- help about module
h(Mod,Func) -- help about function in module
h(Mod,Func,Arity) -- help about function with arity in module
lf() -- list locally defined functions
lr() -- list locally defined records
lt() -- list locally defined types
rd(R,D) -- define a record
rf() -- remove all record information
rf(R) -- remove record information about R
rl() -- display all record information
rl(R) -- display record information about R
rp(Term) -- display Term using the shell's record information
rr(File) -- read record information from File (wildcards allowed)
rr(F,R) -- read selected record information from file(s)
rr(F,R,O) -- read selected record information with options
tf() -- forget all locally defined types
tf(T) -- forget locally defined type named as atom T
v(N) -- use the value of query <N>
catch_exception(B) -- how exceptions are handled
history(N) -- set how many previous commands to keep
results(N) -- set how many previous command results to keep
save_module(FilePath) -- save all locally defined functions, types and records to a file
""",
io:put_chars(S),
io:nl(),
true.


%% local_func(Function, Args, Bindings, Shell, RecordTable,
%% LocalFuncHandler, ExternalFuncHandler) -> {value,Val,Bs}
%% Evaluate local functions, including shell commands.
Expand Down
44 changes: 2 additions & 42 deletions lib/stdlib/src/shell_default.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,50 +72,10 @@ code:load_abs("$PATH/user_default").
-export(['$handle_undefined_function'/2]).
-import(io, [format/1]).

-doc "Print the help for all shell internal commands.".
-doc "Print the help for all shell commands.".
-spec help() -> true.
help() ->
S = ~"""
** shell internal commands **
b() -- display all variable bindings
e(N) -- repeat the expression in query <N>
f() -- forget all variable bindings
f(X) -- forget the binding of variable X
h() -- history
h(Mod) -- help about module
h(Mod,Func)-- help about function in module
h(Mod,Func,Arity) -- help about function with arity in module
ht(Mod) -- help about a module's types
ht(Mod,Type) -- help about type in module
ht(Mod,Type,Arity) -- help about type with arity in module
hcb(Mod) -- help about a module's callbacks
hcb(Mod,CB) -- help about callback in module
hcb(Mod,CB,Arity) -- help about callback with arity in module
history(N) -- set how many previous commands to keep
results(N) -- set how many previous command results to keep
catch_exception(B) -- how exceptions are handled
v(N) -- use the value of query <N>
rd(R,D) -- define a record
rf() -- remove all record information
rf(R) -- remove record information about R
rl() -- display all record information
rl(R) -- display record information about R
rp(Term) -- display Term using the shell's record information
rr(File) -- read record information from File (wildcards allowed)
rr(F,R) -- read selected record information from file(s)
rr(F,R,O) -- read selected record information with options
lf() -- list locally defined functions
lt() -- list locally defined types
lr() -- list locally defined records
ff() -- forget all locally defined functions
ff({F,A}) -- forget locally defined function named as atom F and arity A
tf() -- forget all locally defined types
tf(T) -- forget locally defined type named as atom T
fl() -- forget all locally defined functions, types and records
save_module(FilePath) -- save all locally defined functions, types and records to a file
""",
io:put_chars(S),
io:nl(),
shell:help(),
c:help(),
format(~"** commands in module i (interpreter interface) **\n"),
format(~"ih() -- print help for the i module\n"),
Expand Down

0 comments on commit 14bbc87

Please sign in to comment.