Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,31 @@ Please see [The Python Fire Guide](docs/guide.md).

_Note that these flags are separated from the Fire command by an isolated `--`._

## Xonsh shell support

```xsh
xpip install fire
xontrib load fire

obj = {'var': 'val'}
fire obj var
# val

type(@.env)
# xonsh.environ.Env
fire @.env get USER - upper
# PC

type(@.imp)
# xonsh.built_ins.InlineImporter
fire @.imp.json dumps --help
# @.imp.json dumps OBJ <flags>
fire @.imp.json dumps '{"a":1}' --indent 4
# {
# "a": 1
# }
```

## License

Licensed under the
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test = [
]

[tool.setuptools.packages.find]
include = ["fire*"]
include = ["fire*", "xontrib*"]

[tool.setuptools.package-data]
fire = ["console/*"]
Expand Down
21 changes: 21 additions & 0 deletions xontrib/fire.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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])