yargs-file-commands
Version:
A yargs helper function that lets you define your commands structure via directory and file naming conventions.
44 lines (43 loc) • 1.55 kB
TypeScript
import type { CommandModule } from 'yargs';
import type { Command } from './Command';
/**
* Represents a node in the command tree structure
* @type {CommandTreeNode}
*/
type CommandTreeNode = {
/** Name of the command segment */
segmentName: string;
} & ({
/** Internal node type with children */
type: 'internal';
/** Child command nodes */
children: CommandTreeNode[];
} | {
/** Leaf node type with command implementation */
type: 'leaf';
/** The command implementation */
command: Command;
});
/**
* Builds a tree structure from command definitions
* @param {Command[]} commands - Array of command definitions
* @returns {CommandTreeNode[]} Root nodes of the command tree
*
* @description
* Constructs a hierarchical tree structure from flat command definitions,
* preserving the command hierarchy defined by the file system structure.
*/
export declare const buildSegmentTree: (commands: Command[]) => CommandTreeNode[];
/**
* Creates a Yargs command module from a tree node
* @param {CommandTreeNode} treeNode - The tree node to convert
* @returns {CommandModule} Yargs command module
*
* @description
* Recursively converts a tree node into a Yargs command module.
* For leaf nodes, returns the actual command implementation.
* For internal nodes, creates a parent command that manages subcommands.
*/
export declare const createCommand: (treeNode: CommandTreeNode) => CommandModule;
export declare const logCommandTree: (commands: CommandTreeNode[], level?: number) => void;
export {};