This project provides a canonical JSON schema for defining Command-Line Interfaces (CLIs) in a declarative YAML format. The goal is to establish a universal standard for CLIs, enabling automation, consistency, and a better developer experience. The core of the project is a JSON schema that defines the structure of the CLI, and a validation library to check YAML files against this schema.
The main technologies used are:
- Node.js: The runtime environment for the project.
- JSON Schema: Used to define the structure of the CLI definition files.
- YAML: The format for writing the declarative CLI definitions.
- Ajv: A fast JSON schema validator.
- Jest: The testing framework.
- Commander.js: A library for building command-line interfaces in Node.js.
- ESLint and Prettier: For code linting and formatting.
The core cli.schema.json is publicly available via a CDN at https://cdn.jsdelivr.net/npm/cli-schema@3.0.0/schema/cli.schema.json. This public availability enables powerful integrations, particularly for IDEs. By including a special comment in YAML definition files, users can leverage:
- Autocompletion: Suggestions for command, argument, and option properties as they type.
- Real-time Validation: Instant feedback on structural errors or non-conformant values.
- Contextual Documentation: Hover-over descriptions for schema properties directly in the editor.
This is achieved by adding a directive like # yaml-language-server: $schema=https://cdn.jsdelivr.net/npm/cli-schema@3.0.0/schema/cli.schema.json to the top of YAML files.
To install the project dependencies, run:
npm installThe main CLI tool can be run with the following command:
npm startYou can also use the npx command to run the CLI and validate a file:
npx cli-schema path/to/your/file.ymlTo run the test suite, use the following command:
npm testTo check the code for linting errors, run:
npm run lintTo automatically fix linting errors, run:
npm run lint:fixTo format the code using Prettier, run:
npm run format- Code Style: The project uses Prettier for automatic code formatting and ESLint for enforcing code style and quality.
- Testing: Tests are written using the Jest framework and are located in the
testdirectory. - Contributions: Contributions are welcome. Please refer to the
CONTRIBUTING.mdfile for guidelines. - Project Structure: The project follows a standard Node.js project structure:
bin: Contains the executable script for the CLI.src: Contains the main source code for the validation library.schema: Contains the JSON schema for the CLI definitions.test: Contains the tests for the project.examples: Contains example YAML definition files.