Various other little bits.
[catacomb-python] / pwsafe
diff --git a/pwsafe b/pwsafe
index e285380..3485b08 100755 (executable)
--- a/pwsafe
+++ b/pwsafe
@@ -8,6 +8,14 @@ from os import environ
 from sys import argv, exit, stdin, stdout, stderr
 from getopt import getopt, GetoptError
 from fnmatch import fnmatch
+import sre as re
+
+prog = re.sub(r'^.*[/\\]', '', argv[0])
+def moan(msg):
+  print >>stderr, '%s: %s' % (prog, msg)
+def die(msg):
+  moan(msg)
+  exit(1)
 
 if 'PWSAFE' in environ:
   file = environ['PWSAFE']
@@ -70,7 +78,10 @@ def cmd_find(av):
   if len(av) != 1:
     return 1
   pw = PW(file)
-  print pw[av[0]]
+  try:
+    print pw[av[0]]
+  except KeyError, exc:
+    die('Password `%s\' not found.' % exc.args[0])
 
 def cmd_store(av):
   if len(av) < 1 or len(av) > 2:
@@ -134,7 +145,10 @@ def cmd_del(av):
     return 1
   pw = PW(file, 'w')
   tag = av[0]
-  del pw[tag]
+  try:
+    del pw[tag]
+  except KeyError, exc:
+    die('Password `%s\' not found.' % exc.args[0])
 
 def asciip(s):
   for ch in s:
@@ -163,9 +177,9 @@ commands = { 'create': [cmd_create,
              'dump' : [cmd_dump, '']}
 
 def version():
-  print 'pwsafe 1.0.0'
+  print '%s 1.0.0' % prog
 def usage(fp):
-  print >>fp, 'Usage: pwsafe COMMAND [ARGS...]'
+  print >>fp, 'Usage: %s COMMAND [ARGS...]' % prog
 def help():
   version()
   print
@@ -179,6 +193,8 @@ Options:
 -v, --version          Show program version number.
 -u, --usage            Show short usage message.
 
+-f, --file=FILE                Where to find the password-safe file.
+
 Commands provided:
 '''
   for c in commands:
@@ -215,5 +231,5 @@ if argv[0] in commands:
 else:
   c = 'find'
 if commands[c][0](argv):
-  print >>stderr, 'Usage: pwsafe %s %s' % (c, commands[c][1])
+  print >>stderr, 'Usage: %s %s %s' % (prog, c, commands[c][1])
   exit(1)