Coder Social home page Coder Social logo

author / shell Goto Github PK

View Code? Open in Web Editor NEW
74.0 74.0 9.0 459 KB

A very lightweight framework for building shell/CLI applications. Works in Node.js, Deno, and the browser.

License: MIT License

JavaScript 100.00%
browser cli cli-applications command-line deno executable javascript javascriptnodejs middleware shell web

shell's People

Contributors

coreybutler avatar gbdrummer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

shell's Issues

Add useExcept middleware

Having a useExcept() method (similar to useWith) would help simplify configurations.

The main use case is when all commands except one (or a small minority) require the same middleware. As new commands are created, it becomes increasingly burdensome to modify middleware without this.

Tagged Commands

As I've used this library to build applications, I've recognized a need for experimental commands, beta commands, and even hidden commands (hidden from help).

It would be nice to have a "tag" or some other identifier to identify which commands are experimental, which should be hidden, etc.

One possible implementation is:

new Command({
  name: 'cmd',
  tags: ['beta'],
  async handler () {...}
})

Special tags may have special documentation/help features:

  • hidden: available, but does not show up
  • ignore: completely ignore the command (won't run)
  • experimental: prefixes description with EXPERIMENTAL.
  • deprecated: prefixes description with DEPRECATED.

Tags should be exposed to command handlers and directly through the shell, making it possible for developers to create custom functionality for tagged commands.

Please use the reactions to cast a vote in favor of or against this feature suggestion »

Single Package

Instead of requiring users to choose node-shell or browser-shell, it would be better to have a single cross-runtime module.

Note to self: Use the same strategy from NGN to make this happen.

2022-02-10: Return values for exec command

Is your feature request related to a problem? Please describe.
I often find myself wanting to be able to return a value when I run a command.

Describe the solution you'd like
Right now, I have to pass in a callback function to do this:

shell.exec('my-command', value => {...})

It would be nice to be able to do this:

const value = await shell.exec('my-command')

...doStuffWithValue...

This would allow me to simply return a value from my command handler function without having to fire a callback.

Please use the reactions to cast a vote in favor of or against this feature suggestion »

Flag/Argument Transformations

I want a transformer to process arguments/flags passed to the CLI utility. For example:

my cmd -i ./local/path
flags: {
  input: {
    alias: 'i',
    description: 'The input source directory.',
    type: 'string',
    transform (value) {
      return path.resolve(value)
    }
  }
}

In the case above, the resulting "input" flag would have a value of /users/cbutler/local/path instead of ./local/path because the transformer modifies the data before it is used within a command.

This could be used for sanitizing inputs of any kind, or normalizing data (such as case sensitivity, typos, etc). It would be better to do this where the flag is defined, instead of requiring each and every command handler to do this. Currently, middleware is the only way to handle this, but that's less intuitive than a transformer.

Middleware order of operations

Issue:
Middleware assigned to the shell is executing after middleware assigned to specific commands.

How To Reproduce:

let status = []
const cmd = new Command({
  name: 'run',
  async handler(meta) {
    return meta.input
  }
})

cmd.use(async function(meta, next) {
  status.push('2')
  next()
})

const sh = new Shell({
  name: 'test',
  use: [
    (meta, next) => {
      status.push('1')
      next()
    }
  ],
  commands: [cmd]
})

sh.exec(['run', 'other'])

Expected Behavior:
The value of status should be 1,2, but is actually 2,1.

Middleware should be executed according to the hierarchy of the command, i.e.:

graph LR
sh[1. shell middleware]
c[2. command middleware]
s[3. subcommand middleware]

sh-->c
c-->s

It currently runs in the opposite order.

Add universal/common flag "exception" list

Similar to issue #3, sometimes there are "nearly universal" flags. In other words, there are flags which apply to all but one or two commands within a shell. Having an option to ignore a set of common flag attributes or exclude them from being applied to a command would reduce configuration footprints and simplify maintenance of shells.

Documentation Cleanup

I could use some help cleaning up the docs. These were written pretty quickly and there are clearly some errors and typos.

Generate Documentation

Consider adding a plugin capable of generating documentation in Markdown format (JSON is already supported).

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.