File: constraints.rb

package info (click to toggle)
ruby-optimist 3.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 348 kB
  • sloc: ruby: 2,912; makefile: 4
file content (28 lines) | stat: -rwxr-xr-x 708 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env ruby
require_relative '../lib/optimist'

opts = Optimist::options do
  opt :dog, "user is dog"
  opt :cat, "user is cat"
  opt :rat, "user is rat"
  conflicts :dog, :cat, :rat

  opt :wash, "pet wash"
  opt :dry, "pet dry"
  depends :wash, :dry

  opt :credit, "pay creditcard"
  opt :cash, "pay cash"
  opt :cheque, "pay cheque"
  either :credit, :cash, :cheque
end
p opts

# $ ./constraints.rb --dog --cat
# Error: only one of --dog, --cat, --rat can be given.

# $ ./constraints.rb --dog --wash
# Error: --wash, --dry have a dependency and must be given together.

# $ ./constraints.rb --cash --cheque --rat --wash --dry
# Error: one and only one of --credit, --cash, --cheque is required.