mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(cloudcmd) add ability to suggest option, when wrong provided
This commit is contained in:
parent
f0fd4031bb
commit
40f885e7c4
2 changed files with 42 additions and 16 deletions
|
|
@ -6,6 +6,7 @@ import {createRequire} from 'module';
|
|||
import {promisify} from 'util';
|
||||
import tryToCatch from 'try-to-catch';
|
||||
import {createSimport} from 'simport';
|
||||
import parse from 'yargs-parser';
|
||||
|
||||
import exit from '../server/exit.js';
|
||||
import {
|
||||
|
|
@ -34,8 +35,21 @@ const require = createRequire(import.meta.url);
|
|||
|
||||
const Info = require('../package.json');
|
||||
|
||||
const {argv} = process;
|
||||
const args = require('minimist')(argv.slice(2), {
|
||||
const maybeRoot = (a) => {
|
||||
if (a === '.')
|
||||
return process.cwd();
|
||||
|
||||
return a;
|
||||
};
|
||||
|
||||
const yargsOptions = {
|
||||
configuration: {
|
||||
'strip-aliased': true,
|
||||
'strip-dashed': true,
|
||||
},
|
||||
coerce: {
|
||||
root: maybeRoot,
|
||||
},
|
||||
string: [
|
||||
'name',
|
||||
'port',
|
||||
|
|
@ -81,6 +95,7 @@ const args = require('minimist')(argv.slice(2), {
|
|||
'import',
|
||||
'import-listen',
|
||||
'log',
|
||||
'zip',
|
||||
'dropbox',
|
||||
],
|
||||
default: {
|
||||
|
|
@ -127,19 +142,19 @@ const args = require('minimist')(argv.slice(2), {
|
|||
'dropbox-token': config('dropboxToken'),
|
||||
},
|
||||
alias: {
|
||||
v: 'version',
|
||||
h: 'help',
|
||||
p: 'password',
|
||||
o: 'online',
|
||||
u: 'username',
|
||||
s: 'save',
|
||||
a: 'auth',
|
||||
c: 'config',
|
||||
version: 'v',
|
||||
help: 'h',
|
||||
password: 'p',
|
||||
online: 'o',
|
||||
username: 'u',
|
||||
save: 's',
|
||||
auth: 'a',
|
||||
config: 'c',
|
||||
},
|
||||
unknown: (cmd) => {
|
||||
exit('\'%s\' is not a cloudcmd option. See \'cloudcmd --help\'.', cmd);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const {argv} = process;
|
||||
const args = parse(argv.slice(2), yargsOptions);
|
||||
|
||||
if (args.version)
|
||||
version();
|
||||
|
|
@ -149,6 +164,16 @@ else
|
|||
main();
|
||||
|
||||
async function main() {
|
||||
const validateArgs = await simport('@putout/cli-validate-args');
|
||||
|
||||
const error = await validateArgs(args, [
|
||||
...yargsOptions.boolean,
|
||||
...yargsOptions.string,
|
||||
]);
|
||||
|
||||
if (error)
|
||||
return exit(error);
|
||||
|
||||
if (args.repl)
|
||||
repl();
|
||||
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@
|
|||
"@cloudcmd/fileop": "^5.0.0",
|
||||
"@cloudcmd/move-files": "^4.0.0",
|
||||
"@cloudcmd/read-files-sync": "^2.0.0",
|
||||
"@putout/cli-validate-args": "^1.0.1",
|
||||
"@putout/plugin-cloudcmd": "^1.2.0",
|
||||
"apart": "^2.0.0",
|
||||
"chalk": "^4.0.0",
|
||||
|
|
@ -111,7 +112,6 @@
|
|||
"just-snake-case": "^1.1.0",
|
||||
"markdown-it": "^12.0.0",
|
||||
"mellow": "^3.0.0",
|
||||
"minimist": "^1.2.0",
|
||||
"nomine": "^4.0.0",
|
||||
"object.omit": "^3.0.0",
|
||||
"once": "^1.4.0",
|
||||
|
|
@ -137,7 +137,8 @@
|
|||
"tryrequire": "^3.0.0",
|
||||
"win32": "^5.1.11",
|
||||
"wraptile": "^3.0.0",
|
||||
"writejson": "^3.0.0"
|
||||
"writejson": "^3.0.0",
|
||||
"yargs-parser": "^20.2.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/code-frame": "^7.5.5",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue