@socketsecurity/lib
Version:
Core utilities and infrastructure for Socket.dev security tools
77 lines (76 loc) • 2.87 kB
TypeScript
/**
* Yargs parser result interface.
*/
interface YargsArguments extends Record<string, unknown> {
_: string[];
$0?: string;
}
/**
* Options for configuring argument parsing, similar to Node.js util.parseArgs.
*/
export interface ParseArgsOptionsConfig {
// Whether the option accepts multiple values (array).
multiple?: boolean | undefined;
// Short alias for the option (single character).
short?: string | undefined;
// Type of the option value.
type?: 'boolean' | 'string' | undefined;
// Default value for the option.
default?: unknown | undefined;
// Transform function to coerce parsed values.
coerce?: (value: unknown) => unknown | undefined;
}
/**
* Configuration object for parseArgs function, similar to Node.js util.parseArgs.
*/
export interface ParseArgsConfig {
// Command-line arguments to parse (defaults to process.argv.slice(2)).
args?: readonly string[] | undefined;
// Options configuration object.
options?: Record<string, ParseArgsOptionsConfig> | undefined;
// Whether to throw on unknown options (default: true).
strict?: boolean | undefined;
// Whether to populate tokens array (not implemented, for API compatibility).
tokens?: boolean | undefined;
// Whether to allow positional arguments after options.
allowPositionals?: boolean | undefined;
// Whether to allow negative numbers as option values.
allowNegative?: boolean | undefined;
// Advanced yargs-parser configuration passthrough.
configuration?: Record<string, boolean | string> | undefined;
}
/**
* Result of parsing command-line arguments.
*/
export interface ParsedArgs<T = Record<string, unknown>> {
// Parsed option values.
values: T;
// Positional arguments (non-option arguments).
positionals: string[];
// Raw parsed arguments object from yargs-parser.
raw: YargsArguments;
}
/**
* Parse command-line arguments with a Node.js parseArgs-compatible API.
* Uses yargs-parser internally for robust argument parsing.
*/
export declare function parseArgs<T = Record<string, unknown>>(config?: ParseArgsConfig): ParsedArgs<T>;
/**
* Parse command-line arguments with Socket defaults.
* Provides sensible defaults for Socket CLI applications.
*/
export declare function parseArgsWithDefaults<T = Record<string, unknown>>(config?: ParseArgsConfig): ParsedArgs<T>;
/**
* Common parseArgs configuration for Socket registry scripts.
*/
export declare const commonParseArgsConfig: ParseArgsConfig;
/**
* Extract positional arguments from process.argv.
* Useful for commands that accept file paths or other positional parameters.
*/
export declare function getPositionalArgs(startIndex?: number): string[];
/**
* Check if a specific flag is present in argv.
*/
export declare function hasFlag(flag: string, argv?: string[]): boolean;
export {};