Clipanion

website·Indexed 34 days ago

https://mael.dev/typanion/

A type-safe CLI framework for Node.js that provides type inference for declared options, reducing duplicated types and improving tooling integration. It features support for command inheritance via ES6 classes, custom error handling, and built-in help functionality.

Tokens
9.5K
Snippets
79
Records
98
Agent score
71%

What's inside Clipanion

  1. Overview of Typanion runtime validation

    Typanion is a library designed for runtime data validation that integrates directly with the type system. It uses a set of composable operators to describe data structures, from which it automatically derives both validation protocols and type hints.
  2. Overview of Cascading Predicates in Typion

    Cascading predicates are used to assert that a value follows a particular pattern. Unlike other predicates, they do not contribute to refining the value type. They are typically composed using the cascade function.
  3. Typanion feature capabilities and optimization

    Typanion is a lightweight validation library that supports error messages, data coercions, and utilities beyond basic JSON validation. It utilizes a functional approach, making it highly tree-shakeable and easily optimized by modern JavaScript bundlers.
  4. Organize a Secret Santa exchange via web application

    Secret Santa is a low-effort web application for setting up Secret Santa exchanges. It allows users to generate participant links without requiring registration or sharing email addresses with third-party services.
  5. Leverage type inference and safety in Clipanion

    Clipanion provides automatic type inference for declared options, eliminating the need to manually write and synchronize duplicate type definitions. It unifies commands into a state machine to reduce bugs and enable command overloads.
  6. Use Magic Bin to manage live processes via a daemon

    Magic Bin is a CLI application that allows developers to manage live processes through a live daemon. It is particularly useful for describing development environments to spawn all required services simultaneously.
  7. Build TypeScript CLI applications with Clipanion

    Clipanion is a framework for building CLI applications with full TypeScript coverage while maintaining idiomatic syntax. It provides the comprehensive CLI features necessary to support large-scale Node CLI applications, such as Yarn.
  8. Use Typanion for TypeScript type inference

    Typanion provides strong type inference for data validation. When a validator function successfully passes, TypeScript automatically refines the values to the expected types, ensuring type safety throughout the application.
  9. Use Typanion for runtime and server-side validation

    Typanion is a companion library designed for runtime validation. While initially built for Clipanion, it functions independently for tasks such as server-side validation. It provides strong TypeScript integration using standard JavaScript syntax.
  10. Add a global help command to a Clipanion CLI

    To provide a built-in help command that lists all available documented commands, register the Builtins.HelpCommand within your Cli instance.
    import { Cli, Builtins } from 'clipanion';
    
    const cli = new Cli({
      binaryName: 'my-app',
      binaryLabel: 'My Application',
      binaryVersion: '1.0.0',
    });
    
    cli.register(Builtins.HelpCommand);
  11. Define command paths for hierarchical CLI structures

    By default, Clipanion mounts commands as top-level. To create a CLI application with subcommands (e.g., my-cli install), use the static paths property on the command class. A path is a list of fixed strings that must appear in the command line for that command to be selected. You can provide multiple path options by passing an array of arrays.
    import { Command } from 'clipanion';
    
    class InstallCommand extends Command {
      // This command triggers on 'install' or 'i'
      static paths = [['install'], ['i']];
    
      async execute() {
        // ...
      }
    }