clipanion
Type-safe CLI library / framework with no runtime dependencies
Last updated 10 months ago by arcanis .
MIT · Repository · Original npm · Tarball · package.json
$ gnpm install clipanion 
SYNC missed versions from official npm registry.

Clipanion

Type-safe CLI library with no runtime dependencies

npm version Licence Yarn

Installation

yarn add clipanion

Why

  • Clipanion supports advanced typing mechanisms
  • Clipanion supports nested commands (yarn workspaces list)
  • Clipanion supports transparent option proxying without -- (for example yarn dlx eslint --fix)
  • Clipanion supports all option types you could think of (including negations, batches, ...)
  • Clipanion offers a Typanion integration for increased validation capabilities
  • Clipanion generates an optimized state machine out of your commands
  • Clipanion generates good-looking help pages out of the box
  • Clipanion offers common optional command entries out-of-the-box (e.g. version command, help command)

Clipanion is used in Yarn with great success.

Documentation

Check the website for our documentation: mael.dev/clipanion.

Migration

You can use clipanion-v3-codemod to migrate a Clipanion v2 codebase to v3.

Overview

Commands are declared by extending from the Command abstract base class, and more specifically by implementing its execute method which will then be called by Clipanion. Whatever exit code it returns will then be set as the exit code for the process:

class SuccessCommand extends Command {
    async execute() {
        return 0;
    }
}

Commands can also be exposed via one or many arbitrary paths using the paths static property:

class FooCommand extends Command {
    static paths = [[`foo`]];
    async execute() {
        this.context.stdout.write(`Foo\n`);
    }
}

class BarCommand extends Command {
    static paths = [[`bar`]];
    async execute() {
        this.context.stdout.write(`Bar\n`);
    }
}

Options are defined as regular class properties, annotated by the helpers provided in the Option namespace. If you use TypeScript, all property types will then be properly inferred with no extra work required:

class HelloCommand extends Command {
    // Positional option
    name = Option.String();

    async execute() {
        this.context.stdout.write(`Hello ${this.name}!\n`);
    }
}

Option arguments can be validated and coerced using the Typanion library:

class AddCommand extends Command {
    a = Option.String({required: true, validator: t.isNumber()});
    b = Option.String({required: true, validator: t.isNumber()});

    async execute() {
        this.context.stdout.write(`${this.a + this.b}\n`);
    }
}

License (MIT)

Copyright © 2019 Mael Nison

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Current Tags

  • 4.0.0-rc.3                                ...           latest (10 months ago)

83 Versions

  • 4.0.0-rc.3                                ...           10 months ago
  • 4.0.0-rc.2                                ...           a year ago
  • 4.0.0-rc.1                                ...           a year ago
  • 3.2.1                                ...           a year ago
  • 3.2.0                                ...           2 years ago
  • 3.2.0-rc.16                                ...           2 years ago
  • 3.2.0-rc.15                                ...           2 years ago
  • 3.2.0-rc.14                                ...           2 years ago
  • 3.2.0-rc.13                                ...           2 years ago
  • 3.2.0-rc.12                                ...           2 years ago
  • 3.2.0-rc.11                                ...           3 years ago
  • 3.2.0-rc.10                                ...           3 years ago
  • 3.2.0-rc.9                                ...           3 years ago
  • 3.2.0-rc.8                                ...           3 years ago
  • 3.2.0-rc.7                                ...           3 years ago
  • 3.2.0-rc.6                                ...           3 years ago
  • 3.2.0-rc.5                                ...           3 years ago
  • 3.2.0-rc.4                                ...           3 years ago
  • 3.2.0-rc.3                                ...           3 years ago
  • 3.2.0-rc.2                                ...           3 years ago
  • 3.2.0-rc.1                                ...           3 years ago
  • 3.1.0                                ...           3 years ago
  • 3.0.1                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 3.0.0-rc.12                                ...           4 years ago
  • 3.0.0-rc.11                                ...           4 years ago
  • 3.0.0-rc.10                                ...           4 years ago
  • 3.0.0-rc.9                                ...           4 years ago
  • 3.0.0-rc.8                                ...           4 years ago
  • 3.0.0-rc.7                                ...           4 years ago
  • 3.0.0-rc.6                                ...           4 years ago
  • 3.0.0-rc.5                                ...           4 years ago
  • 3.0.0-rc.4                                ...           4 years ago
  • 3.0.0-rc.3                                ...           4 years ago
  • 3.0.0-rc.2                                ...           4 years ago
  • 3.0.0-rc.1                                ...           4 years ago
  • 2.6.2                                ...           4 years ago
  • 2.6.1                                ...           4 years ago
  • 2.6.0                                ...           4 years ago
  • 2.5.0                                ...           4 years ago
  • 2.4.4                                ...           4 years ago
  • 2.4.3                                ...           4 years ago
  • 2.4.2                                ...           4 years ago
  • 2.4.1                                ...           4 years ago
  • 2.4.0                                ...           5 years ago
  • 2.3.1                                ...           5 years ago
  • 2.3.0                                ...           5 years ago
  • 2.2.2                                ...           5 years ago
  • 2.2.1                                ...           5 years ago
  • 2.1.6                                ...           5 years ago
  • 2.1.5                                ...           5 years ago
  • 2.1.4                                ...           5 years ago
  • 2.1.3                                ...           5 years ago
  • 2.1.2                                ...           5 years ago
  • 2.1.1                                ...           5 years ago
  • 2.1.0                                ...           5 years ago
  • 2.0.1                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 2.0.0-rc.16                                ...           5 years ago
  • 2.0.0-rc.15                                ...           5 years ago
  • 2.0.0-rc.14                                ...           5 years ago
  • 2.0.0-rc.13                                ...           5 years ago
  • 2.0.0-rc.12                                ...           5 years ago
  • 2.0.0-rc.11                                ...           5 years ago
  • 2.0.0-rc.10                                ...           5 years ago
  • 2.0.0-rc.9                                ...           5 years ago
  • 2.0.0-rc.8                                ...           5 years ago
  • 2.0.0-rc.6                                ...           5 years ago
  • 2.0.0-rc.5                                ...           5 years ago
  • 2.0.0-rc.4                                ...           5 years ago
  • 2.0.0-rc.3                                ...           5 years ago
  • 2.0.0-rc.2                                ...           5 years ago
  • 2.0.0-rc.1                                ...           5 years ago
  • 2.0.0-rc.0                                ...           5 years ago
  • 0.17.1                                ...           5 years ago
  • 0.17.0                                ...           5 years ago
  • 0.16.1                                ...           5 years ago
  • 0.16.0                                ...           5 years ago
  • 0.15.0                                ...           6 years ago
  • 0.14.1                                ...           6 years ago
  • 0.14.0                                ...           6 years ago
  • 0.13.1                                ...           6 years ago
  • 0.13.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (22)

Copyright 2013 - present © cnpmjs.org | Home |