Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

command-line-publish

brettz972MIT1.1.0

Convert command-line-usage JSON or JavaScript ESM into HTML or SVG files

argv, parse, argument, args, option, options, cli, command, line, docs, documentation, command-line-args, command-line-usage

readme

command-line-publish

Tool to convert command-line-args/command-line-usage JSON arrays to SVG or HTML.

Install

npm install -D command-line-publish

CLI Usage

command-line-publish <args>

or:

clp --format=html --config="jsWithSectionsExport.js" "cli.html"
clp --format=svg --config="jsonWithSectionsProperty.json" "cli.svg"

And here is the documentation generated by our use of command-line-publish on itself.

First as HTML:

And then as embeddable SVG (not copy-pasteable on the README, but it is if you click the image or visit the file directly):

cli.svg

After using the commands to generate, you can:

  • Link to the HTML, e.g., as we did above: [cli.html](https://brettz9.github.io/command-line-publish/cli.html)
  • Embed the SVG, e.g., as we did above: ![cli.svg](https://brettz9.github.io/command-line-publish/cli.svg) (If you are not on Github Pages, you may, in the case of SVG, also use the form: ![cli.svg](https://raw.githubusercontent.com/brettz9/command-line-publish/master/cli.svg?sanitize=true) (Applying for HTML will only show the raw source.))

Note that we have configured this repository's master branch to have its contents served from Github Pages.

Programmatic usage

import {html, svg} from 'command-line-publish';

// This JavaScript (or JSON) file must export a `sections` property,
//  and for easier reusability, it is recommended that ths same file
//  define a `definitions` property for use by `command-line-args`
import {sections} from './path/to/config-file.js';

// The options objects are optional
svg(sections, {target: 'cli.svg', ansiToSvgOptions: {}});
html(sections, {target: 'cli.html', ansiToHtmlOptions: {}});

Here is a sampling of our own config file:

import {readFile} from 'fs/promises';

const pkg = JSON.parse(
  await readFile(new URL('../package.json', import.meta.url))
);

const optionDefinitions = [
  {
    name: 'target', alias: 't', type: String, defaultOption: true,
    description: 'The file path target to which to write the result',
    typeLabel: '{underline file-path}'
  },
  // ... snipped
  {
    name: 'help', alias: 'h', type: Boolean,
    description: 'Display this help guide'
  }
];

const cliSections = [
  {
    // We're now actually letting `command-line-basics auto-generate the
    //  `header` now
    header: pkg.name,
    // Add italics: `{italic textToItalicize}`
    content: pkg.description +
      '\n\n{italic clp -c="configPath" [--format=svg|html] target}'
  },
  {
    // We're now actually letting `command-line-basics auto-generate the
    //  `header` now
    header: 'Options',
    optionList: optionDefinitions
  }
];

export {optionDefinitions as definitions, cliSections as sections};

See also

changelog

CHANGES for command-line-publish

1.1.0

  • Enhancement: Allow supplying of title (currently HTML only), defaulting to "CLI Docs"
  • Fix: Avoid copy-paste error producing "Git Utilities CLI docs"

1.0.0

User-facing

  • Breaking change: Require Node 14+
  • Breaking enhancement: Native ESM
  • npm: Update command-line-basics (major), command-line-usage (patch)

Dev-facing

  • npm: Update devDeps.
  • npm: Avoid reusing version script
  • npm: Switch to pnpm
  • Linting: As per latest
  • npm: Add build-cli script

0.7.0

  • npm: Update dep. command-line basics; update devDeps.

0.6.1

  • Fix: Was misslabeling export type as "json"; fixed to be "svg"
  • Docs: Show how to get SVG link to be copy-pasteable (and make ours so)

0.6.0

  • npm: Lower package.json's engines to 10.0.0 as experimental fs.promises seems to still work ok.
  • npm: Update devDeps

0.5.0

  • npm: Update deps and devDeps

0.4.1

  • Fix: backslash escaping

0.4.0

  • npm: Update command-line-basics

0.3.0

  • npm: Update command-line-basics

0.2.0

  • Refactor: Use pkg.name for header (better reusability across projects)
  • Refactor: Use external command-line-basics for help, version, notifier

0.1.0

  • Initial version