Skip to content

Commit 27582ca

Browse files
committed
cli: Allow consuming arguments from the command line when running a file
1 parent f4adc25 commit 27582ca

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/sage/cli/run_file_cmd.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def extend_parser(parser: argparse.ArgumentParser):
2323
"""
2424
parser.add_argument(
2525
"file",
26-
nargs="?",
26+
nargs="*",
2727
help="execute the given file as sage code",
2828
)
2929

@@ -32,13 +32,16 @@ def __init__(self, options: CliOptions):
3232
Initialize the command.
3333
"""
3434
self.options = options
35+
# shift sys.argv for compatibility with the old sage bash script and python command when consuming arguments from the command line
36+
import sys
37+
del sys.argv[0]
3538

3639
def run(self) -> int:
3740
r"""
3841
Execute the given command.
3942
"""
40-
input_file = preparse_file_named(self.options.file) if self.options.file.endswith('.sage') else self.options.file
41-
if self.options.file.endswith('.pyx') or self.options.file.endswith('.spyx'):
43+
input_file = preparse_file_named(self.options.file[0]) if self.options.file[0].endswith('.sage') else self.options.file[0]
44+
if self.options.file[0].endswith('.pyx') or self.options.file[0].endswith('.spyx'):
4245
s = load_cython(input_file)
4346
eval(compile(s, tmp_filename(), 'exec'), sage_globals())
4447
else:

0 commit comments

Comments
 (0)