https://github.com/author/shell-middleware
Common middleware for shell applications (Browser & Node.js runtimes)
https://github.com/author/shell-middleware
Last synced: 3 months ago
JSON representation
Common middleware for shell applications (Browser & Node.js runtimes)
- Host: GitHub
- URL: https://github.com/author/shell-middleware
- Owner: author
- License: mit
- Created: 2020-02-29T16:07:53.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-29T17:16:23.000Z (over 6 years ago)
- Last Synced: 2025-02-19T18:18:20.302Z (over 1 year ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# shell-middleware
Common middleware for [@author.io/shell](https://github.com/author.shell) CLI applications (Browser & Node.js runtimes).
**To Use:**
|Runtime |Example |
|---------|---------|
| Node.js | _Install:_ `npm install @author.io/shell-middleware -S`
_Usage:_ `import { ValidInput } from '@author.io/shell-middleware'` |
| Browser | `import { ValidInput } from 'https://cdn.pika.dev/@author.io/shell-middleware@latest'` |
## Capabilities
This library contains a collection of commonly used middleware methods for use with a shell app.
```javascript
import { Shell } from 'https://cdn.pika.dev/@author.io/shell@latest'
// Import this library...
import { MiddlewareA, MiddlewareB } from 'https://cdn.pika.dev/@author.io/shell-middleware@latest'
// Simple shell
const shell = new Shell({
name: 'my-cli'
})
shell.use() // <----- Apply middleware.
...
```
### ValidInput
This method enforces flag processing rules (see [@author.io/arg](https://github.com/author/arg) for options). For example, this method will recognize failure to specify a required flag by displaying a violation notice. All further processing is aborted.
```javascript
import { ValidInput } from '...@author.io/shell-middleware@latest'
shell.use(ValidInput)
```
### ValidInputWithHelp
This is nearly identical to **ValidInput**, except it will _also display the default help message_.
```javascript
import { ValidInputWithHelp } from '...@author.io/shell-middleware@latest'
shell.use(ValidInputWithHelp)
```
### Log
Log the original command. This is a pass-thru method, so processing will continue.
```javascript
import { Log } from '...@author.io/shell-middleware@latest'
shell.use(Log)
```