@trenskow/arguments-parser 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.js +15 -8
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -12,7 +12,7 @@ import caseit from '@trenskow/caseit';
12
12
  import { default as isvalid, keyPaths, formalize } from 'isvalid';
13
13
  import print from '@trenskow/print';
14
14
 
15
- const argumentsParser = ({ args = process.argv.slice(2), argvLevel = 0, placeholder = '<>' }) => {
15
+ const argumentsParser = ({ args = process.argv.slice(2), argvLevel = 0, placeholder = '<>', command } = {}) => {
16
16
 
17
17
  const [ opening, closing ] = placeholder.split('');
18
18
 
@@ -75,10 +75,15 @@ const argumentsParser = ({ args = process.argv.slice(2), argvLevel = 0, placehol
75
75
 
76
76
  try {
77
77
 
78
- args = args.slice(1);
79
- argvLevel++;
80
-
81
- return await commands[tool]({ args, argumentsParser: argumentsParser({ args, argvLevel, placeholder }) });
78
+ return await commands[tool]({
79
+ args: args.slice(1),
80
+ argumentsParser: argumentsParser({
81
+ args: args.slice(1),
82
+ argvLevel: argvLevel + 1,
83
+ placeholder,
84
+ command: commands[tool]
85
+ })
86
+ });
82
87
 
83
88
  } catch (error) {
84
89
  print.err(`${error.stack}`);
@@ -86,7 +91,9 @@ const argumentsParser = ({ args = process.argv.slice(2), argvLevel = 0, placehol
86
91
  }
87
92
 
88
93
  },
89
- options: async (schema, options = {}) => {
94
+ options: async (schema, options = { }) => {
95
+
96
+ options.command = options.command || command;
90
97
 
91
98
  schema = formalize(schema, {
92
99
  plugins: [() => ({
@@ -115,9 +122,9 @@ const argumentsParser = ({ args = process.argv.slice(2), argvLevel = 0, placehol
115
122
 
116
123
  const printHelp = (error) => {
117
124
 
118
- if (typeof options?.cmd?.description === 'string') {
125
+ if (typeof options?.command?.description === 'string') {
119
126
  print();
120
- print(options.cmd.description);
127
+ print(options.command.description);
121
128
  }
122
129
 
123
130
  print();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/arguments-parser",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Yet another arguments parser.",
5
5
  "main": "index.js",
6
6
  "type": "module",