How to access command-line arguments passed to a Go program?

前端 未结 6 1229
夕颜
夕颜 2020-12-08 01:26

How do I access command-line arguments in Go? They\'re not passed as arguments to main.

A complete program, possibly created by linking m

6条回答
  •  Happy的楠姐
    2020-12-08 02:23

    Peter's answer is exactly what you need if you just want a list of arguments.

    However, if you're looking for functionality similar to that present on UNIX, then you could use the go implementation of docopt. You can try it here.

    docopt will return JSON that you can then process to your heart's content.

提交回复
热议问题