Browse files

start to flesh out command line usage

  • Loading branch information...
1 parent d8b9e4e commit bf38921fac4a5340887464006461d76a0ec85000 @jmoiron committed Oct 27, 2010
Showing with 58 additions and 0 deletions.
  1. +3 −0 bin/iris
  2. +55 −0 iris/script.py
View
3 bin/iris
@@ -3,3 +3,6 @@
"""Iris script executable."""
+import sys
+from iris import script
+sys.exit(script.main())
View
55 iris/script.py
@@ -3,3 +3,58 @@
"""Support for the iris script."""
+from cmdparse import Command, CommandParser
+
+class AddCommand(Command):
+ """Add a photo or directory of photos."""
+ def __init__(self):
+ Command.__init__(self, "add", summary="add files or directories.")
+ self.add_option('-r', '--recursive', action='store_true', default=False)
+
+ def run(self, options, args):
+ print "add: ", options, args
+
+class TagCommand(Command):
+ """Tag one or more photos.
+
+ You can tag photos based on filename:
+ iris tag photos/italy/*.JPG
+
+ Or via a query on iris' database:
+ iris tag -q ...
+ """
+ def __init__(self):
+ Command.__init__(self, "tag", summary="tag photos by filename, query, etc.")
+ self.add_option('-r', '--recursive', action='store_true', default=False)
+
+ def run(self, options, args):
+ print "tag: ", options, args
+
+class HelpCommand(Command):
+ """Provides extended help for other commands."""
+ def __init__(self):
+ Command.__init__(self, "help", summary="extended help for other commands.")
+
+ def run(self, options, args):
+ if not args:
+ self.parser.print_help()
+ return
+ name = args[0]
+ cmd = self.parser.find_command(name)
+ print cmd.__doc__
+ cmd.print_help()
+
+def main():
+ parser = CommandParser()
+ parser.add_command(HelpCommand())
+ parser.add_command(AddCommand())
+ parser.add_command(TagCommand())
+ command, options, args = parser.parse_args()
+ if command is None:
+ parser.print_help()
+ return 0
+ try:
+ return command.run(options, args)
+ except KeyboardInterrupt:
+ return -1
+

0 comments on commit bf38921

Please sign in to comment.