File: 1.0.0.markdown

package info (click to toggle)
scopt 3.5.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 312 kB
  • sloc: xml: 45; makefile: 13
file content (38 lines) | stat: -rw-r--r-- 1,626 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
29
30
31
32
33
34
35
36
37
38
## hello, world
This is the initial release of scopt, a little command line parsing library.

You can customize an *OptionParser* by passing in functions to process each option or argument.

    val parser = new OptionParser("scopt") {
      intOpt("f", "foo", "foo is an integer property", {v: Int => config.foo = v})
      opt("o", "output", "<file>", "output is a string property", {v: String => config.bar = v})
      booleanOpt("xyz", "xyz is a boolean property", {v: Boolean => config.xyz = v})
      keyValueOpt("l", "lib", "<libname>", "<filename>", "load library <libname>",
        {(key: String, value: String) => { config.libname = key; config.libfile = value } })
      arg("<singlefile>", "<singlefile> is an argument", {v: String => config.whatnot = v})
      // arglist("<file>...", "arglist allows variable number of arguments",
      //   {v: String => config.files = (v :: config.files).reverse })
    }
    if (parser.parse(args)) {
       // do stuff
    }
    else {
      // arguments are bad, usage message will have been displayed
    }

It handles various kinds of options such as optional, required, and key-value.
From the above, it also automatically generates the usage text as follows:

    Usage: scopt [options] <filename>

      -f <value> | --foo <value>
            foo is an integer property
      -o <file> | --output <file>
            output is a string property
      --xyz <value>
            xyz is a boolean property
      -l:<libname>=<filename> | --lib:<libname>=<filename>
            load library <libname>
      <singlefile>
            <singlefile> is an argument