Introduce a sort-by flag that accepts a python comparator function
I'd like to add some more complex sorting logic, it would be nice if power users could pass a python function that is used as a comparator to the program.
We store data in an sqlite cache, and query that. So your function would need to write SQL to query todos.
I have some vague plans to move caching out into a separate helper, which indexes all todos and provides an API for querying. todoman would become mostly a UI on top of that.
So I'm not sure if I'd implement this right now, or wait until that happens.
This would only influence the sorting of the result though, so something like
from functools import cmp_to_key
from dopy.core import Dopy
# Using dopy to get python without indentation to make it easier to specify the func in a flag
dopy = Dopy()
if flags.sort_by not None:
processed = dopy.preprocess(source)
def compare(x, y):
return exec(processed, namespace={"x": x, "y": y})
data = sorted(data, key=cmp_to_key(compare))
could work without really increasing processing time or memory footprint significantly.
At least I think so, I haven't tried it yet.