mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-06 09:20:57 +01:00
small cleanup, still failing tests
passing new tests, failing for invalid arguments
This commit is contained in:
parent
dfc48b6cab
commit
471fd37df0
1 changed files with 12 additions and 13 deletions
|
@ -113,7 +113,7 @@ parser.add_argument('args',
|
||||||
metavar='args',
|
metavar='args',
|
||||||
help='Additional arguments to the script specified '
|
help='Additional arguments to the script specified '
|
||||||
'by script-file',
|
'by script-file',
|
||||||
nargs='*',
|
nargs=argparse.REMAINDER,
|
||||||
default=[])
|
default=[])
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,24 +150,19 @@ def premain(argv=None):
|
||||||
setproctitle(' '.join(['xonsh'] + sys.argv[1:]))
|
setproctitle(' '.join(['xonsh'] + sys.argv[1:]))
|
||||||
builtins.__xonsh_ctx__ = {}
|
builtins.__xonsh_ctx__ = {}
|
||||||
args, other = parser.parse_known_args(argv)
|
args, other = parser.parse_known_args(argv)
|
||||||
if args.file is not None:
|
file = args.file
|
||||||
|
if file is not None:
|
||||||
arguments = (argv or sys.argv)
|
arguments = (argv or sys.argv)
|
||||||
file_index = arguments.index(args.file)
|
index = arguments.index(file)
|
||||||
# A script-file was passed and is to be executed. The argument parser
|
# A script-file was passed and is to be executed. The argument parser
|
||||||
# might have parsed switches intended for the script, so reset the
|
# might have parsed switches intended for the script, so reset the
|
||||||
# parsed switches to their default values
|
# parsed switches to their default values
|
||||||
old_args = args
|
args = parser.parse_args(arguments[1:index])
|
||||||
args = parser.parse_known_args('')[0]
|
args.file = file
|
||||||
args.file = old_args.file
|
|
||||||
# Save the arguments that are intended for the script-file. Switches
|
# Save the arguments that are intended for the script-file. Switches
|
||||||
# and positional arguments passed before the path to the script-file are
|
# and positional arguments passed before the path to the script-file are
|
||||||
# ignored.
|
# ignored.
|
||||||
args.args = arguments[file_index+1:]
|
args.args = arguments[index+1:]
|
||||||
elif not args.args and other and other[0].startswith('-'):
|
|
||||||
err_msg = 'xonsh: error: invalid argument {!r}'.format(other[0])
|
|
||||||
print(err_msg, file=sys.stderr)
|
|
||||||
parser.print_help()
|
|
||||||
exit()
|
|
||||||
if args.help:
|
if args.help:
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
exit()
|
exit()
|
||||||
|
@ -237,7 +232,7 @@ def main(argv=None):
|
||||||
code = sys.stdin.read()
|
code = sys.stdin.read()
|
||||||
run_code_with_cache(code, shell.execer, glb=shell.ctx, loc=None,
|
run_code_with_cache(code, shell.execer, glb=shell.ctx, loc=None,
|
||||||
mode='exec')
|
mode='exec')
|
||||||
else:
|
elif len(sys.argv) <= 1:
|
||||||
# otherwise, enter the shell
|
# otherwise, enter the shell
|
||||||
env['XONSH_INTERACTIVE'] = True
|
env['XONSH_INTERACTIVE'] = True
|
||||||
ignore_sigtstp()
|
ignore_sigtstp()
|
||||||
|
@ -248,6 +243,10 @@ def main(argv=None):
|
||||||
from xonsh import xonfig # lazy import
|
from xonsh import xonfig # lazy import
|
||||||
xonfig.main(['wizard', '--confirm'])
|
xonfig.main(['wizard', '--confirm'])
|
||||||
shell.cmdloop()
|
shell.cmdloop()
|
||||||
|
else:
|
||||||
|
print('xonsh: error: invalid argument {!r}'.format(sys.argv[1]))
|
||||||
|
parser.print_usage()
|
||||||
|
parser.exit(1)
|
||||||
postmain(args)
|
postmain(args)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue