New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

clerc

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clerc - npm Package Compare versions

Comparing version 0.0.3 to 0.1.0

200

dist/index.d.ts

@@ -1,7 +0,5 @@

import { LiteEmit } from 'lite-emit';
interface Plugin<U, T extends Clerc = Clerc> {
interface Plugin<T extends Clerc = Clerc, U extends Clerc = Clerc> {
setup: (cli: T) => U;
}
declare function definePlugin<T extends Clerc, U extends Clerc>(p: Plugin<T, U>): Plugin<T, U>;
declare const definePlugin: <T extends Clerc<{}>, U extends Clerc<{}>>(p: Plugin<T, U>) => Plugin<T, U>;

@@ -17,5 +15,12 @@ declare type Dict<T> = Record<string, T>;

declare type Enhance<T, E extends Dict<any> | Dict<any>[]> = GetLength<MustArray<E>> extends 0 ? T : Enhance<EnhanceSingle<T, MustArray<E>[0]>, GetTail<MustArray<E>>>;
interface ParsedArgs {
[arg: string]: any;
"--"?: string[] | undefined;
_: string[];
}
interface FlagOptions {
description: string;
alias?: MaybeArray<string>;
description: string;
default?: PossibleInputKind;
required?: boolean;
}

@@ -25,25 +30,40 @@ interface Flag extends FlagOptions {

}
interface ParameterOptions {
description: string;
required?: boolean;
}
interface Parameter extends ParameterOptions {
name: string;
}
interface CommandOptions {
alias?: MaybeArray<string>;
parameters?: Dict<ParameterOptions>;
flags?: Dict<FlagOptions>;
}
interface Command<N extends string = string, D extends string = string> extends CommandOptions {
interface Command<N extends string | SingleCommandType = string, D extends string = string> extends CommandOptions {
name: N;
description: D;
}
declare type CommandRecord = Dict<Command>;
declare type CommandRecord = Dict<Command> & {
[SingleCommand]?: Command;
};
declare type MakeEventMap<T extends CommandRecord> = {
[K in keyof T]: [InvokerContext];
[K in keyof T]: [InspectorContext];
};
declare type PossibleFlagKind = string | number | boolean | Dict<any>;
declare type PossibleInputKind = string | number | boolean | Dict<any>;
interface HandlerContext<C extends CommandRecord = CommandRecord, N extends keyof C = keyof C> {
name: N;
flags: Dict<PossibleFlagKind | PossibleFlagKind[]>;
name?: N;
resolved: boolean;
raw: ParsedArgs;
parameters: PossibleInputKind[];
flags: Dict<MaybeArray<PossibleInputKind> | undefined>;
cli: Clerc<C>;
}
declare type Handler = (ctx: HandlerContext) => void;
interface InvokerContext<C extends CommandRecord = CommandRecord, N extends keyof C = keyof C> extends HandlerContext<C, N> {
interface InspectorContext<C extends CommandRecord = CommandRecord, N extends keyof C = keyof C> extends HandlerContext<C, N> {
}
declare type Invoker = (ctx: InvokerContext<any>, next: Invoker) => void;
declare type Inspector = (ctx: InspectorContext<any>, next: () => void) => void;
declare const SingleCommand: unique symbol;
declare type SingleCommandType = typeof SingleCommand;
declare class Clerc<C extends CommandRecord = {}> {

@@ -53,21 +73,153 @@ _name: string;

_version: string;
_invokers: Invoker[];
_inspectors: Inspector[];
_commands: C;
__command_emitter: LiteEmit<MakeEventMap<C>>;
private __commandEmitter;
private constructor();
private get __isSingleCommand();
private get __hasCommands();
/**
* Create a new cli
* @returns
* @example
* ```ts
* const cli = Clerc.create()
* ```
*/
static create(): Clerc<{}>;
/**
* Set the name of the cli
* @param name
* @returns
* @example
* ```ts
* Clerc.create()
* .name("test")
* ```
*/
name(name: string): this;
/**
* Set the description of the cli
* @param description
* @returns
* @example
* ```ts
* Clerc.create()
* .description("test cli")
*/
description(description: string): this;
/**
* Set the version of the cli
* @param version
* @returns
* @example
* ```ts
* Clerc.create()
* .version("1.0.0")
*/
version(version: string): this;
command<N extends string, D extends string>(name: N, description: D, options?: CommandOptions): this & Clerc<C & Record<N, Command<N, D>>>;
on<K extends keyof C>(name: K, cb: Handler): this;
use<T extends Clerc, U>(plugin: Plugin<U, T>): U;
registerInvoker(invoker: Invoker): this;
parse(): void;
/**
* Register a command
* @param name
* @param description
* @param options
* @returns
* @example
* ```ts
* Clerc.create()
* .command("test", "test command", {
* alias: "t",
* flags: {
* foo: {
* alias: "f",
* description: "foo flag",
* }
* }
* })
* ```
* @example
* ```ts
* Clerc.create()
* .command("", "single command", {
* flags: {
* foo: {
* alias: "f",
* description: "foo flag",
* }
* }
* })
* ```
*/
command<N extends string | SingleCommandType, D extends string>(name: N, description: D, options?: CommandOptions): this & Clerc<C & Record<N, Command<N, D>>>;
/**
* Register a handler
* @param name
* @param handler
* @returns
* @example
* ```ts
* Clerc.create()
* .command("test", "test command")
* .on("test", (ctx) => {
* console.log(ctx);
* })
* ```
*/
on<K extends keyof C>(name: K, handler: Handler): this;
/**
* Use a plugin
* @param plugin
* @returns
* @example
* ```ts
* Clerc.create()
* .use(plugin)
* ```
*/
use<T extends Clerc, U extends Clerc>(plugin: Plugin<T, U>): U;
/**
* Register a inspector
* @param inspector
* @returns
* @example
* ```ts
* Clerc.create()
* .inspector((ctx, next) => {
* console.log(ctx);
* next();
* })
* ```
*/
inspector(inspector: Inspector): this;
/**
* Parse the command line arguments
* @param args
* @returns
* @example
* ```ts
* Clerc.create()
* .parse(process.argv.slice(2)) // Optional
* ```
*/
parse(argv?: string[]): void;
}
declare function resolveFlagAlias(command: Command): Dict<MaybeArray<string>>;
declare function resolveCommand(commands: CommandRecord, name: string): Command<string, string>;
declare function compose(invokers: Invoker[]): (ctx: HandlerContext) => void;
declare class SingleCommandError extends Error {
}
declare class CommandExistsError extends Error {
}
declare class CommonCommandExistsError extends Error {
}
declare class NoSuchCommandsError extends Error {
}
export { Clerc, Command, CommandOptions, CommandRecord, Dict, Enhance, Flag, FlagOptions, Handler, HandlerContext, Invoker, InvokerContext, MakeEventMap, MaybeArray, Plugin, PossibleFlagKind, compose, definePlugin, resolveCommand, resolveFlagAlias };
declare type CamelCase<T extends string> = T extends `${infer A}-${infer B}${infer C}` ? `${A}${Capitalize<B>}${CamelCase<C>}` : T;
declare const camelCase: <T extends string>(s: T) => CamelCase<T>;
declare type KebabCase<T extends string, A extends string = ""> = T extends `${infer F}${infer R}` ? KebabCase<R, `${A}${F extends Lowercase<F> ? "" : "-"}${Lowercase<F>}`> : A;
declare const kebabCase: <T extends string>(s: T) => KebabCase<T, "">;
declare const resolveFlagAlias: (_command: Command) => Dict<string[]>;
declare const resolveFlagDefault: (_command: Command) => Dict<PossibleInputKind | undefined>;
declare function resolveCommand(commands: CommandRecord, name: string | SingleCommandType): Command | undefined;
declare const resolveArgv: () => string[];
declare function compose(inspectors: Inspector[]): (ctx: InspectorContext) => void;
export { CamelCase, Clerc, Command, CommandExistsError, CommandOptions, CommandRecord, CommonCommandExistsError, Dict, Enhance, Flag, FlagOptions, Handler, HandlerContext, Inspector, InspectorContext, KebabCase, MakeEventMap, MaybeArray, NoSuchCommandsError, Parameter, ParameterOptions, Plugin, PossibleInputKind, SingleCommand, SingleCommandError, SingleCommandType, camelCase, compose, definePlugin, kebabCase, resolveArgv, resolveCommand, resolveFlagAlias, resolveFlagDefault };

3

package.json
{
"name": "clerc",
"version": "0.0.3",
"version": "0.1.0",
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",

@@ -42,2 +42,3 @@ "description": "Clerc is a simple and easy-to-use cli framework.",

"dependencies": {
"is-platform": "^0.2.0",
"lite-emit": "^1.4.0",

@@ -44,0 +45,0 @@ "minimist": "^1.2.7"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc