mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-06 09:20:57 +01:00
main.py takes script file or script on stdin
This commit is contained in:
parent
0ff1b8df5f
commit
b1423b78ee
1 changed files with 21 additions and 3 deletions
|
@ -13,6 +13,11 @@ parser.add_argument('-c',
|
||||||
dest='command',
|
dest='command',
|
||||||
required=False,
|
required=False,
|
||||||
default=None)
|
default=None)
|
||||||
|
parser.add_argument('file',
|
||||||
|
metavar='script-file',
|
||||||
|
help='If present, execute the script contained in script-file and exit',
|
||||||
|
nargs='?',
|
||||||
|
default=None)
|
||||||
|
|
||||||
def main(argv=None):
|
def main(argv=None):
|
||||||
"""Main entry point for xonsh cli."""
|
"""Main entry point for xonsh cli."""
|
||||||
|
@ -21,10 +26,23 @@ def main(argv=None):
|
||||||
|
|
||||||
shell = Shell()
|
shell = Shell()
|
||||||
|
|
||||||
if args.command is None:
|
if args.command is not None:
|
||||||
shell.cmdloop()
|
# run a single command and exit
|
||||||
else:
|
|
||||||
shell.default(args.command)
|
shell.default(args.command)
|
||||||
|
elif args.file is not None:
|
||||||
|
if os.path.isfile(args.file):
|
||||||
|
with open(args.file) as f:
|
||||||
|
for line in f:
|
||||||
|
shell.default(line)
|
||||||
|
else:
|
||||||
|
print('xonsh: {0}: No such file or directory.'.format(args.file))
|
||||||
|
elif not sys.stdin.isatty():
|
||||||
|
# run a script given on stdin
|
||||||
|
for line in sys.stdin:
|
||||||
|
shell.default(line)
|
||||||
|
else:
|
||||||
|
# otherwise, enter the shell
|
||||||
|
shell.cmdloop()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Add table
Reference in a new issue