TheFriendlyCoder / friendlyshell

Framework for writing interactive Python command line interfaces, similar to the 'cmd' built in class.
Apache License 2.0
0 stars 0 forks source link

Add support for return values to action methods #62

Open TheFriendlyCoder opened 6 years ago

TheFriendlyCoder commented 6 years ago

Currently the FShell APIs allow help methods, completion methods and alias methods to return data for use by the core APIs. However, actual action methods currently don't support any return values to speak of.

What I'd like to do here is add support for a simple "return code" value to be returned from each action method. If a method doesn't return anything we'll assume a return code of 0, and any non-zero return code will be assumed to represent some sort of error or failure condition.

For now I think it'd be best to just record this return value somehow for later reference, like for returning from the run() method, as a way of indicating to the caller that the command has not succeeded. In the most trivial case this could be used when running FShell using an input script to detect if the operations performed by the script were successful or not.

For this particular improvement I think it'd be sufficient to detect the return value from an action method, store the value from the most recent action performed in a member variable, and return that value from the run() method for future reference.