-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathfire.py
More file actions
21 lines (19 loc) · 771 Bytes
/
fire.py
File metadata and controls
21 lines (19 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""Turns any object into a CLI tool using Fire in the xonsh shell."""
@aliases.register
def _fire(args, stdout):
"""Turns any object into a CLI tool using Fire in the xonsh shell."""
if len(args) == 0:
print('Usage: fire <object name> [args|--help]', file=stderr)
print('Example: fire @ --help', file=stderr)
return 1
def fixed_fire():
"""Fix https://github.com/google/python-fire/issues/188"""
import fire
fire.core.Display = lambda lines, out: stdout.write("\n".join(lines) + "\n")
return fire
try:
obj = eval(args[0])
except:
obj = evalx(args[0])
with __xonsh__.env.swap(UPDATE_OS_ENVIRON=True, PAGER='-'):
fixed_fire().Fire(obj, command=args[1:], name=args[0])