1

From the docs, I've installed the DocOpt with Pkg.add("DocOpt") and created the same naval_fate.jl:

doc = """Naval Fate.

Usage:
  naval_fate.jl ship new <name>...
  naval_fate.jl ship <name> move <x> <y> [--speed=<kn>]
  naval_fate.jl ship shoot <x> <y>
  naval_fate.jl mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate.jl -h | --help
  naval_fate.jl --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.

"""

using DocOpt  # import docopt function

arguments = docopt(doc, version=v"2.0.0")
dump(arguments)

But when I run julia naval_fate.jl ship new FOO, I didn't dump the results as shown in the documentation. I got this instead:

Dict{AbstractString,Any}
  slots: Array{UInt8}((64,)) UInt8[0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00  …  0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x01]
  keys: Array{AbstractString}((64,))
    1: #undef
    2: #undef
    3: #undef
    4: #undef
    5: #undef
    ...
    60: #undef
    61: #undef
    62: SubString{String}
      string: String " (  ship new <name> ...   )   |   (  ship <name> move <x> <y>  [ --speed=<kn> ]   )   |   (  ship shoot <x> <y>  )   |   (  mine  ( set | remove )  <x> <y>  [ --moored | --drifting ]   )   |   (  -h  |  --help  )   |   (  --version  ) "
      offset: Int64 58
      endof: Int64 3
    63: #undef
    64: SubString{String}
      string: String "--speed <kn>"
      offset: Int64 0
      endof: Int64 7
  vals: Array{Any}((64,))
    1: #undef
    2: #undef
    3: #undef
    4: #undef
    5: #undef
    ...
    60: #undef
    61: #undef
    62: Void nothing
    63: #undef
    64: SubString{String}
      string: String "Naval Fate.\n\nUsage:\n  naval_fate.jl ship new <name>...\n  naval_fate.jl ship <name> move <x> <y> [--speed=<kn>]\n  naval_fate.jl ship shoot <x> <y>\n  naval_fate.jl mine (set|remove) <x> <y> [--moored|--drifting]\n  naval_fate.jl -h | --help\n  naval_fate.jl --version\n\nOptions:\n  -h --help     Show this screen.\n  --version     Show version.\n  --speed=<kn>  Speed in knots [default: 10].\n  --moored      Moored (anchored) mine.\n  --drifting    Drifting mine.\n\n"
      offset: Int64 379
      endof: Int64 2
  ndel: Int64 0
  count: Int64 15
  age: UInt64 27
  idxfloor: Int64 1
  maxprobe: Int64 4

The output shown on the documentation is:

$ julia naval_fate.jl ship new FOO
Dict{String,Any} len 15
  remove: Bool false
  --help: Bool false
  <name>: Array(UTF8String,(1,)) UTF8String["FOO"]
  --drifting: Bool false
  mine: Bool false
  move: Bool false
  --version: Bool false
  --moored: Bool false
  <x>: Nothing nothing
  ship: Bool true
  new: Bool true
  ...

Why is that so? Is it because of some cached session?

4

0 に答える 0