Comparing version 2.0.1 to 2.1.0
@@ -28,3 +28,3 @@ "use strict"; | ||
this.registrations.set(commandClass, commandBuilder.cliIndex); | ||
const { definitions } = commandClass.getMeta(commandClass.prototype); | ||
const { definitions } = commandClass.resolveMeta(commandClass.prototype); | ||
for (const definition of definitions) | ||
@@ -50,3 +50,3 @@ definition(commandBuilder); | ||
command.path = state.path; | ||
const { transformers } = commandClass.getMeta(commandClass.prototype); | ||
const { transformers } = commandClass.resolveMeta(commandClass.prototype); | ||
for (const transformer of transformers) | ||
@@ -53,0 +53,0 @@ transformer(state, command); |
@@ -15,3 +15,3 @@ import { CommandBuilder, RunState } from '../core'; | ||
new (): Command<Context>; | ||
getMeta(prototype: Command<Context>): Meta<Context>; | ||
resolveMeta(prototype: Command<Context>): Meta<Context>; | ||
schema?: { | ||
@@ -25,2 +25,3 @@ validate: (object: any) => void; | ||
static getMeta<Context extends BaseContext>(prototype: Command<Context>): Meta<Context>; | ||
static resolveMeta<Context extends BaseContext>(prototype: Command<Context>): Meta<Context>; | ||
private static registerDefinition; | ||
@@ -40,3 +41,5 @@ private static registerTransformer; | ||
*/ | ||
static Boolean(descriptor: string): <Context extends BaseContext>(prototype: Command<Context>, propertyName: string) => void; | ||
static Boolean(descriptor: string, { hidden }?: { | ||
hidden?: boolean; | ||
}): <Context extends BaseContext>(prototype: Command<Context>, propertyName: string) => void; | ||
/** | ||
@@ -47,3 +50,5 @@ * Register a listener that looks for an option and its followup argument. When Clipanion detects that this argument is present, the value will be set to whatever follows the option in the input. The value won't be set unless the option is found, so you must remember to set it to an appropriate default value. | ||
*/ | ||
static String(descriptor: string): PropertyDecorator; | ||
static String(descriptor: string, opts?: { | ||
hidden?: boolean; | ||
}): PropertyDecorator; | ||
/** | ||
@@ -60,3 +65,5 @@ * Register a listener that looks for positional arguments. When Clipanion detects that an argument isn't an option, it will put it in this property and continue processing the rest of the command line. | ||
*/ | ||
static Array(descriptor: string): <Context extends BaseContext>(prototype: Command<Context>, propertyName: string) => void; | ||
static Array(descriptor: string, { hidden }?: { | ||
hidden?: boolean; | ||
}): <Context extends BaseContext>(prototype: Command<Context>, propertyName: string) => void; | ||
/** | ||
@@ -63,0 +70,0 @@ * Register a listener that takes all the positional arguments remaining and store them into the selected property. |
@@ -12,4 +12,3 @@ "use strict"; | ||
const base = prototype.constructor; | ||
return base.meta = base.meta || { | ||
usage: [], | ||
return base.meta = Object.prototype.hasOwnProperty.call(base, `meta`) ? base.meta : { | ||
definitions: [], | ||
@@ -28,2 +27,18 @@ transformers: [ | ||
} | ||
static resolveMeta(prototype) { | ||
const definitions = []; | ||
const transformers = []; | ||
for (let proto = prototype; proto instanceof Command; proto = proto.__proto__) { | ||
const meta = this.getMeta(proto); | ||
for (const definition of meta.definitions) | ||
definitions.push(definition); | ||
for (const transformer of meta.transformers) { | ||
transformers.push(transformer); | ||
} | ||
} | ||
return { | ||
definitions, | ||
transformers, | ||
}; | ||
} | ||
static registerDefinition(prototype, definition) { | ||
@@ -57,7 +72,7 @@ this.getMeta(prototype).definitions.push(definition); | ||
*/ | ||
static Boolean(descriptor) { | ||
static Boolean(descriptor, { hidden = false } = {}) { | ||
return (prototype, propertyName) => { | ||
const optNames = descriptor.split(`,`); | ||
this.registerDefinition(prototype, command => { | ||
command.addOption({ names: optNames, arity: 0 }); | ||
command.addOption({ names: optNames, arity: 0, hidden }); | ||
}); | ||
@@ -74,3 +89,3 @@ this.registerTransformer(prototype, (state, command) => { | ||
} | ||
static String(descriptor = { required: true }) { | ||
static String(descriptor = { required: true }, { hidden = false } = {}) { | ||
return (prototype, propertyName) => { | ||
@@ -80,3 +95,3 @@ if (typeof descriptor === `string`) { | ||
this.registerDefinition(prototype, command => { | ||
command.addOption({ names: optNames, arity: 1 }); | ||
command.addOption({ names: optNames, arity: 1, hidden }); | ||
}); | ||
@@ -108,7 +123,7 @@ this.registerTransformer(prototype, (state, command) => { | ||
*/ | ||
static Array(descriptor) { | ||
static Array(descriptor, { hidden = false } = {}) { | ||
return (prototype, propertyName) => { | ||
const optNames = descriptor.split(`,`); | ||
this.registerDefinition(prototype, command => { | ||
command.addOption({ names: optNames, arity: 1 }); | ||
command.addOption({ names: optNames, arity: 1, hidden }); | ||
}); | ||
@@ -115,0 +130,0 @@ this.registerTransformer(prototype, (state, command) => { |
@@ -289,2 +289,3 @@ export declare const NODE_INITIAL = 0; | ||
arity: 1 | 0; | ||
hidden: boolean; | ||
}; | ||
@@ -309,5 +310,4 @@ export declare class CommandBuilder<Context> { | ||
addProxy(): void; | ||
addOption({ names, arity }: { | ||
addOption({ names, arity, hidden }: Partial<OptDefinition> & { | ||
names: string[]; | ||
arity?: 0 | 1; | ||
}): void; | ||
@@ -314,0 +314,0 @@ setContext(context: Context): void; |
@@ -419,5 +419,5 @@ "use strict"; | ||
} | ||
addOption({ names, arity = 0 }) { | ||
addOption({ names, arity = 0, hidden = false }) { | ||
this.allOptionNames.push(...names); | ||
this.options.push({ names, arity }); | ||
this.options.push({ names, arity, hidden }); | ||
} | ||
@@ -432,3 +432,5 @@ setContext(context) { | ||
if (detailed) { | ||
for (const { names, arity } of this.options) { | ||
for (const { names, arity, hidden } of this.options) { | ||
if (hidden) | ||
continue; | ||
const args = []; | ||
@@ -435,0 +437,0 @@ for (let t = 0; t < arity; ++t) |
{ | ||
"name": "clipanion", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"main": "lib/advanced", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72121
1725