forked from wyvernlang/wyvern
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolved issue wyvernlang#326, supported command line arguments, adde…
…d example Wyvern program that demonstrate the usage of command line argument
- Loading branch information
Showing
4 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// program to print all the command line arguments given by the user | ||
// delimited by comma | ||
|
||
require stdout | ||
require java | ||
import java:wyvern.stdlib.support.CommandLineUtils.utils | ||
|
||
val cmdLineArgs = utils.getArgs() // store the arguments in a dynamic array. | ||
|
||
def printCmdLineArgs(index: Int): Unit | ||
if (index != utils.getLength() - 1) | ||
stdout.print(cmdLineArgs.get(index)) | ||
stdout.print(", ") | ||
printCmdLineArgs(index + 1) | ||
else | ||
stdout.print(cmdLineArgs.get(utils.getLength() - 1)) | ||
stdout.println() | ||
|
||
printCmdLineArgs(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package wyvern.stdlib.support; | ||
|
||
public class CommandLineUtils { | ||
private static String[] arguments; // array of command line arguments. | ||
private static DynArrayList argumentsArrayList; // array list of command line arguments. | ||
public static final CommandLineUtils utils = new CommandLineUtils(); | ||
|
||
private CommandLineUtils() { | ||
} | ||
|
||
public CommandLineUtils(String[] arguments) { | ||
this.arguments = arguments; | ||
this.convertToDynArrayList(); | ||
} | ||
|
||
public DynArrayList getArgs() { | ||
return argumentsArrayList; | ||
} | ||
|
||
public int getLength() { | ||
return arguments.length; | ||
} | ||
|
||
private void convertToDynArrayList() { | ||
argumentsArrayList = new DynArrayList(); | ||
for (String str : arguments) { | ||
argumentsArrayList.add(str); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters