injekt/slop — Issue #31: Think about supporting 'bup.options' style parsing
Author: injekt
Created: 2011-11-02 17:20:23+00:00
State: open

http://apenwarr.ca/log/?m=201111#02

```
optspec = """
bup save [-tc] [-n name]
--
r,remote= hostname:/path/to/repo of remote repository
t,tree output a tree id
c,commit output a commit id
n,name= name of backup set to update (if any)
d,date= date for the commit (seconds since the epoch)
v,verbose increase log output (can be used more than once)
q,quiet don't show progress meter
smaller= only back up files smaller than n bytes
bwlimit= maximum bytes/sec to transmit to server
f,indexfile= the name of the index file (normally BUP_DIR/bupindex)
strip strips the path to every filename given
strip-path= path-prefix to be stripped when saving
graft= a graft point *old_path*=*new_path* (can be used more than once)
"""
o = options.Options(optspec)
(opt, flags, extra) = o.parse(sys.argv[1:])
```

```
spec = <<-SPEC
ruby foo.rb [options]
---
r,remote= hostname:/path/to/repo of remote repository
t,tree output a tree id
c,commit output a commit id
n,name= name of backup set to update (if any)
d,date= date for the commit (seconds since the epoch)
v,verbose increase log output (can be used more than once)
q,quiet don't show progress meter
smaller= only back up files smaller than n bytes
bwlimit= maximum bytes/sec to transmit to server
f,indexfile= the name of the index file (normally BUP_DIR/bupindex)
strip strips the path to every filename given
strip-path= path-prefix to be stripped when saving
graft= a graft point *old_path*=*new_path* (can be used more than once)
SPEC

opts = Slop.spec(spec)
opts.parse

# ruby foo.rb --verbose --smaller 10 -r foo:/tmp
opts.verbose? #=> true
opts[:smaller] #=> 10
opts[:remote] #=> foo:/tmp
```