Jaymon / captain

command line python scripts for humans
MIT License
13 stars 1 forks source link

new interface idea #45

Closed Jaymon closed 4 years ago

Jaymon commented 6 years ago

inspired by fire

and function in the file would be a subcommand, so:

# script.py
import captain

def foo(): print("foo")
def bar(): print("bar")

captain.exit()

could be used like:

$ python script.py foo
foo
$ python script.py bar
bar

classes could be sub-sub commands:

# script.py
import captain

def foo(): print("foo")

class Bar(object):
    def che(self): print("bar che")
    def __call__(self): print ("bar")

captain.exit()

would result in:

$ python script.py foo
foo
$ python script.py bar
bar
$python script.py bar che
bar che

any function that started with an underscore (eg, def _baz) would be hidden from being called from the command line.

The primary benefit would be getting rid of the main_ prefix. Though you could still use it if you had no subcommands, so:

# script.py
import captain

def main(): print("main")

captain.exit()

would be called with:

$ python script.py
main