added getSubcommand method

This commit is contained in:
mmacierzanka committed 2021-09-12 01:28:36 +02:00
1 parent beeff8d233
commit c8ad647553
1 file changed
+13
+13
View File
@@ -84,4 +84,17 @@ export class NestedCommand extends BaseCommand {
type: 1,
};
}
public getSubcommand(name: string, group?: string): SubCommand | null {
if (group) {
const gr = this._children.filter((c) => c instanceof SubCommandGroup).find((g) => g.name === group) as SubCommandGroup;
if (gr) {
return gr.children.find((c) => c.name === name) || null;
} else {
return null;
}
} else {
return (this._children.filter((c) => c instanceof SubCommand).find((c) => c.name === name) as SubCommand) || null;
}
}
}