Easily invoke commands from one directory (CommandPath)

A CommandPath is an object that you can create to represent a directory with executables in it. You can then use that object to get command objects which you can then run.

This feature was created to be able to create a "postgres" or "node" or "virtualenv" CommandPath object referencing their bin directory. Commands in those bin directories (e.g. postgres / psql) could be run and be able to directly call other commands in that directory without referencing the absolute path.

Command objects that are created from CommandPath objects will automatically be run with that directory added to the beginning of their PATH. This means that they can run each other directly without specifying the directory.


echo hello $1 > output
ls $1
echo hello $1 > output
command1 tom
echo hello dots > output

from commandlib import CommandPath

command_path = CommandPath("./bin_directory")

Run command from CommandPath:


File 'output' will contain:

hello harry

Command can call other command in CommandPath without specifying its path:


File 'output' will contain:

hello tom

Commands with dots in command path are translated into underscores:


File 'output' will contain:

hello dots

Referencing a non-existent command raises an exception:

'non_existent_command' not found in '/path/to/bin_directory'

Executable specification

Documentation automatically generated from command-path.story storytests.