Giter VIP home page Giter VIP logo

ts-cli's Introduction

@jill64/ts-cli

npm-version npm-license npm-download-month npm-min-size ci.yml

> Solidly-Typed CLI Router

Installation

npm i @jill64/ts-cli

Example

import { App } from '@jill64/ts-cli'

new App(
  {
    args: [
      ['arg1', 'Argument 1'],
      ['arg2', 'Argument 2'],
      ['arg3', 'Argument 3']
    ],
    options: {
      verbose: {
        alias: 'V',
        description: 'Verbose output'
      },
      host: {
        alias: 'h',
        description: 'Host name',
        type: 'string'
      }
    },
    optional: [
      ['optional-1', 'Optional Argument 1'],
      ['optional-2', 'Optional Argument 2'],
      ['optional-3', 'Optional Argument 3']
    ],
    rest: {
      placeholder: 'rest-argument',
      description: 'Rest Argument'
    },
    codes: {
      0: success,
      1: failure
    }
  },
  ({ args, options, optional, rest }) => {
    // `<command> <arg1> <arg2> <arg3> [options] [optional1?] [optional2?] [optional3?] <...rest>`

    options.verbose // boolean
    options.host // string

    // Allow 0 or 1 or void
    return 0
  }
)

Add Route (Subcommands)

The add function defines a route.

import { App } from '@jill64/ts-cli'

new App(/* ... */)
  .add(
    'test',
    {
      // Config
    },
    () => {
      // `<command> test`
      // ...
    }
  )
  .add(
    'test start',
    {
      // Config
    },
    () => {
      // `<command> test start`
      // ...
    }
  )

Run as Command

The run function executes the command immediately using process.argv.

import { App } from '@jill64/ts-cli'
import process from 'node:process'

new App(/* ... */).run(process.argv)

Export as API

// index.js
import { App } from '@jill64/ts-cli'

export const command = new App(/* ... */).add(/* ... */).add(/* ... */)
import { command } from 'index.js'

// `example`
command.execute({
  args: {
    arg1: 'value1',
    arg2: 'value2',
    arg3: 'value3'
  },
  optional: {
    'optional-1': 'optional-value1',
    'optional-2': 'optional-value2',
    'optional-3': 'optional-value3'
  },
  // or
  // rest: ['rest1', 'rest2', 'rest3'],
  options: {
    verbose: true,
    host: 'example.com'
  }
})

// `example test`
command.invoke.test({
  // ...
})

// `example test start`
command.invoke['test start']({
  // ...
})

License

MIT

ts-cli's People

Contributors

wraith-ci[bot] avatar renovate[bot] avatar jill64 avatar

Stargazers

Jrson avatar

Watchers

 avatar

ts-cli's Issues

Sanctuary

Detected Project Issues

Performance

  • No specific performance issues detected from the provided files.

Reliability

  • The project uses strict TypeScript configuration for improved reliability.

Maintenance

  • Dependencies are pinned, which can lead to easier maintenance but may increase the effort needed to update dependencies.
  • The project uses GitHub Actions for continuous integration, which helps ensure code quality and reliability.

Security

  • No specific security issues detected from the provided files. It's recommended to regularly audit dependencies for security vulnerabilities.

Documentation

  • The README provides basic documentation on installation, usage, and examples, which is good for getting started quickly.
  • The project could benefit from more detailed documentation regarding its API and configuration options for advanced usage.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • jill64/.github main
npm
package.json
  • @jill64/transform 1.0.3
  • @jill64/eslint-config-ts 1.1.27
  • @jill64/prettier-config 1.0.0
  • @types/node 20.14.8
  • typescript 5.5.2
  • vitest 1.6.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.