#!/usr/bin/python2.1
# This file is released to the Public Domain by Moshe Zadka
# Author: Moshe Zadka <pms@zadka.site.co.il>
import sys
import PMS.Commands, PMS.Console

usage = "%(name)s: usage: %(name)s (subject|date|from)\n"

commands = { 
	'subject': PMS.Commands.sort_subject,
	'from': PMS.Commands.sort_from,
	'date': PMS.Commands.sort_date
}

def main():
	name = sys.argv[0]
	if len(sys.argv)<2:
		sys.stderr.write(usage % vars())
	command = PMS.Console.get_begins_with(sys.argv[1], commands.keys())
	if len(command) != 1:
		sys.stderr.write(usage % vars())
	command = command[0]
	try:
		PMS.Console.run_function(commands[command], (), {})
	except RuntimeError, message:
		sys.stderr.write(("%(name)s: "+str(message)+"\n") % vars())

if __name__ == '__main__':
	main()
