Comparing version 0.9.6 to 0.11.0
@@ -5,3 +5,2 @@ // Shell.js | ||
import Shell from "./Shell.js"; | ||
const shell = function (config) { | ||
@@ -11,4 +10,3 @@ const shell = new Shell(config); | ||
}; | ||
export { shell, Shell }; | ||
export * as utils from "./utils/index.js"; |
@@ -66,5 +66,5 @@ // Plugin "args" | ||
`the "-${shortcut}" argument is not a valid option`, | ||
Array.isArray(config.command) | ||
? `in command "${config.command.join(" ")}"` | ||
: void 0, | ||
Array.isArray(config.command) ? | ||
`in command "${config.command.join(" ")}"` | ||
: void 0, | ||
]); | ||
@@ -150,12 +150,12 @@ } | ||
const required = | ||
typeof option.required === "function" | ||
? !!option.required.call(null, { | ||
config: config, | ||
command: command, | ||
}) | ||
: !!option.required; | ||
typeof option.required === "function" ? | ||
!!option.required.call(null, { | ||
config: config, | ||
command: command, | ||
}) | ||
: !!option.required; | ||
if (required && params[option.name] == null) { | ||
throw error([ | ||
"Required Option:", | ||
`the \"${option.name}\" option must be provided`, | ||
`the "${option.name}" option must be provided`, | ||
]); | ||
@@ -174,3 +174,3 @@ } | ||
"Invalid Argument Value:", | ||
`the value of option \"${option.name}\"`, | ||
`the value of option "${option.name}"`, | ||
`must be one of ${JSON.stringify(option.enum)},`, | ||
@@ -196,3 +196,3 @@ `got ${JSON.stringify(value)}`, | ||
"Invalid Argument:", | ||
`fail to interpret all arguments \"${leftover.join(" ")}\"`, | ||
`fail to interpret all arguments "${leftover.join(" ")}"`, | ||
]); | ||
@@ -216,8 +216,8 @@ } | ||
const required = | ||
typeof main.required === "function" | ||
? !!main.required.call(null, { | ||
config: config, | ||
command: command, | ||
}) | ||
: !!main.required; | ||
typeof main.required === "function" ? | ||
!!main.required.call(null, { | ||
config: config, | ||
command: command, | ||
}) | ||
: !!main.required; | ||
if (required && params[main.name].length === 0) { | ||
@@ -298,8 +298,8 @@ throw error([ | ||
const required = | ||
typeof option.required === "function" | ||
? !!option.required.call(null, { | ||
config: config, | ||
command: undefined, | ||
}) | ||
: !!option.required; | ||
typeof option.required === "function" ? | ||
!!option.required.call(null, { | ||
config: config, | ||
command: undefined, | ||
}) | ||
: !!option.required; | ||
if (required && value == null) { | ||
@@ -320,3 +320,3 @@ throw error([ | ||
"Invalid Parameter Value:", | ||
`the value of option \"${option.name}\"`, | ||
`the value of option "${option.name}"`, | ||
`must be one of ${JSON.stringify(option.enum)},`, | ||
@@ -352,8 +352,8 @@ `got ${JSON.stringify(val)}`, | ||
const required = | ||
typeof config.main.required === "function" | ||
? !!config.main.required.call(null, { | ||
config: config, | ||
command: undefined, | ||
}) | ||
: !!config.main.required; | ||
typeof config.main.required === "function" ? | ||
!!config.main.required.call(null, { | ||
config: config, | ||
command: undefined, | ||
}) | ||
: !!config.main.required; | ||
if (required && value == null) { | ||
@@ -377,8 +377,8 @@ throw error([ | ||
// Recursive | ||
const has_child_commands = options.extended | ||
? data.length | ||
: Object.keys(config.commands).length; | ||
const has_child_commands = | ||
options.extended ? data.length : Object.keys(config.commands).length; | ||
if (has_child_commands) { | ||
const command = options.extended | ||
? data[0][appconfig.command] | ||
const command = | ||
options.extended ? | ||
data[0][appconfig.command] | ||
: data[appconfig.command].shift(); | ||
@@ -390,7 +390,7 @@ if (!config.commands[command]) { | ||
`expect one of ${JSON.stringify( | ||
Object.keys(config.commands).sort() | ||
Object.keys(config.commands).sort(), | ||
)}`, | ||
Array.isArray(config.command) | ||
? `in command ${JSON.stringify(config.command.join(" "))}` | ||
: void 0, | ||
Array.isArray(config.command) ? | ||
`in command ${JSON.stringify(config.command.join(" "))}` | ||
: void 0, | ||
]); | ||
@@ -403,3 +403,3 @@ } | ||
config.commands[command], | ||
options.extended ? data.shift() : ldata | ||
options.extended ? data.shift() : ldata, | ||
); | ||
@@ -421,3 +421,3 @@ } | ||
`the property --${key} is not a registered argument`, | ||
].join(" ") | ||
].join(" "), | ||
); | ||
@@ -424,0 +424,0 @@ } |
@@ -103,3 +103,3 @@ // Plugin "config" | ||
config.options[name], | ||
values | ||
values, | ||
)); | ||
@@ -120,5 +120,5 @@ if (!ctx._config.extended) { | ||
`collide with the one in ${ | ||
ctx.collision[name].length === 0 | ||
? "application" | ||
: JSON.stringify(ctx.collision[name].join(" ")) | ||
ctx.collision[name].length === 0 ? | ||
"application" | ||
: JSON.stringify(ctx.collision[name].join(" ")) | ||
},`, | ||
@@ -143,5 +143,5 @@ "change its name or use the extended property", | ||
`for option ${JSON.stringify(name)}`, | ||
commands.length | ||
? `in command ${JSON.stringify(commands.join(" "))}` | ||
: void 0, | ||
commands.length ? | ||
`in command ${JSON.stringify(commands.join(" "))}` | ||
: void 0, | ||
]); | ||
@@ -322,3 +322,3 @@ } | ||
`key ${JSON.stringify( | ||
config.name | ||
config.name, | ||
)} is not equal with name ${JSON.stringify(config.name)}`, | ||
@@ -325,0 +325,0 @@ ]); |
@@ -63,3 +63,3 @@ // Plugin "help" | ||
command, | ||
config.commands[command.name] | ||
config.commands[command.name], | ||
); | ||
@@ -69,4 +69,4 @@ } | ||
handler.call(this, ...arguments); | ||
return config.description != null | ||
? config.description | ||
return config.description != null ? | ||
config.description | ||
: (config.description = `No description yet for the ${config.name} command`); | ||
@@ -83,4 +83,4 @@ }; | ||
handler.call(this, ...arguments); | ||
return config.description != null | ||
? config.description | ||
return config.description != null ? | ||
config.description | ||
: (config.description = `No description yet for the ${config.name} command`); | ||
@@ -138,3 +138,3 @@ }; | ||
`parameter ${JSON.stringify( | ||
appconfig.command | ||
appconfig.command, | ||
)} must be an array in flatten mode,`, | ||
@@ -159,4 +159,5 @@ `got ${JSON.stringify(params[appconfig.command])}`, | ||
// Note, when argv equals ['help'], there is no leftover and main is null | ||
const leftover = !options.extended | ||
? params[appconfig.commands[commands[0]].main.name] | ||
const leftover = | ||
!options.extended ? | ||
params[appconfig.commands[commands[0]].main.name] | ||
: params[1][appconfig.commands[commands[0]].main.name]; | ||
@@ -254,5 +255,5 @@ if (leftover) { | ||
"Invalid Command:", | ||
`argument \"${commands | ||
`argument "${commands | ||
.slice(0, i + 1) | ||
.join(" ")}\" is not a valid command`, | ||
.join(" ")}" is not a valid command`, | ||
]); | ||
@@ -277,3 +278,3 @@ } | ||
return `${options.indent}${l}`; | ||
}) | ||
}), | ||
); | ||
@@ -327,3 +328,3 @@ } else { | ||
return `${options.indent}${l}`; | ||
}) | ||
}), | ||
); | ||
@@ -361,3 +362,3 @@ } else { | ||
return `${options.indent}${l}`; | ||
}) | ||
}), | ||
); | ||
@@ -386,3 +387,3 @@ } else { | ||
`${options.indent}${[command.name].join(" ")}`, | ||
options.columns | ||
options.columns, | ||
); | ||
@@ -403,3 +404,3 @@ if (line.length > options.columns) { | ||
content.push(""); | ||
content.push(`COMMAND \"${command.name}\"`); | ||
content.push(`COMMAND "${command.name}"`); | ||
// Raw command, no main, no child commands | ||
@@ -446,4 +447,4 @@ if ( | ||
`${options.indent}Where command is ${Object.keys( | ||
command.commands | ||
)}.` | ||
command.commands, | ||
)}.`, | ||
); | ||
@@ -453,4 +454,4 @@ } else if (commands.length > 1) { | ||
`${options.indent}Where command is one of ${Object.keys( | ||
command.commands | ||
).join(", ")}.` | ||
command.commands, | ||
).join(", ")}.`, | ||
); | ||
@@ -465,7 +466,7 @@ } | ||
// has_help_option = Object.values(config.options).some (option) -> option.name is 'help' | ||
const has_help_command = Object.values(config.commands).some(function ( | ||
command | ||
) { | ||
return command.name === "help"; | ||
}); | ||
const has_help_command = Object.values(config.commands).some( | ||
function (command) { | ||
return command.name === "help"; | ||
}, | ||
); | ||
const has_help_option = true; | ||
@@ -484,3 +485,3 @@ content.push(""); | ||
return `${options.indent}${l}`; | ||
}) | ||
}), | ||
); | ||
@@ -502,3 +503,3 @@ } else { | ||
return `${options.indent}${l}`; | ||
}) | ||
}), | ||
); | ||
@@ -505,0 +506,0 @@ } else { |
@@ -35,3 +35,3 @@ // Plugin "router" | ||
} | ||
if (!config.router.stdin instanceof stream.Readable) { | ||
if (!(config.router.stdin instanceof stream.Readable)) { | ||
throw error([ | ||
@@ -43,3 +43,3 @@ "Invalid Configuration Property:", | ||
} | ||
if (!config.router.stdout instanceof stream.Writable) { | ||
if (!(config.router.stdout instanceof stream.Writable)) { | ||
throw error([ | ||
@@ -51,3 +51,3 @@ "Invalid Configuration Property:", | ||
} | ||
if (!config.router.stderr instanceof stream.Writable) { | ||
if (!(config.router.stderr instanceof stream.Writable)) { | ||
throw error([ | ||
@@ -74,5 +74,5 @@ "Invalid Configuration Property:", | ||
"accept string or function", | ||
!command.length | ||
? "in application," | ||
: `in command ${JSON.stringify(command.join(" "))},`, | ||
!command.length ? "in application," : ( | ||
`in command ${JSON.stringify(command.join(" "))},` | ||
), | ||
`got ${JSON.stringify(config.handler)}`, | ||
@@ -111,3 +111,3 @@ ]); | ||
throw error( | ||
`Invalid Handler: expect a string or a function, got ${handler}` | ||
`Invalid Handler: expect a string or a function, got ${handler}`, | ||
); | ||
@@ -144,3 +144,3 @@ } | ||
} | ||
return new Promise(function (resolve, reject) { | ||
return new Promise(function (resolve) { | ||
return resolve(result); | ||
@@ -175,4 +175,5 @@ }); | ||
// Object.keys(config.commands).length or | ||
err = config.root | ||
? error([ | ||
err = | ||
config.root ? | ||
error([ | ||
"Missing Application Handler:", | ||
@@ -183,4 +184,4 @@ 'a "handler" definition is required when no child command is defined', | ||
"Missing Command Handler:", | ||
`a \"handler\" definition ${JSON.stringify( | ||
params[appconfig.command] | ||
`a "handler" definition ${JSON.stringify( | ||
params[appconfig.command], | ||
)} is required when no child command is defined`, | ||
@@ -207,3 +208,3 @@ ]); | ||
`Fail to load route. Message is: ${err.message}`, | ||
command | ||
command, | ||
); | ||
@@ -218,3 +219,3 @@ }); | ||
`Fail to load route. Message is: ${err.message}`, | ||
command | ||
command, | ||
); | ||
@@ -258,6 +259,7 @@ throw err; | ||
// command = (for i in [0...params.length] then params[i][appconfig.command]) if appconfig.extended | ||
command = []; | ||
for (const param in params) { | ||
command.push[appconfig.command]; | ||
} | ||
// command = []; | ||
// for (const param in params) { | ||
// command.push[appconfig.command]; | ||
// } | ||
console.warn("TODO"); | ||
} | ||
@@ -264,0 +266,0 @@ const config = this.config(command).get(); |
@@ -46,3 +46,3 @@ // Shell.js Core object | ||
`got ${JSON.stringify(module)}`, | ||
].join(" ") | ||
].join(" "), | ||
); | ||
@@ -56,3 +56,3 @@ } | ||
const loader = await load( | ||
this._config.load /* `, this._config.load.namespace` */ | ||
this._config.load /* `, this._config.load.namespace` */, | ||
); | ||
@@ -59,0 +59,0 @@ return loader(module, namespace); |
@@ -22,4 +22,4 @@ import { mutate, is_object_literal } from "mixme"; | ||
`Invalid Error Argument: expect an object literal, got ${JSON.stringify( | ||
arg | ||
)}.` | ||
arg, | ||
)}.`, | ||
); | ||
@@ -26,0 +26,0 @@ } |
{ | ||
"name": "shell", | ||
"version": "0.9.6", | ||
"version": "0.11.0", | ||
"description": "Command line arguments parser and stringifier", | ||
"keywords": [ | ||
"shell", | ||
"cli", | ||
"arguments", | ||
"parser", | ||
"parameters", | ||
"param", | ||
"option", | ||
"command", | ||
"bash", | ||
"sh", | ||
"getopt" | ||
], | ||
"author": "David Worms <david@adaltas.com> (https://www.adaltas.com)", | ||
"coffeelintConfig": { | ||
"indentation": { | ||
"level": "error", | ||
"value": 2 | ||
}, | ||
"line_endings": { | ||
"level": "error", | ||
"value": "unix" | ||
}, | ||
"max_line_length": { | ||
"level": "ignore" | ||
} | ||
"bugs": { | ||
"email": "open@adaltas.com", | ||
"url": "https://github.com/adaltas/node-shell/issues" | ||
}, | ||
@@ -27,9 +32,15 @@ "contributors": [ | ||
"devDependencies": { | ||
"@eslint/js": "^9.8.0", | ||
"coffeescript": "^2.7.0", | ||
"mocha": "^10.4.0", | ||
"rollup": "^4.18.0", | ||
"dedent": "^1.5.3", | ||
"eslint": "^9.8.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-mocha": "^10.4.3", | ||
"eslint-plugin-prettier": "^5.2.1", | ||
"mocha": "^10.7.0", | ||
"prettier": "^3.3.3", | ||
"rollup": "^4.19.1", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"should": "^13.2.3" | ||
}, | ||
"description": "Command line arguments parser and stringifier", | ||
"engines": { | ||
@@ -53,16 +64,7 @@ "node": ">= 0.10.x" | ||
"homepage": "https://shell.js.org", | ||
"keywords": [ | ||
"shell", | ||
"cli", | ||
"arguments", | ||
"parser", | ||
"parameters", | ||
"param", | ||
"option", | ||
"command", | ||
"bash", | ||
"sh", | ||
"getopt" | ||
], | ||
"license": "MIT", | ||
"lint-staged": { | ||
"*.js": "npm run lint:fix", | ||
"*.md": "prettier -w" | ||
}, | ||
"main": "./lib/index", | ||
@@ -90,8 +92,11 @@ "mocha": { | ||
"build": "npx rollup -c", | ||
"lint:check": "npx eslint", | ||
"lint:fix": "npx eslint --fix", | ||
"lint:staged": "npx lint-staged", | ||
"preversion": "yarn run test", | ||
"pretest": "npm run build", | ||
"test": "mocha 'test/**/*.coffee'" | ||
"test": "mocha 'test/**/*.coffee' 'test/**/*.js'" | ||
}, | ||
"type": "module", | ||
"gitHead": "e7c5da13b6bb9bae719d07f493f0008b2d5b1cc8" | ||
"gitHead": "f5e3cbf1d9673dd84d2e11ab8b0b40f0427a1b35" | ||
} |
@@ -0,6 +1,52 @@ | ||
# Shell.js argument parser and router for Node.js | ||
# Package `shell` | ||
This project demonstrates the usage of the Shell library for creating command-line tools that parse arguments and route function calls based on those arguments. The Shell library uses a declarative syntax and allows you to build powerful and user-friendly command-line interfaces in Node.js. | ||
Core engine available as the `shell` package. | ||
Please start the [tutorial](https://shell.js.org/usage/tutorial/) and refer to the [project website](https://shell.js.org/) to access the documentation. | ||
Please refer to the [project website](https://shell.js.org/) to access the documentation. | ||
## Features | ||
- Reversibility, argument parser and stringifier | ||
- Auto-discovery, extract unregistered options | ||
- Standard and commands-based command lines (eg `git pull ...`) | ||
- Unlimited/multi level commands (eg `myapp server start ...`) | ||
- Type conversion ('string', 'boolean', 'integer', 'array') | ||
- Object literals, config and parsed results are serializable and human readable | ||
- Routing, run asynchronous functions or modules based on user commands | ||
- Auto-generated help | ||
- Complete tests coverages and samples | ||
## Prerequisites | ||
- Node.js (version 20 or later) | ||
- A Node Package Manager | ||
## Installation | ||
To use Shell.js in your project, you need to install it. | ||
```sh | ||
npm install shell | ||
``` | ||
The package export the `shell` function. | ||
```js | ||
import { shell } from "shell"; | ||
shell({ | ||
name: "myapp", | ||
description: "My CLI application", | ||
options: { | ||
config: { | ||
shortcut: "c", | ||
description: "Some option", | ||
}, | ||
}, | ||
commands: { | ||
start: { | ||
description: "Start something", | ||
}, | ||
}, | ||
}).route(); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
160151
5064
0
53
12