Is there a “standard” format for command line/shell help text?

前端 未结 8 1424
难免孤独
难免孤独 2020-11-30 16:30

If not, is there a de facto standard? Basically I\'m writing a command line help text like so:

usage: app_name [opti         


        
8条回答
  •  無奈伤痛
    2020-11-30 16:34

    Typically, your help output should include:

    • Description of what the app does
    • Usage syntax, which:
      • Uses [options] to indicate where the options go
      • arg_name for a required, singular arg
      • [arg_name] for an optional, singular arg
      • arg_name... for a required arg of which there can be many (this is rare)
      • [arg_name...] for an arg for which any number can be supplied
      • note that arg_name should be a descriptive, short name, in lower, snake case
    • A nicely-formatted list of options, each:
      • having a short description
      • showing the default value, if there is one
      • showing the possible values, if that applies
      • Note that if an option can accept a short form (e.g. -l) or a long form (e.g. --list), include them together on the same line, as their descriptions will be the same
    • Brief indicator of the location of config files or environment variables that might be the source of command line arguments, e.g. GREP_OPTS
    • If there is a man page, indicate as such, otherwise, a brief indicator of where more detailed help can be found

    Note further that it's good form to accept both -h and --help to trigger this message and that you should show this message if the user messes up the command-line syntax, e.g. omits a required argument.

提交回复
热议问题