@tkeron/commands 0.0.1 → 0.1.0

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/changelog.md ADDED
@@ -0,0 +1,4 @@
1
+ # v0.1.0
2
+
3
+ - passes positioned arguments to the callback in the second parameter.
4
+
package/dist/index.d.ts CHANGED
@@ -2,14 +2,18 @@ export interface CommandHandler {
2
2
  name: string;
3
3
  aliases: string[];
4
4
  options: string[];
5
- callback: CallableFunction;
5
+ callback: Callback;
6
6
  }
7
+ export type Options = {
8
+ [key: string]: CommandHandler;
9
+ };
10
+ export type Callback = (options: Options, orderedArguments?: string[]) => void;
7
11
  export interface Command {
8
12
  name: string;
9
13
  next: () => Commands;
10
14
  addAliases: (...alias: string[]) => Command;
11
15
  addOptions: (...options: string[]) => Command;
12
- setCallback: (callback: CallableFunction) => Command;
16
+ setCallback: (callback: Callback) => Command;
13
17
  }
14
18
  export interface Commands {
15
19
  addCommand: (commandName: string) => Command;
package/dist/index.js CHANGED
@@ -12,6 +12,11 @@ const run = () => {
12
12
  p[k] = v;
13
13
  return p;
14
14
  }, {});
15
+ const orderedArguments = currentCommands?.filter((c) => !/[:=-]/g.test(c));
16
+ if (orderedArguments &&
17
+ orderedArguments.length &&
18
+ Object.keys(_commands).includes(orderedArguments[0]))
19
+ orderedArguments.shift();
15
20
  for (const commandIndex of currentCommands) {
16
21
  const command = _commands[commandIndex];
17
22
  if (!command)
@@ -22,7 +27,7 @@ const run = () => {
22
27
  return p;
23
28
  }, {})
24
29
  : {};
25
- command.callback(options);
30
+ command.callback(options, orderedArguments);
26
31
  }
27
32
  };
28
33
  const getCommands = () => {
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@tkeron/commands",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "node library for handling command line arguments",
5
- "main": "dist/exports.js",
5
+ "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "build": "tsc",
8
8
  "test": "jest --roots dist --detectOpenHandles --coverage --verbose "
@@ -22,6 +22,6 @@
22
22
  "arguments"
23
23
  ],
24
24
  "repository": {
25
- "url": "git@github.com:tkeron/tkeron.git"
25
+ "url": "git@github.com:tkeron/tkeron.git"
26
26
  }
27
27
  }