spotify/luigi — pull request #185 by jcdavis (2013-09-27 05:44:05+00:00)
Title: Improve handling of bad task name parameter

Currently it can be somewhat confusing if you use an invalid task name, especially when you have hundreds of tasks and get pages of the available tasks as (largely useless) output. This pull request does the following:

1. Sorts the list of available tasks in the argument list.
2. Provides spelling correction by computing the edit distances from existing tasks.

Unfortunately, argparse doesn't offer much in terms of extendability, so this is much hackier than I wish it could be.

Example output using one of the example tasks:
Before:

python examples/top_artists.py Streamss --local-scheduler --date-interval 2012-06
No handlers could be found for logger "luigi-interface"
usage: top_artists.py [-h] [--scheduler-port SCHEDULER_PORT] [--lock]
[--workers WORKERS] [--lock-pid-dir LOCK_PID_DIR]
[--scheduler-host SCHEDULER_HOST] [--local-scheduler]
[--pool POOL]
{JobTask,Top10Artists,Task,WrapperTask,CopyToTable,ArtistToplistToDatabase,AggregateArtists,StreamsHdfs,Streams,AggregateArtistsHadoop,EnvironmentParamsContainer,BaseHadoopJobTask}
...
top_artists.py: error: argument command: invalid choice: 'Streamss' (choose from 'JobTask', 'Top10Artists', 'Task', 'WrapperTask', 'CopyToTable', 'ArtistToplistToDatabase', 'AggregateArtists', 'StreamsHdfs', 'Streams', 'AggregateArtistsHadoop', 'EnvironmentParamsContainer', 'BaseHadoopJobTask')

After:

python examples/top_artists.py Streamss --local-scheduler --date-interval 2012-06
No handlers could be found for logger "luigi-interface"
usage: top_artists.py [-h] [--scheduler-port SCHEDULER_PORT] [--lock]
[--workers WORKERS] [--lock-pid-dir LOCK_PID_DIR]
[--scheduler-host SCHEDULER_HOST] [--local-scheduler]
[--pool POOL]
{AggregateArtists,AggregateArtistsHadoop,ArtistToplistToDatabase,BaseHadoopJobTask,CopyToTable,EnvironmentParamsContainer,JobTask,Streams,StreamsHdfs,Task,Top10Artists,WrapperTask}
...
top_artists.py: error: No task Streamss. Did you mean:
Streams
StreamsHdfs