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

@drizzle-team/brocli

Package Overview
Dependencies
Maintainers
0
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@drizzle-team/brocli - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

6

index.d.ts

@@ -152,3 +152,3 @@ /**

};
type RawCommandUniversal<TOpts extends Record<string, GenericBuilderInternals> | undefined = Record<string, GenericBuilderInternals> | undefined, TOptsData = TOpts extends Record<string, GenericBuilderInternals> ? TypeOf<TOpts> : undefined, TTransformed = TOptsData> = {
type RawCommandUniversal<TOpts extends Record<string, GenericBuilderInternals> | undefined = Record<string, GenericBuilderInternals> | undefined, TOptsData = TOpts extends Record<string, GenericBuilderInternals> ? TypeOf<TOpts> : undefined, TTransformed = TOptsData extends undefined ? undefined : TOptsData> = {
name?: string;

@@ -175,3 +175,3 @@ aliases?: [string, ...string[]];

};
type Command = {
type Command<TOptsType = any, TTransformedType = any> = {
name: string;

@@ -196,3 +196,3 @@ aliases?: [string, ...string[]];

};
declare const command: <TOpts extends Record<string, GenericBuilderInternals> | undefined, TOptsData = TOpts extends Record<string, GenericBuilderInternals> ? { [K_1 in keyof { [K in keyof TOpts]: TOpts[K]["_"]["$output"]; }]: { [K in keyof TOpts]: TOpts[K]["_"]["$output"]; }[K_1]; } : undefined, TTransformed = TOptsData>(command: RawCommandUniversal<TOpts, TOptsData, TTransformed>) => Command;
declare const command: <TOpts extends Record<string, GenericBuilderInternals> | undefined, TOptsData = TOpts extends Record<string, GenericBuilderInternals> ? { [K_1 in keyof { [K in keyof TOpts]: TOpts[K]["_"]["$output"]; }]: { [K in keyof TOpts]: TOpts[K]["_"]["$output"]; }[K_1]; } : undefined, TTransformed = TOptsData>(command: RawCommandUniversal<TOpts, TOptsData, TTransformed>) => Command<TOptsData, TTransformed>;
/**

@@ -199,0 +199,0 @@ * Runs CLI commands

@@ -9,5 +9,2 @@ // src/brocli-error.ts

// src/command-core.ts
import clone from "clone";
// src/help-themes.ts

@@ -46,106 +43,31 @@ var defaultTheme = (calledFor) => {

// src/option-builder.ts
var OptionBuilderBase = class _OptionBuilderBase {
_;
config = () => this._.config;
constructor(config) {
this._ = {
config: config ?? {
aliases: [],
type: "string"
},
$output: void 0
};
}
string(name) {
const config = this.config();
return new _OptionBuilderBase({ ...config, type: "string", name });
}
number(name) {
const config = this.config();
return new _OptionBuilderBase({ ...config, type: "number", name });
}
boolean(name) {
const config = this.config();
return new _OptionBuilderBase({ ...config, type: "boolean", name });
}
positional(displayName) {
const config = this.config();
return new _OptionBuilderBase({ ...config, type: "positional", name: displayName });
}
alias(...aliases) {
const config = this.config();
return new _OptionBuilderBase({ ...config, aliases });
}
desc(description) {
const config = this.config();
return new _OptionBuilderBase({ ...config, description });
}
hidden() {
const config = this.config();
return new _OptionBuilderBase({ ...config, isHidden: true });
}
required() {
const config = this.config();
return new _OptionBuilderBase({ ...config, isRequired: true });
}
default(value) {
const config = this.config();
const enums = config.enumVals;
if (enums && !enums.find((v) => value === v)) {
throw new Error(
`Option enums [ ${enums.join(", ")} ] are incompatible with default value ${value}`
);
// src/util.ts
function isInt(value) {
return value === Math.floor(value);
}
var clone = (data) => {
switch (typeof data) {
case "object": {
if (data === null) return data;
if (Array.isArray(data)) {
return data.map((d) => clone(d));
}
const origData = Object.entries(data);
const cloneData = [];
for (const [key, value] of origData) {
cloneData.push([key, clone(value)]);
}
return Object.fromEntries(cloneData);
}
return new _OptionBuilderBase({ ...config, default: value });
}
enum(...values) {
const config = this.config();
const defaultVal = config.default;
if (defaultVal !== void 0 && !values.find((v) => defaultVal === v)) {
throw new Error(
`Option enums [ ${values.join(", ")} ] are incompatible with default value ${defaultVal}`
);
case "function": {
return data;
}
return new _OptionBuilderBase({ ...config, enumVals: values });
}
min(value) {
const config = this.config();
const maxVal = config.maxVal;
if (maxVal !== void 0 && maxVal < value) {
throw new BroCliError("Unable to define option's min value to be higher than max value!");
case "undefined": {
return data;
}
return new _OptionBuilderBase({ ...config, minVal: value });
default:
return JSON.parse(JSON.stringify(data));
}
max(value) {
const config = this.config();
const minVal = config.minVal;
if (minVal !== void 0 && minVal < value) {
throw new BroCliError("Unable to define option's max value to be lower than min value!");
}
return new _OptionBuilderBase({ ...config, maxVal: value });
}
int() {
const config = this.config();
return new _OptionBuilderBase({ ...config, isInt: true });
}
};
function string(name) {
return typeof name === "string" ? new OptionBuilderBase().string(name) : new OptionBuilderBase().string();
}
function number(name) {
return typeof name === "string" ? new OptionBuilderBase().number(name) : new OptionBuilderBase().number();
}
function boolean(name) {
return typeof name === "string" ? new OptionBuilderBase().boolean(name) : new OptionBuilderBase().boolean();
}
function positional(displayName) {
return typeof displayName === "string" ? new OptionBuilderBase().positional(displayName) : new OptionBuilderBase().positional();
}
// src/util.ts
function isInt(value) {
return value === Math.floor(value);
}
// src/command-core.ts

@@ -290,4 +212,3 @@ var unknownCommand = (caller) => {

};
var command = (command2) => commandCheckBypass(command2);
var commandCheckBypass = (command2, ignoreReserved = true) => {
var command = (command2) => {
const allNames = command2.aliases ? [command2.name, ...command2.aliases] : [command2.name];

@@ -315,3 +236,3 @@ const processedOptions = command2.options ? validateOptions(command2.options) : void 0;

allNames.forEach((n, i) => {
if (!ignoreReserved && n === "help") {
if (n === "help") {
throw new BroCliError(

@@ -371,2 +292,8 @@ `Can't define command '${cmd.name}' - 'help' is a reserved name. If you want to redefine help message - do so in runCli's config.`

const firstCandidate = candidates[0];
if (firstCandidate.data === "help") {
return {
command: "help",
args: removeByIndex(args, firstCandidate.originalIndex)
};
}
const { command: command2, args: argsRes } = getCommandInner(commands, candidates, args);

@@ -386,2 +313,12 @@ if (!command2) throw unknownCommand(firstCandidate.data);

let skipNext = !hasEq;
if (namePart === "--help" || namePart === "-h") {
return {
isHelp: true
};
}
if (namePart === "--version" || namePart === "-v") {
return {
isVersion: true
};
}
if (!arg.startsWith("-")) {

@@ -471,3 +408,5 @@ if (!positionals.length) return {};

option,
skipNext
skipNext,
isHelp,
isVersion
} = parseArg(nonPositionalEntries, positionalEntries, arg, nextArg);

@@ -477,2 +416,4 @@ if (!option) unrecognizedArgsArr.push(arg.split("=")[0]);

result[name] = data;
if (isHelp) return "help";
if (isVersion) return "version";
}

@@ -496,22 +437,2 @@ for (const [optKey, option] of optEntries) {

};
var helpCommand = (commands, helpHandler) => commandCheckBypass({
name: "help",
description: "List commands or command details",
options: {
command: string().alias("c", "cmd").desc("Target command"),
pos: positional().desc("Target command")
},
hidden: true,
handler: async (options) => {
const { command: command2, pos } = options;
if (command2 === void 0 && pos === void 0) {
return await helpHandler(commands);
}
const cmd = commands.find((e) => e.name === pos || e.aliases?.find((a) => a === pos)) ?? commands.find((e) => e.name === command2 || e.aliases?.find((a) => a === command2));
if (cmd) {
return cmd.help ? await executeOrLog(cmd.help) : await helpHandler(cmd);
}
return await helpHandler(commands);
}
}, true);
var getCommandNameRecursive = (command2) => command2.parent ? `${getCommandNameRecursive(command2.parent)} ${command2.name}` : command2.name;

@@ -548,5 +469,4 @@ var validateCommands = (commands, parent) => {

var removeByIndex = (arr, idx) => [...arr.slice(0, idx), ...arr.slice(idx + 1, arr.length)];
var help = async (command2, commands, helpHandler) => typeof command2 === "object" ? command2.help !== void 0 ? await executeOrLog(command2.help) : await helpHandler(command2) : await helpHandler(commands);
var rawCli = async (commands, config) => {
let options;
let cmd;
const processedCmds = validateCommands(commands);

@@ -557,19 +477,8 @@ const argSource = config?.argSource ?? process.argv;

const omitKeysOfUndefinedOptions = config?.omitKeysOfUndefinedOptions ?? false;
const cmds = [...processedCmds, helpCommand(processedCmds, helpHandler)];
let args = argSource.slice(2, argSource.length);
if (!args.length) return await helpHandler(processedCmds);
const helpIndex = args.findIndex((arg) => arg === "--help" || arg === "-h");
if (helpIndex !== -1 && (helpIndex > 0 ? args[helpIndex - 1]?.startsWith("-") ? false : true : true)) {
let command3;
if (args[helpIndex + 1]?.startsWith("-")) {
command3 = getCommand(cmds, args).command;
} else {
const targetName = args[helpIndex + 1];
command3 = cmds.find((cmd2) => {
const names = cmd2.aliases ? [cmd2.name, ...cmd2.aliases] : [cmd2.name];
return names.find((n) => n === targetName);
});
command3 = command3 ?? getCommand(cmds, args).command;
}
return command3 ? command3.help ? await executeOrLog(command3.help) : await helpHandler(command3) : await helpHandler(processedCmds);
if (helpIndex !== -1 && (helpIndex > 0 ? args[helpIndex - 1]?.startsWith("-") && !args[helpIndex - 1].includes("=") ? false : true : true)) {
const command3 = getCommand(processedCmds, args).command;
return help(command3, processedCmds, helpHandler);
}

@@ -580,7 +489,14 @@ const versionIndex = args.findIndex((arg) => arg === "--version" || arg === "-v");

}
const { command: command2, args: newArgs } = getCommand(cmds, args);
const { command: command2, args: newArgs } = getCommand(processedCmds, args);
if (!command2) return helpHandler(processedCmds);
options = parseOptions(command2, newArgs, omitKeysOfUndefinedOptions);
cmd = command2;
await cmd.handler(command2.transform ? await command2.transform(options) : options);
if (command2 === "help") {
const { command: helpCommand } = getCommand(processedCmds, newArgs);
return help(helpCommand, processedCmds, helpHandler);
}
const optionResult = parseOptions(command2, newArgs, omitKeysOfUndefinedOptions);
if (optionResult === "help") return await help(command2, commands, helpHandler);
if (optionResult === "version") return await executeOrLog(version);
if (optionResult) {
await command2.handler(command2.transform ? await command2.transform(optionResult) : optionResult);
}
return void 0;

@@ -597,2 +513,101 @@ };

var handler = (options, handler2) => handler2;
// src/option-builder.ts
var OptionBuilderBase = class _OptionBuilderBase {
_;
config = () => this._.config;
constructor(config) {
this._ = {
config: config ?? {
aliases: [],
type: "string"
},
$output: void 0
};
}
string(name) {
const config = this.config();
return new _OptionBuilderBase({ ...config, type: "string", name });
}
number(name) {
const config = this.config();
return new _OptionBuilderBase({ ...config, type: "number", name });
}
boolean(name) {
const config = this.config();
return new _OptionBuilderBase({ ...config, type: "boolean", name });
}
positional(displayName) {
const config = this.config();
return new _OptionBuilderBase({ ...config, type: "positional", name: displayName });
}
alias(...aliases) {
const config = this.config();
return new _OptionBuilderBase({ ...config, aliases });
}
desc(description) {
const config = this.config();
return new _OptionBuilderBase({ ...config, description });
}
hidden() {
const config = this.config();
return new _OptionBuilderBase({ ...config, isHidden: true });
}
required() {
const config = this.config();
return new _OptionBuilderBase({ ...config, isRequired: true });
}
default(value) {
const config = this.config();
const enums = config.enumVals;
if (enums && !enums.find((v) => value === v)) {
throw new Error(
`Option enums [ ${enums.join(", ")} ] are incompatible with default value ${value}`
);
}
return new _OptionBuilderBase({ ...config, default: value });
}
enum(...values) {
const config = this.config();
const defaultVal = config.default;
if (defaultVal !== void 0 && !values.find((v) => defaultVal === v)) {
throw new Error(
`Option enums [ ${values.join(", ")} ] are incompatible with default value ${defaultVal}`
);
}
return new _OptionBuilderBase({ ...config, enumVals: values });
}
min(value) {
const config = this.config();
const maxVal = config.maxVal;
if (maxVal !== void 0 && maxVal < value) {
throw new BroCliError("Unable to define option's min value to be higher than max value!");
}
return new _OptionBuilderBase({ ...config, minVal: value });
}
max(value) {
const config = this.config();
const minVal = config.minVal;
if (minVal !== void 0 && minVal < value) {
throw new BroCliError("Unable to define option's max value to be lower than min value!");
}
return new _OptionBuilderBase({ ...config, maxVal: value });
}
int() {
const config = this.config();
return new _OptionBuilderBase({ ...config, isInt: true });
}
};
function string(name) {
return typeof name === "string" ? new OptionBuilderBase().string(name) : new OptionBuilderBase().string();
}
function number(name) {
return typeof name === "string" ? new OptionBuilderBase().number(name) : new OptionBuilderBase().number();
}
function boolean(name) {
return typeof name === "string" ? new OptionBuilderBase().boolean(name) : new OptionBuilderBase().boolean();
}
function positional(displayName) {
return typeof displayName === "string" ? new OptionBuilderBase().positional(displayName) : new OptionBuilderBase().positional();
}
export {

@@ -599,0 +614,0 @@ BroCliError,

@@ -5,3 +5,3 @@ {

"author": "Drizzle Team",
"version": "0.5.0",
"version": "0.5.1",
"description": "Typed CLI command runner",

@@ -30,3 +30,2 @@ "license": "Apache-2.0",

"@originjs/vite-plugin-commonjs": "^1.0.3",
"@types/clone": "^2.1.4",
"@types/node": "^20.12.13",

@@ -57,6 +56,3 @@ "dprint": "^0.46.2",

}
},
"dependencies": {
"clone": "^2.1.2"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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