diff --git a/.editorconfig b/.editorconfig
index 1b0b5e1..16849e0 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,22 +1,24 @@
-# http://editorconfig.org
+# https://editorconfig.org
root = true
-[*.js]
+[*.{css,less,scss,js,html,jshtml,md}]
indent_style = tab
+end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
-[*.md]
-indent_style = tab
+[*.{json,rb,yaml,yml}]
+indent_style = space
+indent_size = 2
+end_of_line = lf
charset = utf-8
-trim_trailing_whitespace = false
+trim_trailing_whitespace = true
insert_final_newline = true
-[{.editorconfig,.eslintrc.yaml,.gitignore,.npmignore,.sublimelinterrc,.travis.yml,package.json}]
-indent_style = space
-indent_size = 2
+[{.editorconfig,.gitignore,.npmignore}]
+end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
diff --git a/index.js b/index.js
index 25d49a0..dd4b491 100644
--- a/index.js
+++ b/index.js
@@ -246,9 +246,30 @@ module.exports = class Cli {
}
//-- Accept only this flag
- static acceptOnlyFlag(meowCli, flag) {
- if (Object.keys(meowCli.flags).length === 1 && meowCli.flags[flag]) {
- return meowCli.flags[flag];
+ static acceptOnlyFlag(meowCli, allowedFlag) {
+ const result = this.acceptOnlyFlags(meowCli, [allowedFlag]);
+
+ if (typeof result === 'object') {
+ return result[allowedFlag] || false;
+ }
+
+ return result;
+ }
+
+ //-- Accept only these flags
+ static acceptOnlyFlags(meowCli, allowedFlags) {
+ const inputFlags = Object.keys(meowCli.flags);
+
+ if (inputFlags.length <= allowedFlags.length) {
+ const areFlagsValid = inputFlags.every((flag) => {
+ return allowedFlags.includes(flag);
+ });
+
+ if (areFlagsValid) {
+ return meowCli.flags;
+ }
+
+ this.showTaskUsage(meowCli);
} else if (Object.keys(meowCli.flags).length !== 0) {
this.showTaskUsage(meowCli);
diff --git a/license b/license
index 183eefe..a499a25 100644
--- a/license
+++ b/license
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2011-2018 Absolunet, http://absolunet.com
+Copyright (c) 2011-2018 Absolunet, https://absolunet.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/package.json b/package.json
index 593623a..5aa6d2b 100644
--- a/package.json
+++ b/package.json
@@ -1,12 +1,12 @@
{
"name": "@absolunet/cli",
- "version": "0.5.1",
+ "version": "0.6.0",
"description": "CLI utilities",
"definition": "",
"homepage": "https://github.com/absolunet/node-cli",
"author": {
"name": "Absolunet",
- "url": "http://absolunet.com/"
+ "url": "https://absolunet.com"
},
"license": "MIT",
"repository": {
@@ -17,22 +17,22 @@
"url": "https://github.com/absolunet/node-cli/issues"
},
"engines": {
- "node": ">= 9.8.0"
+ "node": ">= 10.5.0"
},
"scripts": {
"test": "ava test"
},
"devDependencies": {
- "@absolunet/tester": "1.4.0"
+ "@absolunet/tester": "1.7.1"
},
"dependencies": {
- "@absolunet/terminal": "^0.4.4",
+ "@absolunet/terminal": "^0.5.0",
"@absolunet/terminal-pad": "^0.0.2",
- "chalk": "^2.3.2",
+ "chalk": "^2.4.1",
"glob": "^7.1.2",
"indent-string": "^3.2.0",
- "omelette": "^0.4.5",
- "read-pkg-up": "^3.0.0",
+ "omelette": "^0.4.11",
+ "read-pkg-up": "^4.0.0",
"string-width": "^2.1.1"
}
}
diff --git a/readme.md b/readme.md
index d4b1755..96157c1 100644
--- a/readme.md
+++ b/readme.md
@@ -1,9 +1,10 @@
# @absolunet/cli
-[![NPM version](https://img.shields.io/npm/v/@absolunet/cli.svg)](https://www.npmjs.com/package/@absolunet/cli)
-[![Travis build](https://api.travis-ci.org/absolunet/node-cli.svg?branch=master)](https://travis-ci.org/absolunet/node-cli/builds)
-[![Dependencies](https://david-dm.org/absolunet/node-cli/status.svg)](https://david-dm.org/absolunet/node-cli)
-[![Dev dependencies](https://david-dm.org/absolunet/node-cli/dev-status.svg)](https://david-dm.org/absolunet/node-cli?type=dev)
+[![npm](https://img.shields.io/npm/v/@absolunet/cli.svg)](https://www.npmjs.com/package/@absolunet/cli)
+[![npm dependencies](https://david-dm.org/absolunet/node-cli/status.svg)](https://david-dm.org/absolunet/node-cli)
+[![npms](https://badges.npms.io/%40absolunet%2Fcli.svg)](https://npms.io/search?q=%40absolunet%2Fcli)
+[![Travis CI](https://api.travis-ci.org/absolunet/node-cli.svg?branch=master)](https://travis-ci.org/absolunet/node-cli/builds)
+[![Code style ESLint](https://img.shields.io/badge/code_style-@absolunet/node-659d32.svg)](https://github.com/absolunet/eslint-config-node)
> CLI utilities
@@ -280,6 +281,7 @@ meow object
### `acceptOnlyFlag(meowCli, flag)`
Show task usage and quit if CLI call has flags that are not whitelisted
+Return flag value
#### meowCli
*Required*
@@ -294,6 +296,25 @@ Whitelisted flag
+
+
+### `acceptOnlyFlags(meowCli, flag)`
+Show task usage and quit if CLI call has flags that are not whitelisted
+Return `object` of flags values
+
+#### meowCli
+*Required*
+Type: `object`
+meow object
+
+#### refuseFlagsAndArguments
+*Required*
+Type: `array` of `string`
+Whitelisted flags
+
+
+
+
### `isRoot()`
diff --git a/test/index.js b/test/index.js
index 658f932..2e4510b 100644
--- a/test/index.js
+++ b/test/index.js
@@ -6,3 +6,5 @@
const tester = require('@absolunet/tester');
tester.lintJs();
+tester.lintJson();
+tester.lintYaml();