Skip to content

Commit 5697731

Browse files
committed
make -m switch work
1 parent dd28e28 commit 5697731

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public static void main(String[] args) {
6262
private ArrayList<String> programArgs = null;
6363
private String commandString = null;
6464
private String inputFile = null;
65-
private String module = null;
6665
private boolean ignoreEnv = false;
6766
private boolean inspectFlag = false;
6867
private boolean verboseFlag = false;
@@ -104,9 +103,10 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
104103
inspectFlag = true;
105104
break;
106105
case "-m":
107-
i += 1;
108-
if (i < arguments.size()) {
109-
module = arguments.get(i);
106+
if (i + 1 < arguments.size()) {
107+
// don't increment i here so that we capture the correct args
108+
String module = arguments.get(i + 1);
109+
commandString = "import runpy; runpy._run_module_as_main('" + module + "')";
110110
} else {
111111
print("Argument expected for the -m option");
112112
printShortHelp();
@@ -179,7 +179,7 @@ protected List<String> preprocessArguments(List<String> arguments, Map<String, S
179179
}
180180
}
181181

182-
if (inputFile != null || commandString != null || module != null) {
182+
if (inputFile != null || commandString != null) {
183183
i += 1;
184184
if (i < arguments.size()) {
185185
programArgs.addAll(arguments.subList(i, arguments.size()));
@@ -252,7 +252,7 @@ protected void launch(Builder contextBuilder) {
252252
try (Context context = contextBuilder.build()) {
253253
runVersionAction(versionAction, context.getEngine());
254254

255-
if (!quietFlag && (verboseFlag || (commandString == null && inputFile == null && module == null && stdinIsInteractive))) {
255+
if (!quietFlag && (verboseFlag || (commandString == null && inputFile == null && stdinIsInteractive))) {
256256
print("Python " + evalInternal(context, "import sys; sys.version + ' on ' + sys.platform").asString());
257257
if (!noSite) {
258258
print("Type \"help\", \"copyright\", \"credits\" or \"license\" for more information.");

0 commit comments

Comments
 (0)