xonsh/news
Andy Kipp bb394a8e84
feat: add superhelp and additional context via new FuncAlias (#5366)
### Goals

* Make callable aliases transparent.
* Catch errors in callable aliases and show the name of the source.
* Show additional attributes: thredable, capturable.
* Closes #5266

## Exception

### Before

```xsh
aliases['cd']
# <function xonsh.dirstack.cd>

aliases['trace']
# <function xonsh.aliases.trace>

aliases['null'] = lambda: 1/0
null
# ZeroDivisionError: division by zero

@aliases.register('catch')
@aliases.register('me')
@aliases.register('if')
@aliases.register('you')
@aliases.register('can')
def _exc(args, stdin, stdout):
    for line in stdin.readlines():
        print(line.strip() + '!', file=stdout, flush=True)
    return 1/0 if 'i' in $__ALIAS_NAME else 0

echo hey | catch | me | if | you | can
# ZeroDivisionError: division by zero      <--- ???
# hey!!!!!
```

### After

```xsh 
aliases['cd']
# FuncAlias({'name': 'cd', 'func': 'cd'})

aliases['trace']
# FuncAlias({'name': 'trace', 'func': 'trace', '__xonsh_threadable__': False})

$XONSH_SHOW_TRACEBACK=False
$RAISE_SUBPROC_ERROR = False
aliases['null'] = lambda: 1/0
null
#Exception in thread {'cls': 'ProcProxyThread', 'name': 'Thread-15', 'func': FuncAlias({'name': 'null', 'func': '<lambda>'}), 'alias': 'null', 'pid': None}
#ZeroDivisionError: division by zero



@aliases.register('catch')
@aliases.register('me')
@aliases.register('if')
@aliases.register('you')
@aliases.register('can')
def _exc(args, stdin, stdout):
    for line in stdin.readlines():
        print(line.strip() + '!', file=stdout, flush=True)
    return 1/0 if 'i' in $__ALIAS_NAME else 0
echo hey | catch | me | if | you | can
# Exception in thread {'cls': 'ProcProxyThread', 'name': 'Thread-8', 'func': FuncAlias({'name': 'if', 'func': '_exc'}), 'alias': 'if', 'pid': None}
# ZeroDivisionError: division by zero
# hey!!!!!
```

## Superhelp

### Before
```xsh
@aliases.register("hello")
def _alias_hello():
    """Show world."""
    print('world')

hello?
# No manual entry for hello
```

### After
```xsh
@aliases.register("hello")
def _alias_hello():
    """Show world."""
    print('world')

hello?
# FuncAlias({'name': 'hello', 'func': '_alias_hello'}):
# Show world.
```



## For community
⬇️ **Please click the 👍 reaction instead of leaving a `+1` or 👍
comment**

---------

Co-authored-by: a <1@1.1>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-05-13 09:11:58 -04:00
..
appimage_py311.rst Downgrade AppImage to 3.11 (#5364) 2024-04-25 11:46:36 +02:00
downgrade_ptk.rst Downgrade prompt-toolkit to >=3.0.29,<3.0.40 (#5403) 2024-05-09 09:13:03 -04:00
env_completion.rst Use substring for env completion and better way to sort list (#5388) 2024-05-03 10:30:14 +02:00
fix_print_exception.rst Fixed showing exception message (#5394) 2024-05-06 19:48:43 +05:30
fix_process_traceback.rst Fixed empty stacktrace for CalledProcessError (#5391) 2024-05-04 11:50:32 +02:00
funcalias.rst feat: add superhelp and additional context via new FuncAlias (#5366) 2024-05-13 09:11:58 -04:00
jobs_catch_no_process.rst jobs: catching ChildProcessError (#5365) 2024-04-26 10:34:31 +02:00
jobs_repr.rst jobs: default representation changed to dict (#5363) 2024-04-26 10:26:24 +02:00
jupytext.rst Add Jupytext to news (#5402) 2024-05-10 11:03:44 +02:00
main_d.rst Fixed `xonsh -DVAR=VAL` behavior: initiate env variables before shell initialization. (#5396) 2024-05-06 17:39:10 +05:30
mini_refactor.rst CommandPipeline: clean repr + a bit of code cleaning (#5369) 2024-05-03 00:09:31 +05:30
no_env.rst feat: add --no-env flag to avoid inheriting parent-shell env (#5370) 2024-04-29 12:29:22 -04:00
popen_name.rst Add thread details to the exception (#5360) 2024-04-24 11:15:40 +02:00
shell_type.rst Shortcut for shell-type (#5367) 2024-04-25 20:10:18 +02:00
subproc_output_format.rst feat: add subproc output format, autostrip singleline output (#5377) 2024-05-02 11:48:25 -04:00
TEMPLATE.rst single instance of string.Formatter 2018-10-20 12:22:59 -06:00
trace_subproc.rst wip 2024-04-26 13:37:19 +05:30
waitpid_returncode.rst Fixed populating the return code for interrupted process. (#5380) 2024-05-02 22:10:53 +02:00
xonfig_env.rst Xonfig: show sensitive env variables that could affect the shell behavior. (#5374) 2024-05-02 22:46:22 +05:30
zulip.rst Xonsh Zulip Community started (#5372) 2024-04-29 10:01:02 -04:00