Index: python/lib/aubio/cmd.py
===================================================================
--- python/lib/aubio/cmd.py	(revision b02d52f118afe92efebfabd3310a68546eb409ca)
+++ python/lib/aubio/cmd.py	(revision c95062be03d183ed7576fba29218eeae5e179404)
@@ -21,4 +21,5 @@
 
     subparsers = parser.add_subparsers(title='commands', dest='command',
+            parser_class= AubioArgumentParser,
             metavar="")
 
@@ -47,14 +48,14 @@
             help='estimate time of onsets (beginning of sound event)',
             formatter_class = argparse.ArgumentDefaultsHelpFormatter)
-    parser_add_input(subparser)
-    parser_add_buf_hop_size(subparser)
+    subparser.add_input()
+    subparser.add_buf_hop_size()
     helpstr = "onset novelty function"
     helpstr += " <default|energy|hfc|complex|phase|specdiff|kl|mkl|specflux>"
-    parser_add_method(subparser, helpstr=helpstr)
-    parser_add_threshold(subparser)
-    parser_add_silence(subparser)
-    parser_add_minioi(subparser)
-    parser_add_time_format(subparser)
-    parser_add_verbose_help(subparser)
+    subparser.add_method(helpstr=helpstr)
+    subparser.add_threshold()
+    subparser.add_silence()
+    subparser.add_minioi()
+    subparser.add_time_format()
+    subparser.add_verbose_help()
     subparser.set_defaults(process=process_onset)
 
@@ -63,13 +64,13 @@
     subparser = subparsers.add_parser('pitch',
             help='estimate fundamental frequency (monophonic)')
-    parser_add_input(subparser)
-    parser_add_buf_hop_size(subparser, buf_size=2048)
+    subparser.add_input()
+    subparser.add_buf_hop_size(buf_size=2048)
     helpstr = "pitch detection method <default|yinfft|yin|mcomb|fcomb|schmitt>"
-    parser_add_method(subparser, helpstr=helpstr)
-    parser_add_threshold(subparser)
-    parser_add_pitch_unit(subparser)
-    parser_add_silence(subparser)
-    parser_add_time_format(subparser)
-    parser_add_verbose_help(subparser)
+    subparser.add_method(helpstr=helpstr)
+    subparser.add_threshold()
+    subparser.add_pitch_unit()
+    subparser.add_silence()
+    subparser.add_time_format()
+    subparser.add_verbose_help()
     subparser.set_defaults(process=process_pitch)
 
@@ -78,8 +79,8 @@
     subparser = subparsers.add_parser('beat',
             help='estimate location of beats')
-    parser_add_input(subparser)
-    parser_add_buf_hop_size(subparser, buf_size=1024, hop_size=512)
-    parser_add_time_format(subparser)
-    parser_add_verbose_help(subparser)
+    subparser.add_input()
+    subparser.add_buf_hop_size(buf_size=1024, hop_size=512)
+    subparser.add_time_format()
+    subparser.add_verbose_help()
     subparser.set_defaults(process=process_beat)
 
@@ -88,8 +89,8 @@
     subparser = subparsers.add_parser('tempo',
             help='estimate overall tempo in bpm')
-    parser_add_input(subparser)
-    parser_add_buf_hop_size(subparser, buf_size=1024, hop_size=512)
-    parser_add_time_format(subparser)
-    parser_add_verbose_help(subparser)
+    subparser.add_input()
+    subparser.add_buf_hop_size(buf_size=1024, hop_size=512)
+    subparser.add_time_format()
+    subparser.add_verbose_help()
     subparser.set_defaults(process=process_tempo)
 
@@ -98,8 +99,8 @@
     subparser = subparsers.add_parser('notes',
             help='estimate midi-like notes (monophonic)')
-    parser_add_input(subparser)
-    parser_add_buf_hop_size(subparser)
-    parser_add_time_format(subparser)
-    parser_add_verbose_help(subparser)
+    subparser.add_input()
+    subparser.add_buf_hop_size()
+    subparser.add_time_format()
+    subparser.add_verbose_help()
     subparser.set_defaults(process=process_notes)
 
@@ -108,8 +109,8 @@
     subparser = subparsers.add_parser('mfcc',
             help='extract Mel-Frequency Cepstrum Coefficients')
-    parser_add_input(subparser)
-    parser_add_buf_hop_size(subparser)
-    parser_add_time_format(subparser)
-    parser_add_verbose_help(subparser)
+    subparser.add_input()
+    subparser.add_buf_hop_size()
+    subparser.add_time_format()
+    subparser.add_verbose_help()
     subparser.set_defaults(process=process_mfcc)
 
@@ -118,8 +119,8 @@
     subparser = subparsers.add_parser('melbands',
             help='extract energies in Mel-frequency bands')
-    parser_add_input(subparser)
-    parser_add_buf_hop_size(subparser)
-    parser_add_time_format(subparser)
-    parser_add_verbose_help(subparser)
+    subparser.add_input()
+    subparser.add_buf_hop_size()
+    subparser.add_time_format()
+    subparser.add_verbose_help()
     subparser.set_defaults(process=process_melbands)
 
@@ -128,85 +129,87 @@
     subparser = subparsers.add_parser('quiet',
             help='extract timestamps of quiet and loud regions')
-    parser_add_input(subparser)
-    parser_add_hop_size(subparser)
-    parser_add_silence(subparser)
-    parser_add_time_format(subparser)
-    parser_add_verbose_help(subparser)
+    subparser.add_input()
+    subparser.add_hop_size()
+    subparser.add_silence()
+    subparser.add_time_format()
+    subparser.add_verbose_help()
     subparser.set_defaults(process=process_quiet)
 
-def parser_add_input(parser):
-    parser.add_argument("source_uri", default=None, nargs='?',
-            help="input sound file to analyse", metavar = "<source_uri>")
-    parser.add_argument("-i", "--input", dest = "source_uri2",
-            help="input sound file to analyse", metavar = "<source_uri>")
-    parser.add_argument("-r", "--samplerate",
-            metavar = "<freq>", type=int,
-            action="store", dest="samplerate", default=0,
-            help="samplerate at which the file should be represented")
-
-def parser_add_verbose_help(parser):
-    parser.add_argument("-v","--verbose",
-            action="count", dest="verbose", default=1,
-            help="make lots of noise [default]")
-    parser.add_argument("-q","--quiet",
-            action="store_const", dest="verbose", const=0,
-            help="be quiet")
-
-def parser_add_buf_hop_size(parser, buf_size=512, hop_size=256):
-    parser_add_buf_size(parser, buf_size=buf_size)
-    parser_add_hop_size(parser, hop_size=hop_size)
-
-def parser_add_buf_size(parser, buf_size=512):
-    parser.add_argument("-B","--bufsize",
-            action="store", dest="buf_size", default=buf_size,
-            metavar = "<size>", type=int,
-            help="buffer size [default=%d]" % buf_size)
-
-def parser_add_hop_size(parser, hop_size=256):
-    parser.add_argument("-H","--hopsize",
-            metavar = "<size>", type=int,
-            action="store", dest="hop_size", default=hop_size,
-            help="overlap size [default=%d]" % hop_size)
-
-def parser_add_method(parser, method='default', helpstr='method'):
-    parser.add_argument("-m","--method",
-            metavar = "<method>", type=str,
-            action="store", dest="method", default=method,
-            help="%s [default=%s]" % (helpstr, method))
-
-def parser_add_threshold(parser, default=None):
-    parser.add_argument("-t","--threshold",
-            metavar = "<threshold>", type=float,
-            action="store", dest="threshold", default=default,
-            help="threshold [default=%s]" % default)
-
-def parser_add_silence(parser):
-    parser.add_argument("-s", "--silence",
-            metavar = "<value>", type=float,
-            action="store", dest="silence", default=-70,
-            help="silence threshold")
-
-def parser_add_minioi(parser):
-    parser.add_argument("-M", "--minioi",
-            metavar = "<value>", type=str,
-            action="store", dest="minioi", default="12ms",
-            help="minimum Inter-Onset Interval")
-
-def parser_add_pitch_unit(parser, default="Hz"):
-    help_str = "frequency unit, should be one of Hz, midi, bin, cent"
-    help_str += " [default=%s]" % default
-    parser.add_argument("-u", "--pitch-unit",
-            metavar = "<value>", type=str,
-            action="store", dest="pitch_unit", default=default,
-            help=help_str)
-
-def parser_add_time_format(parser):
-    helpstr = "select time values output format (samples, ms, seconds)"
-    helpstr += " [default=seconds]"
-    parser.add_argument("-T", "--time-format",
-             metavar='format',
-             dest="time_format",
-             default=None,
-             help=helpstr)
+class AubioArgumentParser(argparse.ArgumentParser):
+
+    def add_input(self):
+        self.add_argument("source_uri", default=None, nargs='?',
+                help="input sound file to analyse", metavar = "<source_uri>")
+        self.add_argument("-i", "--input", dest = "source_uri2",
+                help="input sound file to analyse", metavar = "<source_uri>")
+        self.add_argument("-r", "--samplerate",
+                metavar = "<freq>", type=int,
+                action="store", dest="samplerate", default=0,
+                help="samplerate at which the file should be represented")
+
+    def add_verbose_help(self):
+        self.add_argument("-v","--verbose",
+                action="count", dest="verbose", default=1,
+                help="make lots of noise [default]")
+        self.add_argument("-q","--quiet",
+                action="store_const", dest="verbose", const=0,
+                help="be quiet")
+
+    def add_buf_hop_size(self, buf_size=512, hop_size=256):
+        self.add_buf_size(buf_size=buf_size)
+        self.add_hop_size(hop_size=hop_size)
+
+    def add_buf_size(self, buf_size=512):
+        self.add_argument("-B","--bufsize",
+                action="store", dest="buf_size", default=buf_size,
+                metavar = "<size>", type=int,
+                help="buffer size [default=%d]" % buf_size)
+
+    def add_hop_size(self, hop_size=256):
+        self.add_argument("-H","--hopsize",
+                metavar = "<size>", type=int,
+                action="store", dest="hop_size", default=hop_size,
+                help="overlap size [default=%d]" % hop_size)
+
+    def add_method(self, method='default', helpstr='method'):
+        self.add_argument("-m","--method",
+                metavar = "<method>", type=str,
+                action="store", dest="method", default=method,
+                help="%s [default=%s]" % (helpstr, method))
+
+    def add_threshold(self, default=None):
+        self.add_argument("-t","--threshold",
+                metavar = "<threshold>", type=float,
+                action="store", dest="threshold", default=default,
+                help="threshold [default=%s]" % default)
+
+    def add_silence(self):
+        self.add_argument("-s", "--silence",
+                metavar = "<value>", type=float,
+                action="store", dest="silence", default=-70,
+                help="silence threshold")
+
+    def add_minioi(self, default="12ms"):
+        self.add_argument("-M", "--minioi",
+                metavar = "<value>", type=str,
+                action="store", dest="minioi", default=default,
+                help="minimum Inter-Onset Interval [default=%s]" % default)
+
+    def add_pitch_unit(self, default="Hz"):
+        help_str = "frequency unit, should be one of Hz, midi, bin, cent"
+        help_str += " [default=%s]" % default
+        self.add_argument("-u", "--pitch-unit",
+                metavar = "<value>", type=str,
+                action="store", dest="pitch_unit", default=default,
+                help=help_str)
+
+    def add_time_format(self):
+        helpstr = "select time values output format (samples, ms, seconds)"
+        helpstr += " [default=seconds]"
+        self.add_argument("-T", "--time-format",
+                 metavar='format',
+                 dest="time_format",
+                 default=None,
+                 help=helpstr)
 
 # some utilities
