### Format Help Text String with argsclopts (JavaScript) Source: https://github.com/bcomnes/argsclopts/blob/master/README.md This snippet shows how to use `formatHelpText` from 'argsclopts' to generate the help text as a string without printing it directly to the console. It requires an `options` object with flag definitions and their corresponding `help` descriptions. A `pkgPath` can be provided to automatically determine the package name and version, or these can be supplied manually. Custom header, footer, or example functions can also be provided. ```javascript import { formatHelpText } from 'argsclopts' import { join } from 'node:path' /** * @typedef {import('argsclopts').ArgscloptsParseArgsOptionsConfig} ArgscloptsParseArgsOptionsConfig */ const pkgPath = join(import.meta.dirname, 'package.json') /** @type {ArgscloptsParseArgsOptionsConfig} */ const options = { foo: { type: 'boolean', short: 'f', help: 'A foo flag thats a boolean' }, bar: { type: 'string', help: 'A bar flag thats a string' } } const helpText = formatHelpText({ options, pkgPath }) console.log(helpText) /* Usage: argsclopts [options] Example: argsclopts --foo, -f A foo flag thats a boolean --bar A bar flag thats a string argsclopts (v1.0.0) */ ``` -------------------------------- ### Generate CLI Header Section with argsclopts Source: https://context7.com/bcomnes/argsclopts/llms.txt Creates the header section for CLI help text, including the usage line and an example. It can use default formatting based on package.json or accept custom formatter functions for complete control over the output. The function can read package name and version from a specified package.json path or receive them explicitly. ```javascript import { header } from 'argsclopts' import { join } from 'node:path' const pkgPath = join(import.meta.dirname, 'package.json') // Using default formatting const defaultHeader = await header({ pkgPath }) console.log(defaultHeader) /* Usage: my-app [options] Example: my-app */ // Using custom formatter functions const customHeader = await header({ name: 'my-tool', headerFn: ({ name }) => `${name} - A custom CLI tool\n`, exampleFn: ({ name }) => ` Examples:\n ${name} --input file.txt\n ${name} -i file.txt -o output.txt\n` }) console.log(customHeader) /* my-tool - A custom CLI tool Examples: my-tool --input file.txt my-tool -i file.txt -o output.txt */ ``` -------------------------------- ### Generate and Print Help Text with argsclopts (JavaScript) Source: https://github.com/bcomnes/argsclopts/blob/master/README.md This snippet demonstrates how to use `printHelpText` from 'argsclopts' to generate and display command-line help information. It requires an `options` object defining flags and their help messages, and optionally a `pkgPath` to resolve package name and version. The output includes usage instructions and flag descriptions. ```javascript import { printHelpText } from 'argsclopts' import { join } from 'node:path' import { parseArgs } from 'node:util' /** * @typedef {import('argsclopts').ArgscloptsParseArgsOptionsConfig} ArgscloptsParseArgsOptionsConfig */ const pkgPath = join(import.meta.dirname, 'package.json') /** @type {ArgscloptsParseArgsOptionsConfig} */ const options = { foo: { type: 'boolean', short: 'f', help: 'A foo flag thats a boolean' }, bar: { type: 'string', help: 'A bar flag thats a string' } } await printHelpText({ options, pkgPath }) /* Usage: argsclopts [options] Example: argsclopts --foo, -f A foo flag thats a boolean --bar A bar flag thats a string argsclopts (v1.0.0) */ const args = ['-f', '--bar', 'b'] const { values } = parseArgs({ args, options }) console.log(values) // { foo: true, bar: 'b' } ``` -------------------------------- ### Generate Flag Usage Documentation with argsclopts Source: https://context7.com/bcomnes/argsclopts/llms.txt Generates only the flag usage section of the help text, excluding the header and footer. This function takes an options object where each flag definition can include its description and default value. The output is a formatted string listing each flag with its short and long names, description, and default value if specified. ```javascript import { usage } from 'argsclopts' const options = { port: { type: 'string', short: 'p', help: 'Port number to listen on', default: '3000' }, host: { type: 'string', help: 'Hostname to bind to' }, debug: { type: 'boolean', short: 'd', help: 'Enable debug mode' } } const usageText = usage(options) console.log(usageText) /* --port, -p Port number to listen on (default: "3000") --host Hostname to bind to --debug, -d Enable debug mode */ ``` -------------------------------- ### Format CLI Help Text with argsclopts and node:util Source: https://context7.com/bcomnes/argsclopts/llms.txt Generates a complete, formatted help text string for a CLI application. It takes an options object similar to `node:util.parseArgs`, augmented with a `help` field for each flag. It can also accept a package.json path or explicit name/version for the header and footer. The output includes usage, flag descriptions, and package metadata. ```javascript import { formatHelpText } from 'argsclopts' import { parseArgs } from 'node:util' import { join } from 'node:path' const pkgPath = join(import.meta.dirname, 'package.json') const options = { foo: { type: 'boolean', short: 'f', help: 'A foo flag thats a boolean' }, bar: { type: 'string', help: 'A bar flag thats a string' } } const helpText = await formatHelpText({ options, pkgPath }) console.log(helpText) /* Usage: argsclopts [options] Example: argsclopts --foo, -f A foo flag thats a boolean --bar A bar flag thats a string argsclopts (v1.0.0) */ // Parse arguments using the same options object const args = ['-f', '--bar', 'b'] const { values } = parseArgs({ args, options }) console.log(values) // { foo: true, bar: 'b' } ``` -------------------------------- ### Generate Header Text with argsclopts (JavaScript) Source: https://github.com/bcomnes/argsclopts/blob/master/README.md This snippet illustrates how to generate only the header section of the help text using the `header` function from 'argsclopts'. You can provide a `pkgPath` to resolve the package name and version, or specify the `name` directly. The `headerFn` and `exampleFn` can be used to customize the generated header text. ```javascript import { header } from 'argsclopts' import { join } from 'node:path' const pkgPath = join(import.meta.dirname, 'package.json') const headerText = header({ pkgPath, exampleFn: ({ name }) => `Example: ${name} --foo bar` }) console.log(headerText) /* Usage: argsclopts [options] Example: argsclopts --foo bar */ ``` -------------------------------- ### Print CLI Help Text Directly with argsclopts Source: https://context7.com/bcomnes/argsclopts/llms.txt Prints formatted help text directly to the console without returning a string. This function is an alias for `formatHelpText` but uses `console.log` internally, making it convenient for immediate display in CLI applications. It accepts the same options object as `formatHelpText`, including flag definitions with help descriptions and optional package information. ```javascript import { printHelpText } from 'argsclopts' import { join } from 'node:path' const pkgPath = join(import.meta.dirname, 'package.json') const options = { verbose: { type: 'boolean', short: 'v', help: 'Enable verbose output' }, config: { type: 'string', short: 'c', help: 'Path to configuration file', default: './config.json' } } // Prints formatted help text directly await printHelpText({ options, pkgPath }) /* Usage: my-cli [options] Example: my-cli --verbose, -v Enable verbose output --config, -c Path to configuration file (default: "./config.json") my-cli (v2.1.0) */ ``` -------------------------------- ### Customize Flag Display with helpLabel in argsclopts Source: https://context7.com/bcomnes/argsclopts/llms.txt Allows customization of how flags are displayed in the help text, overriding the default format. Useful for providing more descriptive or structured labels. ```javascript import { usage } from 'argsclopts' const options = { input: { type: 'string', short: 'i', help: 'Input file path' }, output: { type: 'string', short: 'o', help: 'Output file path', helpLabel: '--output=, -o=' }, experimental: { type: 'boolean', help: 'Enable experimental features', helpLabel: '[EXPERIMENTAL] --experimental' } } const usageText = usage(options) console.log(usageText) /* --input, -i Input file path --output=, -o= Output file path [EXPERIMENTAL] --experimental Enable experimental features */ ``` -------------------------------- ### Generate CLI Footer with argsclopts Source: https://context7.com/bcomnes/argsclopts/llms.txt Generates the footer section for a CLI application displaying package name and version. Supports custom formatter functions for advanced customization. ```javascript import { footer } from 'argsclopts' import { join } from 'node:path' const pkgPath = join(import.meta.dirname, 'package.json') // Default footer format const defaultFooter = await footer({ pkgPath }) console.log(defaultFooter) // my-app (v1.2.3) // Custom footer with additional information const customFooter = await footer({ name: 'my-cli', version: '2.0.0', footerFn: ({ name, version }) => `\n${name} v${version}\nLicense: MIT\nRepository: https://github.com/user/my-cli` }) console.log(customFooter) /* my-cli v2.0.0 License: MIT Repository: https://github.com/user/my-cli */ // Provide explicit name and version const explicitFooter = await footer({ name: 'custom-tool', version: '3.5.1' }) console.log(explicitFooter) // custom-tool (v3.5.1) ``` -------------------------------- ### Generate Usage String with argsclopts (JavaScript) Source: https://github.com/bcomnes/argsclopts/blob/master/README.md This snippet demonstrates how to generate only the usage string portion of the help text using the `usage` function from 'argsclopts'. It takes an `options` object as input, which defines the command-line flags. This is useful when you need to construct parts of the help message separately. ```javascript import { usage } from 'argsclopts' /** * @typedef {import('argsclopts').ArgscloptsParseArgsOptionsConfig} ArgscloptsParseArgsOptionsConfig */ /** @type {ArgscloptsParseArgsOptionsConfig} */ const options = { foo: { type: 'boolean', short: 'f', help: 'A foo flag thats a boolean' }, bar: { type: 'string', help: 'A bar flag thats a string' } } const usageText = usage(options) console.log(usageText) /* Usage: [options] --foo, -f A foo flag thats a boolean --bar A bar flag thats a string */ ``` -------------------------------- ### Perform Local Release with npm Source: https://github.com/bcomnes/argsclopts/blob/master/CONTRIBUTING.md These commands are used to perform a local release if the automated process fails. It involves ensuring a clean git workspace, updating the version number and generating a changelog using 'npm version', and finally publishing the package to npm. ```shell npm version {patch,minor,major} npm publish ``` -------------------------------- ### Generate Footer Text with argsclopts (JavaScript) Source: https://github.com/bcomnes/argsclopts/blob/master/README.md This snippet demonstrates how to generate only the footer section of the help text using the `footer` function from 'argsclopts'. You can provide a `pkgPath` to resolve the package name and version, or specify them directly. The `footerFn` allows customization of the footer text template. ```javascript import { footer } from 'argsclopts' import { join } from 'node:path' const pkgPath = join(import.meta.dirname, 'package.json') const footerText = footer({ pkgPath, footerFn: ({ name, version }) => `${name} v${version} - All rights reserved.` }) console.log(footerText) /* argsclopts v1.0.0 - All rights reserved. */ ``` -------------------------------- ### Read package.json with argsclopts Source: https://context7.com/bcomnes/argsclopts/llms.txt Reads and parses a package.json file from the specified path. This utility function is used internally to extract package name and version information. ```javascript import { readPkg } from 'argsclopts' import { join } from 'node:path' const pkgPath = join(import.meta.dirname, 'package.json') try { const pkg = await readPkg(pkgPath) console.log(`Package: ${pkg.name}`) console.log(`Version: ${pkg.version}`) // Package: argsclopts // Version: 1.0.5 } catch (error) { console.error('Failed to read package.json:', error.message) } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.