@bemoje/cli 0.0.3 → 0.0.4

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.cjs.js CHANGED
@@ -92,20 +92,9 @@ class ArgumentParserSelector extends ParserSelector {
92
92
  }
93
93
  }
94
94
 
95
- const counts = new Map();
96
- function countInstance(ctor) {
97
- const name = ctor.name;
98
- const count = counts.get(name) ?? 0;
99
- counts.set(name, count + 1);
100
- }
101
- function printCounts() {
102
- console.log(counts);
103
- }
104
-
105
95
  class ArgumentReader {
106
96
  constructor(parent){
107
97
  this.parent = parent;
108
- countInstance(ArgumentBuilder);
109
98
  }
110
99
  get $() {
111
100
  return this.parent.$;
@@ -303,7 +292,6 @@ function realizeLazyProperty(obj, key, value) {
303
292
  */ class ArgumentBuilder {
304
293
  constructor(cmd, name){
305
294
  this.cmd = cmd;
306
- countInstance(ArgumentBuilder);
307
295
  this.$ = new commander.Argument(name);
308
296
  this.index = cmd.meta.argValidators.length;
309
297
  cmd.meta.argValidators[this.index] = [];
@@ -671,7 +659,6 @@ function errToObject(error) {
671
659
  /**
672
660
  * An array that holds queued debug messages.
673
661
  */ this.debugMsgQueue = [];
674
- countInstance(OutputManager);
675
662
  this.debug.disable();
676
663
  colors__default["default"].enabled = (()=>{
677
664
  const { FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env;
@@ -713,20 +700,6 @@ function errToObject(error) {
713
700
  }
714
701
 
715
702
  class CommandBuilderMetaData {
716
- constructor(){
717
- this.subcommands = [];
718
- this.globalOptions = [];
719
- this.hiddenGlobalOptions = new Set();
720
- this.presetOptionKeys = [];
721
- this.argParsers = [];
722
- this.argValidators = [];
723
- this.optParsers = {};
724
- this.optValidators = {};
725
- this.rawArgs = [];
726
- this.isNative = false;
727
- this.isInitialized = false;
728
- countInstance(CommandBuilderMetaData);
729
- }
730
703
  get actionHandler() {
731
704
  return async function defaultActionHandler() {
732
705
  this.outputHelp();
@@ -749,6 +722,19 @@ class CommandBuilderMetaData {
749
722
  get hasCustomErrorHandler() {
750
723
  return Object.hasOwn(this, 'errorHandler');
751
724
  }
725
+ constructor(){
726
+ this.subcommands = [];
727
+ this.globalOptions = [];
728
+ this.hiddenGlobalOptions = new Set();
729
+ this.presetOptionKeys = [];
730
+ this.argParsers = [];
731
+ this.argValidators = [];
732
+ this.optParsers = {};
733
+ this.optValidators = {};
734
+ this.rawArgs = [];
735
+ this.isNative = false;
736
+ this.isInitialized = false;
737
+ }
752
738
  }
753
739
 
754
740
  function splitCombinedArgvShorts(argv) {
@@ -812,7 +798,6 @@ Object.defineProperty(commander.Command.prototype, 'builder', {
812
798
  this./**
813
799
  * Indicates whether the auto assign sub command aliases feature is enabled.
814
800
  */ isAutoAssignSubCommandAliasesEnabled = false;
815
- countInstance(CommandFeatureSelector);
816
801
  }
817
802
  /**
818
803
  * Inherits the feature settings from a parent CommandFeatureSelector instance.
@@ -1342,7 +1327,6 @@ function applyDefaults(options = {}) {
1342
1327
  * @param name - The name of the section.
1343
1328
  */ constructor(file, name){
1344
1329
  super(file, name, false);
1345
- countInstance(AppDataSection);
1346
1330
  }
1347
1331
  /**
1348
1332
  * Does nothing
@@ -1404,7 +1388,6 @@ const objAssign = createObjectMerger((value)=>value != null);
1404
1388
  /**
1405
1389
  * Validators for each property key.
1406
1390
  */ this.validators = {};
1407
- countInstance(ConfigSection);
1408
1391
  }
1409
1392
  /**
1410
1393
  * Asserts that a key-value pair is valid.
@@ -1575,7 +1558,6 @@ const objAssign = createObjectMerger((value)=>value != null);
1575
1558
  * @param name - The name of the section.
1576
1559
  */ constructor(file, name){
1577
1560
  super(file, name, false);
1578
- countInstance(PresetsSection);
1579
1561
  this.defineProperty('defaults', {
1580
1562
  description: 'All presets inherit from this preset',
1581
1563
  presets: [],
@@ -1649,7 +1631,6 @@ const objAssign = createObjectMerger((value)=>value != null);
1649
1631
  * @param cmd The parent CommandBuilder instance.
1650
1632
  */ constructor(cmd){
1651
1633
  this.cmd = cmd;
1652
- countInstance(JsonFile);
1653
1634
  }
1654
1635
  /**
1655
1636
  * A lazy-loaded instance of the JsonDB instance containing the data.
@@ -1684,7 +1665,6 @@ const objAssign = createObjectMerger((value)=>value != null);
1684
1665
  class OptionArgumentParserSelector extends ParserSelector {
1685
1666
  constructor(builder){
1686
1667
  super(builder);
1687
- countInstance(OptionArgumentParserSelector);
1688
1668
  }
1689
1669
  custom(parser) {
1690
1670
  const name = this.builder.$.attributeName();
@@ -1696,7 +1676,6 @@ class OptionArgumentParserSelector extends ParserSelector {
1696
1676
  class OptionArgumentValidatorSelector extends ValidatorSelector {
1697
1677
  constructor(builder){
1698
1678
  super(builder);
1699
- countInstance(OptionArgumentValidatorSelector);
1700
1679
  }
1701
1680
  custom(validator) {
1702
1681
  const name = this.builder.$.attributeName();
@@ -1754,7 +1733,6 @@ const OptionHelpers = {
1754
1733
  class OptionReader {
1755
1734
  constructor(parent){
1756
1735
  this.parent = parent;
1757
- countInstance(OptionReader);
1758
1736
  }
1759
1737
  get $() {
1760
1738
  return this.parent.$;
@@ -1818,7 +1796,6 @@ class OptionReader {
1818
1796
  */ class OptionBuilder {
1819
1797
  constructor(cmd, flags){
1820
1798
  this.cmd = cmd;
1821
- countInstance(OptionBuilder);
1822
1799
  this.$ = new commander.Option(flags);
1823
1800
  if (!OptionHelpers.hasArgument(this.$) && this.$.long?.startsWith('--no-')) {
1824
1801
  this.$.default(true);
@@ -1943,7 +1920,6 @@ class OptionReader {
1943
1920
  this.features = new CommandFeatureSelector(this);
1944
1921
  this.parent = null;
1945
1922
  this.meta = new CommandBuilderMetaData();
1946
- countInstance(CommandBuilder);
1947
1923
  this.meta.isNative = isNative;
1948
1924
  this.$ = new commander.Command(name);
1949
1925
  commanderBackRefs.set(this.$, this);
@@ -2979,6 +2955,7 @@ class OptionReader {
2979
2955
  }
2980
2956
  }
2981
2957
  assertCommandNameNotReserved(name) {
2958
+ if (this.isRoot) return;
2982
2959
  if (this.meta.isNative) return;
2983
2960
  if (name === 'u' || name === 'util') {
2984
2961
  this.throwCommanderError(`Name '${name}' is reserved and is not available as name or alias.`);
@@ -3195,7 +3172,6 @@ exports.arrAssign = arrAssign;
3195
3172
  exports.arrLast = arrLast;
3196
3173
  exports.arrSome = arrSome;
3197
3174
  exports.commanderBackRefs = commanderBackRefs;
3198
- exports.countInstance = countInstance;
3199
3175
  exports.createArrayMerger = createArrayMerger;
3200
3176
  exports.createBooleanParser = createBooleanParser;
3201
3177
  exports.createObjectMerger = createObjectMerger;
@@ -3232,7 +3208,6 @@ exports.parseBoolean = parseBoolean;
3232
3208
  exports.parseInteger = parseInteger;
3233
3209
  exports.parseNumber = parseNumber;
3234
3210
  exports.parseString = parseString;
3235
- exports.printCounts = printCounts;
3236
3211
  exports.promptUserEditInTextEditorSync = promptUserEditInTextEditorSync;
3237
3212
  exports.promptUserEditJsonInTextEditorSync = promptUserEditJsonInTextEditorSync;
3238
3213
  exports.readFileSafeSync = readFileSafeSync;
package/index.esm.js CHANGED
@@ -81,20 +81,9 @@ class ArgumentParserSelector extends ParserSelector {
81
81
  }
82
82
  }
83
83
 
84
- const counts = new Map();
85
- function countInstance(ctor) {
86
- const name = ctor.name;
87
- const count = counts.get(name) ?? 0;
88
- counts.set(name, count + 1);
89
- }
90
- function printCounts() {
91
- console.log(counts);
92
- }
93
-
94
84
  class ArgumentReader {
95
85
  constructor(parent){
96
86
  this.parent = parent;
97
- countInstance(ArgumentBuilder);
98
87
  }
99
88
  get $() {
100
89
  return this.parent.$;
@@ -292,7 +281,6 @@ function realizeLazyProperty(obj, key, value) {
292
281
  */ class ArgumentBuilder {
293
282
  constructor(cmd, name){
294
283
  this.cmd = cmd;
295
- countInstance(ArgumentBuilder);
296
284
  this.$ = new Argument(name);
297
285
  this.index = cmd.meta.argValidators.length;
298
286
  cmd.meta.argValidators[this.index] = [];
@@ -660,7 +648,6 @@ function errToObject(error) {
660
648
  /**
661
649
  * An array that holds queued debug messages.
662
650
  */ this.debugMsgQueue = [];
663
- countInstance(OutputManager);
664
651
  this.debug.disable();
665
652
  colors.enabled = (()=>{
666
653
  const { FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env;
@@ -702,20 +689,6 @@ function errToObject(error) {
702
689
  }
703
690
 
704
691
  class CommandBuilderMetaData {
705
- constructor(){
706
- this.subcommands = [];
707
- this.globalOptions = [];
708
- this.hiddenGlobalOptions = new Set();
709
- this.presetOptionKeys = [];
710
- this.argParsers = [];
711
- this.argValidators = [];
712
- this.optParsers = {};
713
- this.optValidators = {};
714
- this.rawArgs = [];
715
- this.isNative = false;
716
- this.isInitialized = false;
717
- countInstance(CommandBuilderMetaData);
718
- }
719
692
  get actionHandler() {
720
693
  return async function defaultActionHandler() {
721
694
  this.outputHelp();
@@ -738,6 +711,19 @@ class CommandBuilderMetaData {
738
711
  get hasCustomErrorHandler() {
739
712
  return Object.hasOwn(this, 'errorHandler');
740
713
  }
714
+ constructor(){
715
+ this.subcommands = [];
716
+ this.globalOptions = [];
717
+ this.hiddenGlobalOptions = new Set();
718
+ this.presetOptionKeys = [];
719
+ this.argParsers = [];
720
+ this.argValidators = [];
721
+ this.optParsers = {};
722
+ this.optValidators = {};
723
+ this.rawArgs = [];
724
+ this.isNative = false;
725
+ this.isInitialized = false;
726
+ }
741
727
  }
742
728
 
743
729
  function splitCombinedArgvShorts(argv) {
@@ -801,7 +787,6 @@ Object.defineProperty(Command.prototype, 'builder', {
801
787
  this./**
802
788
  * Indicates whether the auto assign sub command aliases feature is enabled.
803
789
  */ isAutoAssignSubCommandAliasesEnabled = false;
804
- countInstance(CommandFeatureSelector);
805
790
  }
806
791
  /**
807
792
  * Inherits the feature settings from a parent CommandFeatureSelector instance.
@@ -1331,7 +1316,6 @@ function applyDefaults(options = {}) {
1331
1316
  * @param name - The name of the section.
1332
1317
  */ constructor(file, name){
1333
1318
  super(file, name, false);
1334
- countInstance(AppDataSection);
1335
1319
  }
1336
1320
  /**
1337
1321
  * Does nothing
@@ -1393,7 +1377,6 @@ const objAssign = createObjectMerger((value)=>value != null);
1393
1377
  /**
1394
1378
  * Validators for each property key.
1395
1379
  */ this.validators = {};
1396
- countInstance(ConfigSection);
1397
1380
  }
1398
1381
  /**
1399
1382
  * Asserts that a key-value pair is valid.
@@ -1564,7 +1547,6 @@ const objAssign = createObjectMerger((value)=>value != null);
1564
1547
  * @param name - The name of the section.
1565
1548
  */ constructor(file, name){
1566
1549
  super(file, name, false);
1567
- countInstance(PresetsSection);
1568
1550
  this.defineProperty('defaults', {
1569
1551
  description: 'All presets inherit from this preset',
1570
1552
  presets: [],
@@ -1638,7 +1620,6 @@ const objAssign = createObjectMerger((value)=>value != null);
1638
1620
  * @param cmd The parent CommandBuilder instance.
1639
1621
  */ constructor(cmd){
1640
1622
  this.cmd = cmd;
1641
- countInstance(JsonFile);
1642
1623
  }
1643
1624
  /**
1644
1625
  * A lazy-loaded instance of the JsonDB instance containing the data.
@@ -1673,7 +1654,6 @@ const objAssign = createObjectMerger((value)=>value != null);
1673
1654
  class OptionArgumentParserSelector extends ParserSelector {
1674
1655
  constructor(builder){
1675
1656
  super(builder);
1676
- countInstance(OptionArgumentParserSelector);
1677
1657
  }
1678
1658
  custom(parser) {
1679
1659
  const name = this.builder.$.attributeName();
@@ -1685,7 +1665,6 @@ class OptionArgumentParserSelector extends ParserSelector {
1685
1665
  class OptionArgumentValidatorSelector extends ValidatorSelector {
1686
1666
  constructor(builder){
1687
1667
  super(builder);
1688
- countInstance(OptionArgumentValidatorSelector);
1689
1668
  }
1690
1669
  custom(validator) {
1691
1670
  const name = this.builder.$.attributeName();
@@ -1743,7 +1722,6 @@ const OptionHelpers = {
1743
1722
  class OptionReader {
1744
1723
  constructor(parent){
1745
1724
  this.parent = parent;
1746
- countInstance(OptionReader);
1747
1725
  }
1748
1726
  get $() {
1749
1727
  return this.parent.$;
@@ -1807,7 +1785,6 @@ class OptionReader {
1807
1785
  */ class OptionBuilder {
1808
1786
  constructor(cmd, flags){
1809
1787
  this.cmd = cmd;
1810
- countInstance(OptionBuilder);
1811
1788
  this.$ = new Option(flags);
1812
1789
  if (!OptionHelpers.hasArgument(this.$) && this.$.long?.startsWith('--no-')) {
1813
1790
  this.$.default(true);
@@ -1932,7 +1909,6 @@ class OptionReader {
1932
1909
  this.features = new CommandFeatureSelector(this);
1933
1910
  this.parent = null;
1934
1911
  this.meta = new CommandBuilderMetaData();
1935
- countInstance(CommandBuilder);
1936
1912
  this.meta.isNative = isNative;
1937
1913
  this.$ = new Command(name);
1938
1914
  commanderBackRefs.set(this.$, this);
@@ -2968,6 +2944,7 @@ class OptionReader {
2968
2944
  }
2969
2945
  }
2970
2946
  assertCommandNameNotReserved(name) {
2947
+ if (this.isRoot) return;
2971
2948
  if (this.meta.isNative) return;
2972
2949
  if (name === 'u' || name === 'util') {
2973
2950
  this.throwCommanderError(`Name '${name}' is reserved and is not available as name or alias.`);
@@ -3139,4 +3116,4 @@ function isBoolean(value) {
3139
3116
  return typeof value === 'boolean';
3140
3117
  }
3141
3118
 
3142
- export { AbstractJsonFileSection, AppDataSection, ArgumentBuilder, ArgumentParserSelector, ArgumentReader, ArgumentValidatorSelector, CLI, CommandBuilder, CommandBuilderMetaData, CommandFeatureSelector, ConfigSection, DefaultHelpConfig, ErrorParser, JsonDB, JsonFile, MethodDisabler, OptionArgumentParserSelector, OptionArgumentValidatorSelector, OptionBuilder, OptionHelpers, OptionReader, OutputManager, ParserSelector, PresetsSection, ValidatorSelector, arrAssign, arrLast, arrSome, commanderBackRefs, countInstance, createArrayMerger, createBooleanParser, createObjectMerger, createTypedArrayValidator, createTypedListParser, defaultOpenInEditorCommand, ensureThat, errParseStack, errPrettyStack, errToObject, execInherit, formatTableForTerminal, funSetName, getTempDataPath, isArray, isBoolean, isFunction, isInteger, isNamedFunction, isNamedFunctionArray, isOSX, isObject, isPlainObject, isPrimitive, isString, isStringArray, isStringWithNoSpacesOrDashes, isValidNumber, isVsCodeInstalled, isWindows, objAssign, objUpdatePropertyDescriptors, parseBoolean, parseInteger, parseNumber, parseString, printCounts, promptUserEditInTextEditorSync, promptUserEditJsonInTextEditorSync, readFileSafeSync, readFileSync, readJsonFileSafeSync, realizeLazyProperty, regexEscapeString, setNonEnumerable, splitCombinedArgvShorts, strEnsureStartsWith, strFirstCharToUpperCase, strIsLowerCase, strIsUpperCase, strSplitCamelCase, tempFileSync };
3119
+ export { AbstractJsonFileSection, AppDataSection, ArgumentBuilder, ArgumentParserSelector, ArgumentReader, ArgumentValidatorSelector, CLI, CommandBuilder, CommandBuilderMetaData, CommandFeatureSelector, ConfigSection, DefaultHelpConfig, ErrorParser, JsonDB, JsonFile, MethodDisabler, OptionArgumentParserSelector, OptionArgumentValidatorSelector, OptionBuilder, OptionHelpers, OptionReader, OutputManager, ParserSelector, PresetsSection, ValidatorSelector, arrAssign, arrLast, arrSome, commanderBackRefs, createArrayMerger, createBooleanParser, createObjectMerger, createTypedArrayValidator, createTypedListParser, defaultOpenInEditorCommand, ensureThat, errParseStack, errPrettyStack, errToObject, execInherit, formatTableForTerminal, funSetName, getTempDataPath, isArray, isBoolean, isFunction, isInteger, isNamedFunction, isNamedFunctionArray, isOSX, isObject, isPlainObject, isPrimitive, isString, isStringArray, isStringWithNoSpacesOrDashes, isValidNumber, isVsCodeInstalled, isWindows, objAssign, objUpdatePropertyDescriptors, parseBoolean, parseInteger, parseNumber, parseString, promptUserEditInTextEditorSync, promptUserEditJsonInTextEditorSync, readFileSafeSync, readFileSync, readJsonFileSafeSync, realizeLazyProperty, regexEscapeString, setNonEnumerable, splitCombinedArgvShorts, strEnsureStartsWith, strFirstCharToUpperCase, strIsLowerCase, strIsUpperCase, strSplitCamelCase, tempFileSync };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bemoje/cli",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "dependencies": {
5
5
  "ansi-colors": "^4.1.3",
6
6
  "cli-table": "^0.3.11",
@@ -15,7 +15,6 @@ export declare class CommandBuilderMetaData {
15
15
  rawArgs: string[];
16
16
  isNative: boolean;
17
17
  isInitialized: boolean;
18
- constructor();
19
18
  get actionHandler(): (this: CommandBuilder, ...args: any[]) => void | Promise<void>;
20
19
  get errorHandler(): (this: CommandBuilder, error: unknown, cmd: CommandBuilder) => void;
21
20
  get hasCustomActionHandler(): boolean;
package/src/index.d.ts CHANGED
@@ -7,7 +7,6 @@ export * from './cmd/CommandBuilder';
7
7
  export * from './cmd/CommandBuilderMetaData';
8
8
  export * from './cmd/CommandFeatureSelector';
9
9
  export * from './cmd/DefaultHelpConfig';
10
- export * from './core/counter';
11
10
  export * from './core/OutputManager';
12
11
  export * from './core/ParserSelector';
13
12
  export * from './core/splitCombinedArgvShorts';
@@ -1,3 +0,0 @@
1
- import { TConstructor } from '../util/types/TConstructor';
2
- export declare function countInstance(ctor: TConstructor): void;
3
- export declare function printCounts(): void;