1

文档中,我安装了DocOptwithPkg.add("DocOpt")并创建了相同的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)

但是当我运行时julia naval_fate.jl ship new FOO,我没有转储文档中显示的结果。我得到了这个:

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

文档中显示的输出是:

$ 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
  ...

为什么呢?是因为一些缓存的会话吗?

4

0 回答 0