From 52632e38654436e9a418922aa901f29961ce06e0 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Thu, 31 Dec 2009 17:06:15 -0500 Subject: [PATCH] Completely revamped option parsing based on git-shell-style. This is in options.py. Also added some wvtests for option parsing stuff. --- Makefile | 11 +++++- cmd-split.py | 40 ++++++-------------- options.py | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++ t/__init__.py | 0 t/toptions.py | 47 +++++++++++++++++++++++ 5 files changed, 169 insertions(+), 31 deletions(-) create mode 100644 options.py create mode 100644 t/__init__.py create mode 100644 t/toptions.py diff --git a/Makefile b/Makefile index 1ecc388..7138e85 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,12 @@ randomgen: randomgen.o hashsplit.so: hashsplitmodule.o $(CC) -shared -o $@ $< - -test: all + +runtests: all + ./wvtest.py $(wildcard t/t*.py) + +runtests-cmdline: all + @echo "Testing \"$@\" in Makefile:" ./bup split tags1 ./bup split tags2 diff -u tags1 tags2 || true @@ -19,6 +23,9 @@ test: all ./bup join out2 diff -u testfile1 out1 diff -u testfile2 out2 + +test: all runtests-cmdline + ./wvtestrun $(MAKE) runtests %: %.o gcc -o $@ $< $(LDFLAGS) $(LIBS) diff --git a/cmd-split.py b/cmd-split.py index 2dbfa65..04b6d78 100755 --- a/cmd-split.py +++ b/cmd-split.py @@ -1,7 +1,6 @@ #!/usr/bin/env python -import sys, os, subprocess, errno, zlib, time, getopt -import hashsplit -import git +import sys, os, subprocess, errno, zlib, time +import hashsplit, git, options from helpers import * BLOB_LWM = 8192*2 @@ -74,41 +73,24 @@ def hashsplit_iter(f): if nv != lv: log('%d\t' % nv) lv = nv - - -def usage(): - log('Usage: bup split [-t] [stuff...] +prog [-t] +-- +t test +q,quiet quiet +l,longoption= long option with parameters and a really really long description that will require wrapping +p= short option with parameters +onlylong long option with no short +neveropt never called options +""" + +@wvtest +def test_options(): + o = options.Options('exename', optspec) + (opt,flags,extra) = o.parse(['-tttqp', 7, '--longoption', '19', + 'hanky', '--onlylong']) + WVPASSEQ(flags[0], ('-t', '')) + WVPASSEQ(flags[1], ('-t', '')) + WVPASSEQ(flags[2], ('-t', '')) + WVPASSEQ(flags[3], ('-q', '')) + WVPASSEQ(flags[4], ('-p', 7)) + WVPASSEQ(flags[5], ('--longoption', '19')) + WVPASSEQ(extra, ['hanky']) + WVPASSEQ((opt.t, opt.q, opt.p, opt.l, opt.onlylong, + opt.neveropt), (3,1,7,'19',1,None)) -- 2.39.2