author / shell Goto Github PK
View Code? Open in Web Editor NEWA very lightweight framework for building shell/CLI applications. Works in Node.js, Deno, and the browser.
License: MIT License
A very lightweight framework for building shell/CLI applications. Works in Node.js, Deno, and the browser.
License: MIT License
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.
I could use some help cleaning up the docs. These were written pretty quickly and there are clearly some errors and typos.
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.
How to use a shell command to run "ls -l" and also "mkdir test" for node
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 » |
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.
Consider adding a plugin capable of generating documentation in Markdown format (JSON is already supported).
Can u show me an example of using a shell command in raw html for browser?
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.
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.
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 upignore
: 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 » |
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.