You can pass arguments to the image and also register own command line commands. Just check out the class comment in class "CommandLineHandler" and check its subclasses.
Creating an own handler is easy: just subclass CommandLineHandler with a custom class:
CommandLineHandler subclass: #TimeCommandLineHandler
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Custom-CommandLine'
Implement a class side method to return the command name:
commandName
^ 'time'
and implement an instance side #activate method:
activate
self activateHelp.
FileStream stdout
nextPutAll: '[time] ';
nextPutAll: Time now asString
Now call it from the command line
$PATH_TO_VM myImage.image time
and it will print the current time on stdout. Note that the #activateHelp will activate the --help option which displays the class comment of your custom handler class.
Also note that it is now possible to write in colors in a terminal from Pharo as this photo shows (click to enlarge):
No comments:
Post a Comment