@trenskow/arguments-parser 0.3.132 → 0.3.134

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.
package/index.js CHANGED
@@ -86,4 +86,4 @@ if (process.argv[2] === '_completion') {
86
86
 
87
87
  }
88
88
 
89
- export default autocomplete(process.env.AUTOCOMPLETE) || argumentsParser;
89
+ export default typeof process.env.AUTOCOMPLETE_INDEX !== 'undefined' ? autocomplete() : argumentsParser;
@@ -66,9 +66,11 @@ const bash = (items) => {
66
66
  bash.script = ({
67
67
  command
68
68
  }) => `_${command}() {
69
- eval "$(AUTOCOMPLETE=bash AUTOCOMPLETE_CURRENT=$COMP_CWORD ${command} "\${COMP_WORDS[@]}")"
69
+ eval "$(AUTOCOMPLETE_INDEX=$COMP_CWORD ${command} "\${COMP_WORDS[@]}")"
70
70
  }
71
71
 
72
72
  complete -F _${command} ${command}`;
73
73
 
74
+ bash.autocompleteIndexOffset = 1;
75
+
74
76
  export default bash;
@@ -27,14 +27,12 @@ const supported = {
27
27
 
28
28
  const currentShell = basename(process.env.SHELL || '');
29
29
 
30
- const argumentsParser = (shell) => {
30
+ const argumentsParser = () => {
31
31
 
32
- if (typeof shell === 'undefined') return;
33
-
34
- const writer = supported[shell || currentShell];
32
+ const writer = supported[currentShell];
35
33
 
36
34
  if (!writer) {
37
- process.stderr.write(`Unsupported shell: ${shell}\n`);
35
+ process.stderr.write(`Unsupported shell: ${currentShell}\n`);
38
36
  process.exit(1);
39
37
  }
40
38
 
@@ -98,11 +96,14 @@ const argumentsParser = (shell) => {
98
96
  data: {},
99
97
  validationOptions: {}
100
98
  },
101
- parameters = {},
102
- autocompleteIndex = (process.env.AUTOCOMPLETE_INDEX || 2) - 2
99
+ parameters = {}
103
100
  } = {}
104
101
  ) => {
105
102
 
103
+ let autocompleteIndex = process.env.AUTOCOMPLETE_INDEX;
104
+
105
+ autocompleteIndex = parseInt(autocompleteIndex) - argvLevel - writer.autocompleteIndexOffset;
106
+
106
107
  const base = `${process.argv.slice(1, argvLevel + 2).map(((arg) => basename(arg))).join(' ')}`;
107
108
 
108
109
  const next = async (identifier, command) => {
@@ -60,9 +60,11 @@ zsh.script = ({
60
60
  }) => `#compdef ${command}
61
61
 
62
62
  _${command}() {
63
- eval "$(AUTOCOMPLETE=zsh AUTOCOMPLETE_CURRENT=$CURRENT ${command} "\${words[@]}")"
63
+ eval "$(AUTOCOMPLETE_INDEX=$CURRENT ${command} "\${words[@]}")"
64
64
  }
65
65
 
66
66
  _${command}`;
67
67
 
68
+ zsh.autocompleteIndexOffset = 2;
69
+
68
70
  export default zsh;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trenskow/arguments-parser",
3
- "version": "0.3.132",
3
+ "version": "0.3.134",
4
4
  "description": "Yet another arguments parser.",
5
5
  "main": "index.js",
6
6
  "type": "module",