在GoLang CLI程序中传递长参数的最佳方法及其局限性

I am writing a CLI program in GO and need to be able to pass a rather long list of arguments to the main function. At the moment I am using the standard way of passing arguments (space separated values) and then retrieve 'em using os.Args[index].

So my questions are:

  1. Is there a limit to the number of arguments one can pass?
  2. Is there a limit to the length of a string argument?
  3. Is there any other way of achieving this and if so how?
  1. No, as far as go is concerned. Command line args are parsed into a []string, so at this level it's just a matter of how much memory is available. But, the comments below are correct. Your system will have its own lower limits that you'll hit first.
  2. Same as above.
  3. If you find yourself passing tons for args for every run:
    • if they don't change much, do they make sense as sane defaults for your flags?
    • if they don't make sense as defaults, consider moving to reading them from a config file. CSV, YAML, whatever.

Without knowing more, I'd recommend a the config file. They make it easy to track different configs/runs, easier to edit than a long list of cmd line args, and you can always write it so that args on the cmd line overwrite values in the config.

Check out awesome-go for libraries that already do this, specifically under the command-line and configuration sections.