Skip to content

How to add a description section to your usage guide

Lloyd Brookes edited this page Jun 30, 2019 · 1 revision

Demonstrates supplying specific table layout options to achieve more advanced layout. In this case the second column (containing the hammer and sickle) has a fixed width of 40 and noWrap enabled (as the input is already formatted as desired).

Code

const getUsage = require('command-line-usage')
const ussr =
`                         M
                          MM
                           ,MM
                             MMM
                              MMM
               MMMMMMMM~       MMMM
              MMMMMMMM          MMMM
            MMMMMMMMM            MMMM
          MMMMMMMMM              MMMM7
        +MMMMMMMMMMM=             MMMM
       MMMMMMMMM MMMMM            MMMMM
         MMMMM    MMMMMN          MMMMM
           M       MMMMMM         MMMMM
                     MMMMM?       MMMMM
                      MMMMMM      MMMMM
                        MMMMMM   MMMMMM
                         MMMMMM  MMMMMM
          M               MMMMMMMMMMMM
       MMMMMM               MMMMMMMMM
      MMMMMMMMM              MMMMMMM?
    MMMM   MMMMMM         MMMMMMMMMMM
 MMMMMM     MMMMMMMMMMMMMMMMMMMMMMMMMM
MMMMMM        MMMMMMMMMMMMMMMMMM MMMM
MMMM             MMMMMMMMMMMM           `

const optionDefinitions = [
  {
    name: 'help',
    description: 'Display this usage guide.',
    alias: 'h',
    type: Boolean
  },
  {
    name: 'src',
    description: 'The input files to process. This is some additional text existing solely to demonstrate word-wrapping, nothing more, nothing less. And nothing in between.',
    type: String,
    multiple: true,
    defaultOption: true,
    typeLabel: '{underline file} ...'
  },
  {
    name: 'timeout',
    description: 'Timeout value in ms.',
    alias: 't',
    type: Number,
    typeLabel: '{underline ms}'
  }
]

const sections = [
  {
    header: 'Soviet Union',
    content: {
      options: {
        columns: [
          { name: 'one', maxWidth: 40 },
          { name: 'two', width: 40, noWrap: true }
        ]
      },
      data: [
        {
          one: "At the beginning of World War II, Stalin signed a non-aggression pact with Hitler's Germany; the treaty delayed confrontation between the two countries.\n\nIn June 1941 the Germans invaded, opening the largest and bloodiest theater of war in history. Soviet war casualties accounted for the highest proportion of the conflict in the cost of acquiring the upper hand over Axis forces at intense battles such as Stalingrad. Soviet forces eventually captured Berlin in 1945.\n\nThe territory overtaken by the Red Army became satellite states of the Eastern Bloc. The Cold War emerged in 1947 as the Soviet bloc confronted the Western states that united in the North Atlantic Treaty Organization in 1949.",
          two: ussr
        }
      ]
    }
  },
  {
    header: 'Synopsis',
    content: [
      '$ example [{bold --timeout} {underline ms}] {bold --src} {underline file} ...',
      '$ example {bold --help}'
    ]
  },
  {
    header: 'Options',
    optionList: optionDefinitions
  }
]

console.log(getUsage(sections))

Output

usage