Commit Graph

2742 Commits

Author SHA1 Message Date
Xavier Delaruelle
bc1373dffc init: add -T/--trace options to completion scripts 2020-06-01 21:02:32 +02:00
Xavier Delaruelle
f2d280eb57 Introduce 'trace' verbosity level 2020-06-01 21:02:32 +02:00
Xavier Delaruelle
e2188df5d1 doc: desc. sh-to-mod in NEWS/MIGRATING 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
31fadd19a8 doc: desc. sh-to-mod in module(1) and diff docs 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
2351c9a863 doc: add source-shell-script-in-modulefile design doc 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
20b28d1091 ts: add test for path-like variable in 70/310 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
ffa9e52215 Dedup path entries found after sh-to-mod script source
For path-like variable set by sourced script, the newly added path
entries are analyzed to remove duplicates among the same portion to
avoid a path to be prepended multiple times or appended multiple times.

Deduplication does not apply between prepended portion and appended
portion. Path entries found set prior script sourced are also excluded
from deduplication process.
2020-06-01 20:59:50 +02:00
Xavier Delaruelle
f6d64723ba Exclude PS1 variable from sh-to-mod environment change
Sourced scripts may detect the need to update PS1, but this decision is
taken over a specific environment where initialization scripts have not
been evaluated for the shells.
2020-06-01 20:59:50 +02:00
Xavier Delaruelle
1c3fd35338 No support of BSD sh shell on sh-to-mod currently
sh shell on BSD platform outputs alias definition with different
character escaping than regular sh or dash on Linux platform.

Disable test for this shell on this platform currently. Will see later
on if a need to support this shell is needed.
2020-06-01 20:59:50 +02:00
Xavier Delaruelle
f5991f09c6 ts: rework FOOSHELL var test in 70/310
Prefer BASH environment variable to SHELL to check bash binary location
used for current shell session.
2020-06-01 20:59:50 +02:00
Xavier Delaruelle
628de991ea Run shell without loading its config to proceed sh-to-mod eval 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
3dd6e43836 Add support for csh/tcsh shells on sh-to-mod sub-cmd 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
4439741f95 ts: mksh not supported on sh-to-mod currently 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
5f5bfafcf7 ts: fix install 00/090 when quarantine is disabled
With quarantine mechanism disabled, no specific IFS is set when
modulecmd.tcl output is evaluated with zsh and ksh shells, sh-to-mod
does not output ';' character at end of each function line, thus when
evaluated with default IFS the multiple lines are treated as a single
command line.
2020-06-01 20:59:50 +02:00
Xavier Delaruelle
49b9717130 Add support for fish shell on sh-to-mod sub-cmd 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
8eb4ae85c9 ts: prepare 70/310 for non-sh shells 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
d039eb40a1 Add support for ksh93 shell on sh-to-mod sub-cmd 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
b995368580 Add support for dash shell on sh-to-mod sub-cmd
dash has some limitations for this task:
- there is no mechanism to report shell functions set, so no shell
  function will be defined or unset with this shell through sh-to-mod
- arguments cannot be passed to a sourced script
2020-06-01 20:59:50 +02:00
Xavier Delaruelle
a7de829af9 Add support for sh shell on sh-to-mod sub-cmd 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
37def4d0c1 ts: add install tests for sh-to-mod sub-cmd 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
14d3fcaa8f Add support for ksh shell on sh-to-mod sub-cmd
Specific code is required to retrieve defined functions in environment
as `typeset -f` may output function definition with no clear separation
between each other.
2020-06-01 20:59:50 +02:00
Xavier Delaruelle
1e520138e3 Add support for zsh shell on sh-to-mod sub-cmd 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
2c68a96e11 ts: add tests for 'sh-to-mod' sub-command 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
ca05b8de60 Handle error occuring when sourcing script in sh-to-mod
Redirect stderr onto stdout when sourcing script in sh-to-mod
sub-command in order to avoid a warning message put on stderr by script
were taken as an error by Tcl exec command.

Also mix stdout and stderr messages of script to be able to provide all
of them to user in case an error occurs during script source by shell
(exit code found different than 0).

An error returned by shell execution is reported and ends sh-to-mod
processing.
2020-06-01 20:59:50 +02:00
Xavier Delaruelle
236d21178a Format string and list for output
Add the strTo and listTo procedures to format a string or a list
of string making it compliant with the destination language. Add support
for Tcl and shell output, enclosing strings if they are empty or if they
contain a space character respectively with curly braces or single
quotes. And escaping those character if used in strings.

Use the new procedures in sh-to-mod to enclose/escape script name and
its argument to source in shell command. Also use listTo in reportCmd,
which was previously doing the same enclosing work.

Make use of reportCmd to output result of sh-to-mod sub-command, in
order to get the same formatted output than when doing a module display
(with tabs and colors if enabled).

Add a -nativeargrep argument to reportCmd procedure to use (when called
for sh-to-mod result) Tcl native string representation of list, which
automatically enclose string if needed and escape special characters if
present. Do not make this behavior a default as output made for module
display should not automatically enclose strings using variable value
reference (eg. $VAR).
2020-06-01 20:59:50 +02:00
Xavier Delaruelle
b1052f2044 Add 'sh-to-mod' procedure
Add the `sh-to-mod' procedure that executes script with args through
shell and converts environment changes the script performs into
corresponding modulefile commands.

Environment changes made by script are found by making shell first
outputing environment state, then sourcing script and after that
outputing resulting environment state. Shell full output is after this
execution parsed and analyzed, comparing environment state prior script
source with state after script source.

Add support for Bash shell and track changes over environment variables,
shell functions, shell aliases and current working directory.

Result is returned as a list of modulefile commands. Procedure is called
by cmdModuleShToMod which outputs the modulefile commands with modulefile
header '#%Module'.
2020-06-01 20:59:50 +02:00
Xavier Delaruelle
9d5517d202 init: fix dup apropos/keyword/search in bash comp
apropos, keyword and search sub-commands now accept arguments so they
need to be removed from empty-or-wide-argument-command list
2020-06-01 20:59:50 +02:00
Xavier Delaruelle
80e7033ba2 init: add 'sh-to-mod' sub-cmd to shell comp scripts 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
c5fd2df8b5 init: fix list/source sub-cmd in fish completion
list and source sub-commands do not need available modulefiles as
argument.
2020-06-01 20:59:50 +02:00
Xavier Delaruelle
2bcb6a75fb ts: update existing tests to check 'sh-to-mod' 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
9e63f133af Add skeleton for new 'sh-to-mod' sub-command 2020-06-01 20:59:50 +02:00
Xavier Delaruelle
76e9e16427 Optionally catch error when initializing a state
Ensure, when dumping all states that an error occuring during a state
initialiaztion will not break the whole report.
2020-06-01 20:59:14 +02:00
Xavier Delaruelle
fa0a1d2d7f doc: desc. state handling rework in NEWS 2020-06-01 20:59:14 +02:00
Xavier Delaruelle
ed2533b8ef ts: adapt tests to new state mngt 2020-06-01 20:58:04 +02:00
Xavier Delaruelle
24b5043cdc Refactor 'reportfd' state initialization
Transform the startPager procedure into initStateReportfd to have it
automatically called first time value of 'reportfd' state is queried (so
first time a message has to be outputed).

initStateReportfd procedure embeds the output of document start in case
of structured output mode. This output is done there to avoid an
infinite loop of reportfd state initialization.

Initialization of the 'reportfd' state is triggered in initErrorReport
if debug mode is enabled to have its reportDebug calls processed in
buffer mode to get processed in correct order (otherwise reportfd
initialization will appear first, before debug messages stored in
buffer).

'already_report' state is removed as it is now useless.
2020-06-01 20:58:04 +02:00
Xavier Delaruelle
701d67e98a Refactor 'paginate' state initialization
Transform initPager procedure into initStatePaginate and set this
procedure as the initialization one for the 'paginate' state. Keep a
specific call to 'paginate' state to get it set prior pager
initialization.

'pager_started' state is removed as it is now useless.
2020-06-01 20:58:04 +02:00
Xavier Delaruelle
e85ac5241b Migrate 'report_sep_next' to state struct 2020-06-01 20:58:04 +02:00
Xavier Delaruelle
8a2dccb199 Migrate 'init_error_report' to state struct 2020-06-01 20:58:04 +02:00
Xavier Delaruelle
f3dcd7f603 Migrating 'already_report' to state struct 2020-06-01 20:58:04 +02:00
Xavier Delaruelle
8f818ae06f Migrate 'false_rendered' to state struct 2020-06-01 20:58:04 +02:00
Xavier Delaruelle
4103541c44 Migrate 'lm_info_cached' to state struct 2020-06-01 20:58:04 +02:00
Xavier Delaruelle
acca785264 Migrate all uname props to state struct
Instead of using a specific struct to cache uname properties value, use
global state structure. As a consequence, domainname, kernelversion,
nodename and osversion states are introduced. os state is changed just
to store OS name and not OS name and version: OS version has its own
state now.
2020-06-01 20:58:04 +02:00
Xavier Delaruelle
ee2f4ae513 Migrate 'sub2_separator' to state struct 2020-06-01 20:58:04 +02:00
Xavier Delaruelle
efa0b66fbd Migrate 'sub1_separator' to state struct 2020-06-01 20:58:04 +02:00
Xavier Delaruelle
89847e1d71 Migrate 'cwd' to state struct 2020-06-01 20:58:04 +02:00
Xavier Delaruelle
d063362c51 Migrate 'error_count' to state struct 2020-06-01 20:58:04 +02:00
Xavier Delaruelle
369062a03a Migrate 'return_false' to state struct 2020-06-01 20:58:04 +02:00
Xavier Delaruelle
94d26df397 Migrate 'autoinit' to state struct 2020-06-01 20:58:04 +02:00
Xavier Delaruelle
9868b67c40 Migrate 'inhibit_interp' to state struct 2020-06-01 20:58:04 +02:00
Xavier Delaruelle
ca15a98431 Migrate 'inhibit_errreport' to state struct 2020-06-01 20:58:04 +02:00