@nu-art/commando 0.204.87 → 0.204.88

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 (47) hide show
  1. package/cli/basic.d.ts +3 -2
  2. package/cli/basic.js +15 -15
  3. package/cli/git.d.ts +18 -17
  4. package/cli/git.js +43 -22
  5. package/cli/nvm.d.ts +4 -3
  6. package/cli/nvm.js +13 -10
  7. package/cli/pnpm.d.ts +1 -1
  8. package/cli/pnpm.js +8 -8
  9. package/cli/programming.d.ts +3 -2
  10. package/cli/programming.js +19 -19
  11. package/cli-params/CLIParamsResolver.d.ts +27 -0
  12. package/{cli/cli-params.js → cli-params/CLIParamsResolver.js} +6 -34
  13. package/cli-params/consts.d.ts +6 -0
  14. package/cli-params/consts.js +32 -0
  15. package/cli-params/types.d.ts +27 -0
  16. package/cli-params/types.js +2 -0
  17. package/package.json +1 -1
  18. package/shell/core/BaseCommando.d.ts +54 -0
  19. package/shell/core/BaseCommando.js +73 -0
  20. package/shell/core/CliError.d.ts +15 -0
  21. package/shell/core/CliError.js +22 -0
  22. package/shell/core/CommandBuilder.d.ts +52 -0
  23. package/shell/core/CommandBuilder.js +78 -0
  24. package/shell/core/class-merger.d.ts +20 -0
  25. package/{core → shell/core}/class-merger.js +16 -0
  26. package/shell/index.d.ts +2 -0
  27. package/shell/index.js +18 -0
  28. package/shell/interactive/CommandoInteractive.d.ts +83 -0
  29. package/shell/interactive/CommandoInteractive.js +180 -0
  30. package/shell/interactive/InteractiveShell.d.ts +63 -0
  31. package/shell/interactive/InteractiveShell.js +139 -0
  32. package/shell/simple/Commando.d.ts +17 -0
  33. package/shell/simple/Commando.js +51 -0
  34. package/shell/simple/SimpleShell.d.ts +23 -0
  35. package/shell/simple/SimpleShell.js +48 -0
  36. package/shell/types.d.ts +3 -0
  37. package/shell/types.js +2 -0
  38. package/cli/cli-params.d.ts +0 -56
  39. package/core/CliError.d.ts +0 -6
  40. package/core/CliError.js +0 -12
  41. package/core/class-merger.d.ts +0 -5
  42. package/core/cli.d.ts +0 -147
  43. package/core/cli.js +0 -404
  44. package/test-scripts/test-params.d.ts +0 -1
  45. package/test-scripts/test-params.js +0 -43
  46. /package/{core → shell}/tools.d.ts +0 -0
  47. /package/{core → shell}/tools.js +0 -0
package/cli/basic.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { CliBlock, CliWrapper } from '../core/cli';
1
+ import { BaseCommando } from '../shell/core/BaseCommando';
2
+ import { CliBlock } from '../shell/types';
2
3
  type Cli_EchoOptions = {
3
4
  escape?: boolean;
4
5
  toFile?: {
@@ -16,7 +17,7 @@ type Cli_CpdirOptions = {
16
17
  /**
17
18
  * Represents a Command Line Interface (CLI) to build and execute shell commands.
18
19
  */
19
- export declare class Cli_Basic extends CliWrapper {
20
+ export declare class Cli_Basic extends BaseCommando {
20
21
  /**
21
22
  * Changes directory and optionally executes a block of commands in that directory.
22
23
  * @param {string} folderName - Name of the directory to change to.
package/cli/basic.js CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Cli_Basic = void 0;
4
- const cli_1 = require("../core/cli");
4
+ const BaseCommando_1 = require("../shell/core/BaseCommando");
5
5
  /**
6
6
  * Represents a Command Line Interface (CLI) to build and execute shell commands.
7
7
  */
8
- class Cli_Basic extends cli_1.CliWrapper {
8
+ class Cli_Basic extends BaseCommando_1.BaseCommando {
9
9
  /**
10
10
  * Changes directory and optionally executes a block of commands in that directory.
11
11
  * @param {string} folderName - Name of the directory to change to.
@@ -13,8 +13,8 @@ class Cli_Basic extends cli_1.CliWrapper {
13
13
  * @returns {this} - The Cli instance for method chaining.
14
14
  */
15
15
  cd(folderName, toRun) {
16
- this.cli.append(`cd ${folderName}`);
17
- this.cli.indentIn();
16
+ this.append(`cd ${folderName}`);
17
+ this.indentIn();
18
18
  if (toRun) {
19
19
  toRun(this);
20
20
  this.cd_();
@@ -22,7 +22,7 @@ class Cli_Basic extends cli_1.CliWrapper {
22
22
  return this;
23
23
  }
24
24
  custom(command) {
25
- this.cli.append(command);
25
+ this.append(command);
26
26
  return this;
27
27
  }
28
28
  /**
@@ -30,8 +30,8 @@ class Cli_Basic extends cli_1.CliWrapper {
30
30
  * @returns {this} - The Cli instance for method chaining.
31
31
  */
32
32
  cd_() {
33
- this.cli.indentOut();
34
- this.cli.append(`cd -`);
33
+ this.indentOut();
34
+ this.append(`cd -`);
35
35
  return this;
36
36
  }
37
37
  /**
@@ -40,11 +40,11 @@ class Cli_Basic extends cli_1.CliWrapper {
40
40
  * @returns {this} - The Cli instance for method chaining.
41
41
  */
42
42
  ls(params = '') {
43
- this.cli.append(`ls ${params}`);
43
+ this.append(`ls ${params}`);
44
44
  return this;
45
45
  }
46
46
  mkdir(dirName) {
47
- this.cli.append(`mkdir -p ${dirName}`);
47
+ this.append(`mkdir -p ${dirName}`);
48
48
  return this;
49
49
  }
50
50
  rmdir(dirPath, options) {
@@ -53,7 +53,7 @@ class Cli_Basic extends cli_1.CliWrapper {
53
53
  command += ' -rf';
54
54
  if (options === null || options === void 0 ? void 0 : options.recursive)
55
55
  command += ' -r';
56
- this.cli.append(`${command} ${dirPath}`);
56
+ this.append(`${command} ${dirPath}`);
57
57
  return this;
58
58
  }
59
59
  cpdir(srcPath, destPath, options) {
@@ -61,18 +61,18 @@ class Cli_Basic extends cli_1.CliWrapper {
61
61
  if (options === null || options === void 0 ? void 0 : options.contentOnly)
62
62
  command += '/*';
63
63
  command += ` ${destPath}`;
64
- this.cli.append(command);
64
+ this.append(command);
65
65
  return this;
66
66
  }
67
67
  cat(fileName) {
68
- this.cli.append(`cat ${fileName}`);
68
+ this.append(`cat ${fileName}`);
69
69
  return this;
70
70
  }
71
71
  echo(log, options) {
72
72
  const _escape = (options === null || options === void 0 ? void 0 : options.escape) ? '-e' : '';
73
73
  const _toFile = (options === null || options === void 0 ? void 0 : options.toFile) ? `>${options.toFile.append ? '>' : ''} ${options.toFile.name}` : '';
74
74
  const escapedLog = log.replace(/\\/g, '\\\\').replace(/\n/g, '\\\\n').replace(/\t/g, '\\\t');
75
- this.cli.append(`echo ${_escape} "${escapedLog}" ${_toFile}`);
75
+ this.append(`echo ${_escape} "${escapedLog}" ${_toFile}`);
76
76
  return this;
77
77
  }
78
78
  /**
@@ -80,7 +80,7 @@ class Cli_Basic extends cli_1.CliWrapper {
80
80
  * @returns {this} - The Cli instance for method chaining.
81
81
  */
82
82
  pwd() {
83
- this.cli.append('pwd');
83
+ this.append('pwd');
84
84
  return this;
85
85
  }
86
86
  /**
@@ -90,7 +90,7 @@ class Cli_Basic extends cli_1.CliWrapper {
90
90
  * @returns {this} - The Cli instance for method chaining.
91
91
  */
92
92
  assignVar(varName, value) {
93
- this.cli.append(`${varName}=(${Array.isArray(value) ? value : [value].join(' ')})`);
93
+ this.append(`${varName}=(${Array.isArray(value) ? value : [value].join(' ')})`);
94
94
  return this;
95
95
  }
96
96
  }
package/cli/git.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Cli_Programming } from './programming';
2
2
  import { Cli_Basic } from './basic';
3
- declare const Super: new (...args: any[]) => Cli_Programming & Cli_Basic;
3
+ import { BaseCommando } from '../shell/core/BaseCommando';
4
+ declare const Super: import("@nu-art/ts-common").Constructor<BaseCommando & Cli_Programming & Cli_Basic>;
4
5
  type GitCloneParams = {
5
6
  outputFolder?: string;
6
7
  branch?: string;
@@ -15,22 +16,22 @@ type GitPushParams = {
15
16
  export declare class Cli_Git extends Super {
16
17
  git: {
17
18
  clone: (url: string, options?: GitCloneParams) => this;
18
- checkout: (branch: string) => Cli_Git;
19
- createTag: (tagName: string) => Cli_Git;
20
- gitCommit: (commitMessage: string) => Cli_Git;
21
- add: (file: string) => Cli_Git;
22
- addAll: () => Cli_Git;
23
- addAndCommit: (commitMessage: string) => Cli_Git;
24
- push: (options?: GitPushParams) => Cli_Git;
25
- pushTags: () => Cli_Git;
26
- fetch: () => Cli_Git;
27
- resetHard: (tag?: string) => Cli_Git;
28
- getCurrentBranch: () => Cli_Git;
29
- pull: (params: string) => Cli_Git;
30
- merge: (mergeFrom: string) => Cli_Git;
31
- createBranch: (branch: string) => Cli_Git;
32
- gsui: (modules?: string) => Cli_Git;
33
- status: () => Cli_Git;
19
+ checkout: (branch: string) => this;
20
+ createTag: (tagName: string) => this;
21
+ gitCommit: (commitMessage: string) => this;
22
+ add: (file: string) => this;
23
+ addAll: () => this;
24
+ addAndCommit: (commitMessage: string) => this;
25
+ push: (options?: GitPushParams) => this;
26
+ pushTags: () => this;
27
+ fetch: () => this;
28
+ resetHard: (tag?: string) => this;
29
+ getCurrentBranch: () => this;
30
+ pull: (params: string) => this;
31
+ merge: (mergeFrom: string) => this;
32
+ createBranch: (branch: string) => this;
33
+ gsui: (modules?: string) => this;
34
+ status: () => this;
34
35
  };
35
36
  git_clone(url: string, options?: GitCloneParams): this;
36
37
  private git_checkout;
package/cli/git.js CHANGED
@@ -2,9 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Cli_Git = void 0;
4
4
  const programming_1 = require("./programming");
5
- const class_merger_1 = require("../core/class-merger");
6
5
  const basic_1 = require("./basic");
7
- const Super = (0, class_merger_1.MergeClass)(programming_1.Cli_Programming, basic_1.Cli_Basic);
6
+ const class_merger_1 = require("../shell/core/class-merger");
7
+ const BaseCommando_1 = require("../shell/core/BaseCommando");
8
+ const Super = (0, class_merger_1.MergeClass)(BaseCommando_1.BaseCommando, programming_1.Cli_Programming, basic_1.Cli_Basic);
8
9
  class Cli_Git extends Super {
9
10
  constructor() {
10
11
  super(...arguments);
@@ -32,72 +33,92 @@ class Cli_Git extends Super {
32
33
  const branch = `${(options === null || options === void 0 ? void 0 : options.branch) ? ` -b ${options === null || options === void 0 ? void 0 : options.branch}` : ''}`;
33
34
  const recursive = `${(options === null || options === void 0 ? void 0 : options.recursive) ? ` --recursive` : ''}`;
34
35
  const outputFolder = `${(options === null || options === void 0 ? void 0 : options.outputFolder) ? ` ${options.outputFolder}` : ''}`;
35
- this.cli.append(`git clone${recursive}${branch} ${url}${outputFolder}`);
36
- return this;
37
- }
36
+ const command = `git clone${recursive}${branch} ${url}${outputFolder}`;
37
+ this.append(command);
38
+ return this;
39
+ }
40
+ // git_cloneAssert(url: string, options?: GitCloneParams) {
41
+ // return new Promise<void>((resolve, reject) => {
42
+ // const branch = `${options?.branch ? ` -b ${options?.branch}` : ''}`;
43
+ // const recursive = `${options?.recursive ? ` --recursive` : ''}`;
44
+ // const outputFolder = `${options?.outputFolder ? ` ${options.outputFolder}` : ''}`;
45
+ // const command = `git clone${recursive}${branch} ${url}${outputFolder}`;
46
+ // this.echo(command);
47
+ // this.append(command)
48
+ // .execute((stdout: string, stderr: string, exitCode: number) => {
49
+ // if (exitCode === 0)
50
+ // return resolve();
51
+ //
52
+ // if (exitCode === 128)
53
+ // return reject(new Error(`No access to repo: ${url}`));
54
+ //
55
+ // return reject(new Error(`Got unexpected exit code(${exitCode}) while cloning: ${url}`));
56
+ // });
57
+ // });
58
+ // }
38
59
  git_checkout(branch) {
39
- this.cli.append(`git checkout ${branch}`);
60
+ this.append(`git checkout ${branch}`);
40
61
  return this;
41
62
  }
42
63
  git_createTag(tagName) {
43
- this.cli.append(`git tag -f ${tagName}`);
64
+ this.append(`git tag -f ${tagName}`);
44
65
  return this;
45
66
  }
46
67
  git_gitCommit(commitMessage) {
47
- this.cli.append(`git commit -m "${commitMessage}"`);
68
+ this.append(`git commit -m "${commitMessage}"`);
48
69
  return this;
49
70
  }
50
71
  git_add(file) {
51
- this.cli.append(`git add "${file}"`);
72
+ this.append(`git add "${file}"`);
52
73
  return this;
53
74
  }
54
75
  git_addAll() {
55
- this.cli.append(`git add .`);
76
+ this.append(`git add .`);
56
77
  return this;
57
78
  }
58
79
  git_addAndCommit(commitMessage) {
59
- this.cli.append(`git commit -am "${commitMessage}"`);
80
+ this.append(`git commit -am "${commitMessage}"`);
60
81
  return this;
61
82
  }
62
83
  git_push(options) {
63
- this.cli.append(`git push ${options === null || options === void 0 ? void 0 : options.remote} ${options === null || options === void 0 ? void 0 : options.branch}`);
84
+ this.append(`git push ${options === null || options === void 0 ? void 0 : options.remote} ${options === null || options === void 0 ? void 0 : options.branch}`);
64
85
  return this;
65
86
  }
66
87
  git_pushTags() {
67
- this.cli.append('git push --tags --force');
88
+ this.append('git push --tags --force');
68
89
  return this;
69
90
  }
70
91
  git_fetch() {
71
- this.cli.append('git fetch');
92
+ this.append('git fetch');
72
93
  return this;
73
94
  }
74
95
  git_resetHard(tag = '') {
75
- this.cli.append('git reset --hard ${tag}');
96
+ this.append('git reset --hard ${tag}');
76
97
  return this;
77
98
  }
78
99
  git_getCurrentBranch() {
79
- this.cli.append('git status | grep "On branch" | sed -E "s');
100
+ this.append('git status | grep "On branch" | sed -E "s');
80
101
  return this;
81
102
  }
82
103
  git_pull(params) {
83
- this.cli.append('git pull ${params}');
104
+ this.append('git pull ${params}');
84
105
  return this;
85
106
  }
86
107
  git_merge(mergeFrom) {
87
- this.cli.append(`git merge ${mergeFrom}`);
108
+ this.append(`git merge ${mergeFrom}`);
88
109
  return this;
89
110
  }
90
111
  git_createBranch(branch) {
91
- this.cli.append(`git checkout - b ${branch}`);
92
- this.cli.append(`git push-- set -upstream origin ${branch}`);
112
+ this.append(`git checkout - b ${branch}`);
113
+ this.append(`git push-- set -upstream origin ${branch}`);
93
114
  return this;
94
115
  }
95
116
  git_gsui(modules = '') {
96
- this.cli.append('git submodule update --recursive --init ${modules}');
117
+ this.append('git submodule update --recursive --init ${modules}');
97
118
  return this;
98
119
  }
99
120
  git_status() {
100
- this.cli.append('git status');
121
+ this.append('git status');
101
122
  return this;
102
123
  }
103
124
  }
package/cli/nvm.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { CliWrapper, Commando, CommandoInteractive } from '../core/cli';
2
1
  import { Constructor, Logger } from '@nu-art/ts-common';
2
+ import { Commando } from '../shell/simple/Commando';
3
+ import { CommandoInteractive } from '../shell/interactive/CommandoInteractive';
3
4
  export declare class Cli_NVM extends Logger {
4
5
  private _expectedVersion;
5
6
  private _homeEnvVar;
@@ -16,7 +17,7 @@ export declare class Cli_NVM extends Logger {
16
17
  private getVersion;
17
18
  uninstall: () => Promise<void>;
18
19
  private installVersion;
19
- createInteractiveCommando<T extends Constructor<CliWrapper>[]>(...plugins: T): CommandoInteractive & Commando & import("../core/class-merger").MergeTypes<T>;
20
- createCommando<T extends Constructor<CliWrapper>[]>(...plugins: T): Commando & import("../core/class-merger").MergeTypes<T>;
20
+ createInteractiveCommando<T extends Constructor<any>[]>(...plugins: T): import("../shell/core/class-merger").MergeTypes<[typeof import("../shell/core/BaseCommando").BaseCommando, typeof CommandoInteractive, ...T]> & import("../shell/core/BaseCommando").BaseCommando & CommandoInteractive;
21
+ createCommando<T extends Constructor<any>[]>(...plugins: T): import("../shell/core/class-merger").MergeTypes<[typeof import("../shell/core/BaseCommando").BaseCommando, typeof Commando, ...T]> & import("../shell/core/BaseCommando").BaseCommando & Commando;
21
22
  }
22
23
  export declare const NVM: Cli_NVM;
package/cli/nvm.js CHANGED
@@ -26,12 +26,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.NVM = exports.Cli_NVM = void 0;
27
27
  const programming_1 = require("./programming");
28
28
  const basic_1 = require("./basic");
29
- const cli_1 = require("../core/cli");
30
29
  const fs = __importStar(require("fs"));
31
30
  const fs_1 = require("fs");
32
31
  const path = __importStar(require("path"));
33
- const tools_1 = require("../core/tools");
34
32
  const ts_common_1 = require("@nu-art/ts-common");
33
+ const Commando_1 = require("../shell/simple/Commando");
34
+ const tools_1 = require("../shell/tools");
35
+ const CommandoInteractive_1 = require("../shell/interactive/CommandoInteractive");
35
36
  const CONST__FILE_NVMRC = '.nvmrc';
36
37
  class Cli_NVM extends ts_common_1.Logger {
37
38
  constructor() {
@@ -40,12 +41,12 @@ class Cli_NVM extends ts_common_1.Logger {
40
41
  this._homeEnvVar = '$NVM_DIR';
41
42
  this.install = async () => {
42
43
  if (this.isInstalled()) {
43
- const version = (await this.getVersion()).stdout.trim();
44
+ const version = (await this.getVersion()).trim();
44
45
  if (this._expectedVersion === version)
45
46
  return;
46
47
  await this.uninstall();
47
48
  }
48
- await cli_1.Commando.create()
49
+ await Commando_1.Commando.create()
49
50
  .append(` curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/v${this._expectedVersion}/install.sh" | bash`)
50
51
  .execute();
51
52
  const rcFile = path.resolve(process.env['HOME'], '.bashrc');
@@ -91,7 +92,7 @@ class Cli_NVM extends ts_common_1.Logger {
91
92
  }
92
93
  return extractInstalledVersions((await this.createCommando()
93
94
  .append('nvm ls')
94
- .execute()).stdout);
95
+ .execute((stdout) => stdout)));
95
96
  };
96
97
  this.uninstall = async () => {
97
98
  this.logDebug('Uninstalling PNPM');
@@ -120,22 +121,24 @@ class Cli_NVM extends ts_common_1.Logger {
120
121
  this._expectedVersion = value;
121
122
  }
122
123
  async getVersion() {
123
- const commando = cli_1.Commando.create(programming_1.Cli_Programming, basic_1.Cli_Basic);
124
+ const commando = Commando_1.Commando.create(programming_1.Cli_Programming, basic_1.Cli_Basic);
124
125
  return commando.if('[[ -x "$(command -v nvm)" ]]', (commando) => {
125
- commando.cli.append('nvm --version');
126
- }).execute();
126
+ commando.append('nvm --version');
127
+ }).execute((stdout) => stdout);
127
128
  }
128
129
  createInteractiveCommando(...plugins) {
129
- return cli_1.CommandoInteractive.create(...plugins).debug()
130
+ return CommandoInteractive_1.CommandoInteractive.create(...plugins)
130
131
  .append('export NVM_DIR="$HOME/.nvm"')
131
132
  .append('[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm')
132
133
  .append('nvm use');
133
134
  }
134
135
  createCommando(...plugins) {
135
- return cli_1.Commando.create(...plugins)
136
+ const commando = Commando_1.Commando.create(...plugins);
137
+ commando
136
138
  .append('export NVM_DIR="$HOME/.nvm"')
137
139
  .append('[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm')
138
140
  .append('nvm use');
141
+ return commando;
139
142
  }
140
143
  }
141
144
  exports.Cli_NVM = Cli_NVM;
package/cli/pnpm.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Commando } from '../core/cli';
2
1
  import { Logger } from '@nu-art/ts-common';
2
+ import { Commando } from '../shell/simple/Commando';
3
3
  export declare class Cli_PNPM extends Logger {
4
4
  private _expectedVersion;
5
5
  private _homeEnvVar;
package/cli/pnpm.js CHANGED
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PNPM = exports.Cli_PNPM = void 0;
4
4
  const programming_1 = require("./programming");
5
5
  const basic_1 = require("./basic");
6
- const cli_1 = require("../core/cli");
7
6
  const fs_1 = require("fs");
8
- const tools_1 = require("../core/tools");
9
7
  const ts_common_1 = require("@nu-art/ts-common");
8
+ const Commando_1 = require("../shell/simple/Commando");
9
+ const tools_1 = require("../shell/tools");
10
10
  class Cli_PNPM extends ts_common_1.Logger {
11
11
  constructor() {
12
12
  super();
@@ -14,20 +14,20 @@ class Cli_PNPM extends ts_common_1.Logger {
14
14
  this._homeEnvVar = 'PNPM_HOME';
15
15
  this.install = async (commando) => {
16
16
  if (this.isInstalled()) {
17
- const version = (await this.getVersion()).stdout.trim();
17
+ const version = (await this.getVersion()).trim();
18
18
  if (this._expectedVersion === version)
19
19
  return;
20
20
  await this.uninstall();
21
21
  }
22
22
  this.logDebug(`installing PNPM version ${this._expectedVersion}`);
23
- await (commando !== null && commando !== void 0 ? commando : cli_1.Commando.create())
23
+ await (commando !== null && commando !== void 0 ? commando : Commando_1.Commando.create())
24
24
  .append(`curl -fsSL "https://get.pnpm.io/install.sh" | env PNPM_VERSION=${this._expectedVersion} bash -`)
25
25
  .execute();
26
26
  return this;
27
27
  };
28
28
  this.isInstalled = () => !!process.env[this._homeEnvVar];
29
29
  this.installPackages = async (commando) => {
30
- await (commando !== null && commando !== void 0 ? commando : cli_1.Commando.create())
30
+ await (commando !== null && commando !== void 0 ? commando : Commando_1.Commando.create())
31
31
  .append(`pnpm store prune`)
32
32
  .append(`pnpm install -f --no-frozen-lockfile --prefer-offline false`)
33
33
  .execute();
@@ -77,10 +77,10 @@ class Cli_PNPM extends ts_common_1.Logger {
77
77
  this._expectedVersion = value;
78
78
  }
79
79
  async getVersion() {
80
- const commando = cli_1.Commando.create(programming_1.Cli_Programming, basic_1.Cli_Basic);
80
+ const commando = Commando_1.Commando.create(programming_1.Cli_Programming, basic_1.Cli_Basic);
81
81
  return commando.if('[[ -x "$(command -v pnpm)" ]]', (commando) => {
82
- commando.cli.append('pnpm --version');
83
- }).execute();
82
+ commando.append('pnpm --version');
83
+ }).execute(stdout => stdout);
84
84
  }
85
85
  }
86
86
  exports.Cli_PNPM = Cli_PNPM;
@@ -1,5 +1,6 @@
1
- import { CliBlock, CliWrapper } from '../core/cli';
2
- export declare class Cli_Programming extends CliWrapper {
1
+ import { BaseCommando } from '../shell/core/BaseCommando';
2
+ import { CliBlock } from '../shell/types';
3
+ export declare class Cli_Programming extends BaseCommando {
3
4
  /**
4
5
  * Constructs an if-else conditional command structure.
5
6
  * @param {string} condition - The condition for the if statement.
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Cli_Programming = void 0;
4
- const cli_1 = require("../core/cli");
5
- class Cli_Programming extends cli_1.CliWrapper {
4
+ const BaseCommando_1 = require("../shell/core/BaseCommando");
5
+ class Cli_Programming extends BaseCommando_1.BaseCommando {
6
6
  /**
7
7
  * Constructs an if-else conditional command structure.
8
8
  * @param {string} condition - The condition for the if statement.
@@ -11,18 +11,18 @@ class Cli_Programming extends cli_1.CliWrapper {
11
11
  * @returns {this} - The Cli instance for method chaining.
12
12
  */
13
13
  if(condition, ifBlock, elseBlock) {
14
- this.cli.append(`if ${condition}; then`);
15
- this.cli.indentIn();
14
+ this.append(`if ${condition}; then`);
15
+ this.indentIn();
16
16
  ifBlock(this);
17
17
  if (elseBlock) {
18
- this.cli.indentOut();
19
- this.cli.append('else');
20
- this.cli.indentIn();
18
+ this.indentOut();
19
+ this.append('else');
20
+ this.indentIn();
21
21
  elseBlock(this);
22
22
  }
23
- this.cli.indentOut();
24
- this.cli.append('fi');
25
- this.cli.emptyLine();
23
+ this.indentOut();
24
+ this.append('fi');
25
+ this.emptyLine();
26
26
  return this;
27
27
  }
28
28
  /**
@@ -34,17 +34,17 @@ class Cli_Programming extends cli_1.CliWrapper {
34
34
  */
35
35
  for(varName, arrayNameOrValues, loop) {
36
36
  if (typeof arrayNameOrValues === 'string') {
37
- this.cli.append(`for ${varName} in "\${${arrayNameOrValues}[@]}"; do`);
37
+ this.append(`for ${varName} in "\${${arrayNameOrValues}[@]}"; do`);
38
38
  }
39
39
  else {
40
40
  const values = arrayNameOrValues.map(value => `"${value}"`).join(' ');
41
- this.cli.append(`for ${varName} in ${values}; do`);
41
+ this.append(`for ${varName} in ${values}; do`);
42
42
  }
43
- this.cli.indentIn();
43
+ this.indentIn();
44
44
  loop(this);
45
- this.cli.indentOut();
46
- this.cli.append('done');
47
- this.cli.emptyLine();
45
+ this.indentOut();
46
+ this.append('done');
47
+ this.emptyLine();
48
48
  return this;
49
49
  }
50
50
  /**
@@ -52,7 +52,7 @@ class Cli_Programming extends cli_1.CliWrapper {
52
52
  * @returns {this} - The Cli instance for method chaining.
53
53
  */
54
54
  continue() {
55
- this.cli.append('continue');
55
+ this.append('continue');
56
56
  return this;
57
57
  }
58
58
  /**
@@ -60,7 +60,7 @@ class Cli_Programming extends cli_1.CliWrapper {
60
60
  * @returns {this} - The Cli instance for method chaining.
61
61
  */
62
62
  break() {
63
- this.cli.append('break');
63
+ this.append('break');
64
64
  return this;
65
65
  }
66
66
  /**
@@ -68,7 +68,7 @@ class Cli_Programming extends cli_1.CliWrapper {
68
68
  * @returns {this} - The Cli instance for method chaining.
69
69
  */
70
70
  return() {
71
- this.cli.append('return');
71
+ this.append('return');
72
72
  return this;
73
73
  }
74
74
  }
@@ -0,0 +1,27 @@
1
+ import { BaseCliParam, CliParams } from './types';
2
+ export declare class CLIParamsResolver<T extends BaseCliParam<string, any>[], Output extends CliParams<T> = CliParams<T>> {
3
+ private params;
4
+ static create<T extends BaseCliParam<string, any>[]>(...params: T): CLIParamsResolver<T, CliParams<T>>;
5
+ constructor(params: BaseCliParam<string, any>[]);
6
+ /**
7
+ * Format current input params and return it structured by the app params type.
8
+ * @param inputParams current console input arguments
9
+ * @returns CliParamsObject
10
+ */
11
+ resolveParamValue(inputParams?: string[]): Output;
12
+ /**
13
+ * Find the matching param by finding it's key in the current argument
14
+ * Go over the app params and find the CLIParam object representing it
15
+ * @param inputParam The current console argument being parsed
16
+ * @returns The CliParam or undefined if not found
17
+ * @private
18
+ */
19
+ private findMatchingParamToResolve;
20
+ /**
21
+ * Translate BaseCLIParams passed to the constructor to CLIParams
22
+ * @param params User input of CLI params being passed to the constructor
23
+ * @private
24
+ * @returns CLI Params filled with all mandatory data
25
+ */
26
+ private translate;
27
+ }
@@ -1,39 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CLIParams_Resolver = exports.DefaultProcessor_Number = exports.DefaultProcessor_String = exports.DefaultProcessor_Boolean = void 0;
3
+ exports.CLIParamsResolver = void 0;
4
4
  const ts_common_1 = require("@nu-art/ts-common");
5
- const DefaultProcessor_Boolean = (input, defaultValue) => {
6
- return true;
7
- };
8
- exports.DefaultProcessor_Boolean = DefaultProcessor_Boolean;
9
- const DefaultProcessor_String = (input, defaultValue) => {
10
- if (!input || !input.length) {
11
- if (!defaultValue)
12
- throw new Error('expected string value');
13
- return defaultValue;
14
- }
15
- return input;
16
- };
17
- exports.DefaultProcessor_String = DefaultProcessor_String;
18
- const DefaultProcessor_Number = (input, defaultValue) => {
19
- if (!input) {
20
- if (!defaultValue)
21
- throw new Error('expected number value');
22
- return defaultValue;
23
- }
24
- if (isNaN(Number(input)))
25
- throw new Error('expected number value');
26
- return Number(input);
27
- };
28
- exports.DefaultProcessor_Number = DefaultProcessor_Number;
29
- const DefaultProcessorsMapper = {
30
- string: exports.DefaultProcessor_String,
31
- boolean: exports.DefaultProcessor_Boolean,
32
- number: exports.DefaultProcessor_Number,
33
- };
34
- class CLIParams_Resolver {
5
+ const consts_1 = require("./consts");
6
+ class CLIParamsResolver {
35
7
  static create(...params) {
36
- return new CLIParams_Resolver(params);
8
+ return new CLIParamsResolver(params);
37
9
  }
38
10
  constructor(params) {
39
11
  this.params = this.translate(params);
@@ -111,7 +83,7 @@ class CLIParams_Resolver {
111
83
  param.name = param.keyName;
112
84
  //If no processor is passed apply default by type
113
85
  if (!param.process) {
114
- param.process = DefaultProcessorsMapper[param.type.split('[')[0].trim()];
86
+ param.process = consts_1.DefaultProcessorsMapper[param.type.split('[')[0].trim()];
115
87
  }
116
88
  //Determine if value is array by the param type TODO: improve this chunk of code, this is not strict enough
117
89
  if (!(0, ts_common_1.exists)(param.isArray) && param.type.includes('[]'))
@@ -120,4 +92,4 @@ class CLIParams_Resolver {
120
92
  });
121
93
  }
122
94
  }
123
- exports.CLIParams_Resolver = CLIParams_Resolver;
95
+ exports.CLIParamsResolver = CLIParamsResolver;
@@ -0,0 +1,6 @@
1
+ import { TypedMap } from '@nu-art/ts-common';
2
+ import { CliParam } from './types';
3
+ export declare const DefaultProcessor_Boolean: CliParam<any, boolean>['process'];
4
+ export declare const DefaultProcessor_String: CliParam<any, string>['process'];
5
+ export declare const DefaultProcessor_Number: CliParam<any, number>['process'];
6
+ export declare const DefaultProcessorsMapper: TypedMap<CliParam<any, any>['process']>;