### Example of CLI Flags (Shell) Source: https://github.com/privatenumber/cleye/blob/master/README.md This shell command illustrates the basic syntax for passing flags (options) to a script. It demonstrates two common formats: `--flag-name value` and `--flag-name=value`, both assigning a value to a named flag. ```sh $ my-script --file-a data.json --file-b=file.txt ``` -------------------------------- ### Installing Cleye CLI Tool (Bash) Source: https://github.com/privatenumber/cleye/blob/master/README.md This command installs the `cleye` package from npm, making it available for use in Node.js projects. It's the first step to integrate `cleye` into your development environment. ```Bash npm i cleye ``` -------------------------------- ### Defining CLI Commands with Cleye (TypeScript) Source: https://github.com/privatenumber/cleye/blob/master/README.md This snippet illustrates how to define and register commands in a Cleye application. It uses the `command` function to create an 'install' command with specific parameters and flags, then registers it within the `cli` configuration's `commands` array. It also shows how to access the parsed command name and its parameters from the `argv` object. ```ts import { cli, command } from 'cleye' const argv = cli({ name: 'npm', version: '1.2.3', commands: [ command({ // Command name name: 'install', parameters: [''], flags: { noSave: Boolean, saveDev: Boolean } }) ] }) // $ npm install lodash argv.command // => "install" (string) argv._.packageName // => "lodash" (string) ``` -------------------------------- ### Customizing Help Document Rendering in Cleye (TypeScript) Source: https://github.com/privatenumber/cleye/blob/master/README.md This example demonstrates how to customize the help document rendering in Cleye by modifying the `nodes` array and extending `renderers`. It adds a custom sentence at the end of the document and changes the flag operator from a space to an equals sign (`=`) for flag examples, enhancing the CLI's help output. ```ts cli({ // ..., help: { render(nodes, renderers) { /* Modify nodes... */ // Add some text at end of document nodes.push('\nCheckout Cleye: https://github.com/privatenumber/cleye') /* Extend renderers... */ // Make all flag examples use `=` as the separator renderers.flagOperator = () => '=' /* Render nodes and return help */ return renderers.render(nodes) } } }) ``` -------------------------------- ### Defining a CLI with Parameters and Flags using Cleye (TypeScript) Source: https://github.com/privatenumber/cleye/blob/master/README.md This example demonstrates how to define a command-line interface using `cleye`. It parses command-line arguments, defines required and optional parameters (``, `[last name]`), and a typed flag (`--time`). The script then uses these parsed values to generate a personalized greeting message. ```TypeScript import { cli } from 'cleye' // Parse argv const argv = cli({ name: 'greet.js', // Define parameters parameters: [ '', // First name is required '[last name]' // Last name is optional ], // Define flags/options flags: { // Parses `--time` as a string time: { type: String, description: 'Time of day to greet (morning or evening)', default: 'morning' } } }) const name = [argv._.firstName, argv._.lastName].filter(Boolean).join(' ') if (argv.flags.time === 'morning') { console.log(`Good morning ${name}!`) } else { console.log(`Good evening ${name}!`) } ``` -------------------------------- ### Illustrating End-of-Flags with npm run (Shell) Source: https://github.com/privatenumber/cleye/blob/master/README.md This example demonstrates the common use case of the end-of-flags marker (`--`) in shell commands, specifically with `npm run`. The `--` separates arguments intended for the script being run from those intended for `npm` itself, allowing for distinct parsing contexts. ```sh $ npm run