Comparing version 0.10.2 to 0.11.0
@@ -14,3 +14,3 @@ "use strict"; | ||
*/ | ||
exports.ExistingPath = __1.extendType(__1.string, { | ||
exports.ExistingPath = (0, __1.extendType)(__1.string, { | ||
displayName: 'path', | ||
@@ -30,3 +30,3 @@ description: 'An existing path', | ||
*/ | ||
exports.Directory = __1.extendType(exports.ExistingPath, { | ||
exports.Directory = (0, __1.extendType)(exports.ExistingPath, { | ||
async from(resolved) { | ||
@@ -45,3 +45,3 @@ const stat = fs_1.default.statSync(resolved); | ||
*/ | ||
exports.File = __1.extendType(exports.ExistingPath, { | ||
exports.File = (0, __1.extendType)(exports.ExistingPath, { | ||
async from(resolved) { | ||
@@ -48,0 +48,0 @@ const stat = fs_1.default.statSync(resolved); |
@@ -9,3 +9,3 @@ "use strict"; | ||
*/ | ||
exports.Url = __1.extendType(__1.string, { | ||
exports.Url = (0, __1.extendType)(__1.string, { | ||
displayName: 'url', | ||
@@ -27,3 +27,3 @@ description: 'A valid URL', | ||
*/ | ||
exports.HttpUrl = __1.extendType(exports.Url, { | ||
exports.HttpUrl = (0, __1.extendType)(exports.Url, { | ||
async from(url) { | ||
@@ -30,0 +30,0 @@ if (!['http:', 'https:'].includes(url.protocol)) { |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -27,3 +31,3 @@ if (k2 === undefined) k2 = k; | ||
const effects_1 = require("./effects"); | ||
exports.helpFlag = flag_1.flag({ | ||
exports.helpFlag = (0, flag_1.flag)({ | ||
long: 'help', | ||
@@ -34,3 +38,3 @@ short: 'h', | ||
}); | ||
exports.versionFlag = flag_1.flag({ | ||
exports.versionFlag = (0, flag_1.flag)({ | ||
long: 'version', | ||
@@ -37,0 +41,0 @@ short: 'v', |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -37,4 +41,4 @@ if (k2 === undefined) k2 = k; | ||
function command(config) { | ||
const argEntries = utils_1.entries(config.args); | ||
const circuitbreaker = circuitbreaker_1.createCircuitBreaker(!!config.version); | ||
const argEntries = (0, utils_1.entries)(config.args); | ||
const circuitbreaker = (0, circuitbreaker_1.createCircuitBreaker)(!!config.version); | ||
return { | ||
@@ -47,3 +51,3 @@ name: config.name, | ||
helpTopics() { | ||
return utils_1.flatMap(Object.values(config.args).concat([circuitbreaker]), (x) => { var _a, _b; return (_b = (_a = x.helpTopics) === null || _a === void 0 ? void 0 : _a.call(x)) !== null && _b !== void 0 ? _b : []; }); | ||
return (0, utils_1.flatMap)(Object.values(config.args).concat([circuitbreaker]), (x) => { var _a, _b; return (_b = (_a = x.helpTopics) === null || _a === void 0 ? void 0 : _a.call(x)) !== null && _b !== void 0 ? _b : []; }); | ||
}, | ||
@@ -65,4 +69,4 @@ printHelp(context) { | ||
} | ||
const usageBreakdown = utils_1.groupBy(this.helpTopics(), (x) => x.category); | ||
for (const [category, helpTopics] of utils_1.entries(usageBreakdown)) { | ||
const usageBreakdown = (0, utils_1.groupBy)(this.helpTopics(), (x) => x.category); | ||
for (const [category, helpTopics] of (0, utils_1.entries)(usageBreakdown)) { | ||
lines.push(''); | ||
@@ -75,3 +79,3 @@ lines.push(category.toUpperCase() + ':'); | ||
let line = ''; | ||
line += ' ' + utils_1.padNoAnsi(helpTopic.usage, widestUsage, 'end'); | ||
line += ' ' + (0, utils_1.padNoAnsi)(helpTopic.usage, widestUsage, 'end'); | ||
line += ' - '; | ||
@@ -150,3 +154,3 @@ line += helpTopic.description; | ||
const parsed = await this.parse(context); | ||
circuitbreaker_1.handleCircuitBreaker(context, this, breaker); | ||
(0, circuitbreaker_1.handleCircuitBreaker)(context, this, breaker); | ||
if (Result.isErr(parsed)) { | ||
@@ -153,0 +157,0 @@ return Result.err(parsed.error); |
@@ -23,3 +23,3 @@ "use strict"; | ||
return; | ||
errorIndex = strip_ansi_1.default(strings.join(' ')).length; | ||
errorIndex = (0, strip_ansi_1.default)(strings.join(' ')).length; | ||
} | ||
@@ -85,3 +85,3 @@ if (error.nodes.length === 0) | ||
errorMessages.push(` ${x.highlighted.colorized}`); | ||
for (const [index, line] of utils_1.enumerate(x.message.split('\n'))) { | ||
for (const [index, line] of (0, utils_1.enumerate)(x.message.split('\n'))) { | ||
const prefix = index === 0 ? chalk_1.default.bold('^') : ' '; | ||
@@ -104,3 +104,3 @@ const msg = chalk_1.default.red(` ${pad} ${prefix} ${line}`); | ||
withNoHighlight.forEach(({ message }) => { | ||
const num = chalk_1.default.red.bold(`${utils_1.padNoAnsi(number.toString(), maxNumberWidth, 'start')}.`); | ||
const num = chalk_1.default.red.bold(`${(0, utils_1.padNoAnsi)(number.toString(), maxNumberWidth, 'start')}.`); | ||
errorMessages.push(` ${num} ${chalk_1.default.red(message)}`); | ||
@@ -107,0 +107,0 @@ number++; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -48,3 +52,3 @@ if (k2 === undefined) k2 = k; | ||
var _a; | ||
const decoder = type_1.extendType(exports.boolean, config.type); | ||
const decoder = (0, type_1.extendType)(exports.boolean, config.type); | ||
return { | ||
@@ -91,3 +95,3 @@ description: (_a = config.description) !== null && _a !== void 0 ? _a : config.type.description, | ||
var _a, _b; | ||
const options = findOption_1.findOption(nodes, { | ||
const options = (0, findOption_1.findOption)(nodes, { | ||
longNames: [config.long], | ||
@@ -94,0 +98,0 @@ shortNames: config.short ? [config.short] : [], |
@@ -9,3 +9,7 @@ "use strict"; | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -12,0 +16,0 @@ if (k2 === undefined) k2 = k; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -55,3 +59,3 @@ if (k2 === undefined) k2 = k; | ||
var _a, _b; | ||
const options = findOption_1.findOption(nodes, { | ||
const options = (0, findOption_1.findOption)(nodes, { | ||
longNames: [config.long], | ||
@@ -58,0 +62,0 @@ shortNames: config.short ? [config.short] : [], |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -55,3 +59,3 @@ if (k2 === undefined) k2 = k; | ||
var _a; | ||
const options = findOption_1.findOption(nodes, { | ||
const options = (0, findOption_1.findOption)(nodes, { | ||
longNames: [config.long], | ||
@@ -58,0 +62,0 @@ shortNames: config.short ? [config.short] : [], |
@@ -8,3 +8,3 @@ "use strict"; | ||
const debug_1 = __importDefault(require("debug")); | ||
const debug = debug_1.default('cmd-ts:parser'); | ||
const debug = (0, debug_1.default)('cmd-ts:parser'); | ||
/** | ||
@@ -11,0 +11,0 @@ * Create an AST from a token list |
@@ -17,3 +17,3 @@ "use strict"; | ||
}; | ||
for (const [stringIndex, string] of utils_1.enumerate(strings)) { | ||
for (const [stringIndex, string] of (0, utils_1.enumerate)(strings)) { | ||
const chars = [...string]; | ||
@@ -20,0 +20,0 @@ for (let i = 0; i < chars.length; i++) { |
@@ -9,3 +9,3 @@ "use strict"; | ||
function oneOf(literals) { | ||
const examples = literals.map(x => util_1.inspect(x)).join(', '); | ||
const examples = literals.map(x => (0, util_1.inspect)(x)).join(', '); | ||
return { | ||
@@ -12,0 +12,0 @@ async from(str) { |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -79,3 +83,3 @@ if (k2 === undefined) k2 = k; | ||
var _a, _b; | ||
const options = findOption_1.findOption(nodes, { | ||
const options = (0, findOption_1.findOption)(nodes, { | ||
longNames: [config.long], | ||
@@ -82,0 +86,0 @@ shortNames: config.short ? [config.short] : [], |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -11,3 +11,3 @@ "use strict"; | ||
const result = await runSafely(ap, strings); | ||
if (Result_1.isErr(result)) { | ||
if ((0, Result_1.isErr)(result)) { | ||
return result.error.run(); | ||
@@ -28,5 +28,5 @@ } | ||
const result = await ap.run({ nodes, visitedNodes: new Set(), hotPath }); | ||
if (Result_1.isErr(result)) { | ||
if ((0, Result_1.isErr)(result)) { | ||
throw new effects_1.Exit({ | ||
message: errorBox_1.errorBox(nodes, result.error.errors, hotPath), | ||
message: (0, errorBox_1.errorBox)(nodes, result.error.errors, hotPath), | ||
exitCode: 1, | ||
@@ -37,3 +37,3 @@ into: 'stderr', | ||
else { | ||
return Result_1.ok(result.value); | ||
return (0, Result_1.ok)(result.value); | ||
} | ||
@@ -43,3 +43,3 @@ } | ||
if (e instanceof effects_1.Exit) { | ||
return Result_1.err(e); | ||
return (0, Result_1.err)(e); | ||
} | ||
@@ -55,4 +55,4 @@ throw e; | ||
const result = await runSafely(ap, strings); | ||
if (Result_1.isErr(result)) { | ||
return Result_1.err(result.error.dryRun()); | ||
if ((0, Result_1.isErr)(result)) { | ||
return (0, Result_1.err)(result.error.dryRun()); | ||
} | ||
@@ -85,5 +85,5 @@ else { | ||
ap.register(registerContext); | ||
const tokens = tokenizer_1.tokenize(strings); | ||
return parser_1.parse(tokens, registerContext); | ||
const tokens = (0, tokenizer_1.tokenize)(strings); | ||
return (0, parser_1.parse)(tokens, registerContext); | ||
} | ||
//# sourceMappingURL=runner.js.map |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -35,3 +39,3 @@ if (k2 === undefined) k2 = k; | ||
function subcommands(config) { | ||
const circuitbreaker = circuitbreaker_1.createCircuitBreaker(!!config.version); | ||
const circuitbreaker = (0, circuitbreaker_1.createCircuitBreaker)(!!config.version); | ||
const type = { | ||
@@ -53,3 +57,3 @@ async from(str) { | ||
let errorMessage = `Not a valid subcommand name`; | ||
const closeOptions = didyoumean_1.default(str, flatMap(commands, x => x.names)); | ||
const closeOptions = (0, didyoumean_1.default)(str, flatMap(commands, x => x.names)); | ||
if (closeOptions) { | ||
@@ -62,3 +66,3 @@ const option = Array.isArray(closeOptions) ? closeOptions[0] : closeOptions; | ||
}; | ||
const subcommand = positional_1.positional({ | ||
const subcommand = (0, positional_1.positional)({ | ||
displayName: 'subcommand', | ||
@@ -147,3 +151,3 @@ description: 'one of ' + Object.keys(config.cmds).join(', '), | ||
const breaker = await circuitbreaker.parse(context); | ||
circuitbreaker_1.handleCircuitBreaker(context, this, breaker); | ||
(0, circuitbreaker_1.handleCircuitBreaker)(context, this, breaker); | ||
return Result.err({ ...parsedSubcommand.error, partialValue: {} }); | ||
@@ -150,0 +154,0 @@ } |
@@ -27,3 +27,3 @@ "use strict"; | ||
exports.string = { | ||
...type_1.identity(), | ||
...(0, type_1.identity)(), | ||
description: 'a string', | ||
@@ -36,3 +36,3 @@ displayName: 'str', | ||
exports.boolean = { | ||
...type_1.identity(), | ||
...(0, type_1.identity)(), | ||
description: 'a boolean', | ||
@@ -39,0 +39,0 @@ displayName: 'true/false', |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -30,3 +34,3 @@ if (k2 === undefined) k2 = k; | ||
function union(ts, { combineErrors = errors => errors.join('\n'), } = {}) { | ||
const merged = Object.assign({}, ...ts.map(x => type_1.typeDef(x))); | ||
const merged = Object.assign({}, ...ts.map(x => (0, type_1.typeDef)(x))); | ||
return { | ||
@@ -37,3 +41,3 @@ ...merged, | ||
for (const t of ts) { | ||
const decoded = await Result.safeAsync(type_1.fromFn(t)(input)); | ||
const decoded = await Result.safeAsync((0, type_1.fromFn)(t)(input)); | ||
if (Result.isOk(decoded)) { | ||
@@ -40,0 +44,0 @@ return decoded.value; |
@@ -12,3 +12,3 @@ "use strict"; | ||
function padNoAnsi(str, length, place) { | ||
const noAnsiStr = strip_ansi_1.default(str); | ||
const noAnsiStr = (0, strip_ansi_1.default)(str); | ||
if (length < noAnsiStr.length) | ||
@@ -15,0 +15,0 @@ return str; |
{ | ||
"name": "cmd-ts", | ||
"version": "0.10.2", | ||
"version": "0.11.0", | ||
"homepage": "https://cmd-ts.now.sh", | ||
@@ -14,11 +14,2 @@ "license": "MIT", | ||
], | ||
"scripts": { | ||
"build": "tsc && tsc --project ./tsconfig.esm.json", | ||
"lint": "eslint src/**/*.ts test/**/*.ts example/**/*.ts ./.eslintrc.js", | ||
"now-build": "mdbook build --dest-dir=public", | ||
"start": "yarn build --watch", | ||
"prepublishOnly": "rm -rf dist && yarn build && yarn test", | ||
"test": "jest", | ||
"ts-node": "./scripts/ts-node" | ||
}, | ||
"husky": { | ||
@@ -38,38 +29,46 @@ "hooks": { | ||
"chalk": "^4.0.0", | ||
"debug": "^4.1.1", | ||
"didyoumean": "^1.2.1", | ||
"debug": "^4.3.4", | ||
"didyoumean": "^1.2.2", | ||
"strip-ansi": "^6.0.0" | ||
}, | ||
"devDependencies": { | ||
"@swc-node/jest": "1.3.0", | ||
"@swc-node/register": "1.3.1", | ||
"@types/debug": "4.1.5", | ||
"@changesets/cli": "^2.22.0", | ||
"@swc-node/register": "1.5.1", | ||
"@types/debug": "4.1.7", | ||
"@types/didyoumean": "1.2.0", | ||
"@types/fs-extra": "9.0.8", | ||
"@types/jest": "26.0.20", | ||
"@types/node-fetch": "2.5.8", | ||
"@types/request": "2.48.7", | ||
"@typescript-eslint/eslint-plugin": "4.24.0", | ||
"@typescript-eslint/parser": "4.24.0", | ||
"@types/fs-extra": "9.0.13", | ||
"@types/node-fetch": "2.6.1", | ||
"@types/request": "2.48.8", | ||
"@typescript-eslint/eslint-plugin": "5.24.0", | ||
"@typescript-eslint/parser": "5.24.0", | ||
"cargo-mdbook": "0.4.4", | ||
"docs-ts": "0.6.4", | ||
"eslint": "7.27.0", | ||
"eslint-config-prettier": "7.2.0", | ||
"eslint-plugin-import": "2.23.3", | ||
"eslint-plugin-prettier": "3.4.0", | ||
"docs-ts": "0.6.10", | ||
"eslint": "8.15.0", | ||
"eslint-config-prettier": "8.5.0", | ||
"eslint-plugin-import": "2.26.0", | ||
"eslint-plugin-prettier": "4.0.0", | ||
"esm": "3.2.25", | ||
"execa": "5.0.0", | ||
"fs-extra": "9.1.0", | ||
"husky": "5.2.0", | ||
"execa": "6.1.0", | ||
"fs-extra": "10.1.0", | ||
"husky": "8.0.1", | ||
"infer-types": "0.0.2", | ||
"jest": "27.3.0", | ||
"jest-junit": "12.0.0", | ||
"node-fetch": "2.6.1", | ||
"prettier": "2.3.0", | ||
"node-fetch": "2.6.7", | ||
"prettier": "2.6.2", | ||
"request": "2.88.2", | ||
"tempy": "1.0.0", | ||
"typedoc": "0.20.30", | ||
"typescript": "4.2.3" | ||
"tempy": "3.0.0", | ||
"typedoc": "0.22.15", | ||
"typescript": "4.6.4", | ||
"vitest": "^0.12.6" | ||
}, | ||
"peerDependencies": {} | ||
} | ||
"scripts": { | ||
"build": "tsc && tsc --project ./tsconfig.esm.json", | ||
"lint": "eslint src/**/*.ts test/**/*.ts example/**/*.ts ./.eslintrc.js", | ||
"now-build": "mdbook build --dest-dir=public", | ||
"start": "yarn build --watch", | ||
"test": "vitest", | ||
"ts-node": "./scripts/ts-node", | ||
"changeset:version": "changeset version && pnpm install --no-frozen-lockfile", | ||
"changeset:publish": "pnpm run build && changeset publish" | ||
}, | ||
"readme": "# `cmd-ts`\n\n> š» A type-driven command line argument parser, with awesome error reporting š¤¤\n\nNot all command line arguments are strings, but for some reason, our CLI parsers force us to use strings everywhere. š¤ `cmd-ts` is a fully-fledged command line argument parser, influenced by Rust's [`clap`](https://github.com/clap-rs/clap) and [`structopt`](https://github.com/TeXitoi/structopt):\n\nš¤© Awesome autocomplete, awesome safeness\n\nš Decode your own custom types from strings with logic and context-aware error handling\n\nš² Nested subcommands, composable API\n\n### Basic usage\n\n```ts\nimport { command, run, string, number, positional, option } from 'cmd-ts';\n\nconst cmd = command({\n name: 'my-command',\n description: 'print something to the screen',\n version: '1.0.0',\n args: {\n number: positional({ type: number, displayName: 'num' }),\n message: option({\n long: 'greeting',\n type: string,\n }),\n },\n handler: (args) => {\n args.message; // string\n args.number; // number\n console.log(args);\n },\n});\n\nrun(cmd, process.argv.slice(2));\n```\n\n#### `command(arguments)`\n\nCreates a CLI command.\n\n### Decoding custom types from strings\n\nNot all command line arguments are strings. You sometimes want integers, UUIDs, file paths, directories, globs...\n\n> **Note:** this section describes the `ReadStream` type, implemented in `./src/example/test-types.ts`\n\nLet's say we're about to write a `cat` clone. We want to accept a file to read into stdout. A simple example would be something like:\n\n```ts\n// my-app.ts\n\nimport { command, run, positional, string } from 'cmd-ts';\n\nconst app = command({\n /// name: ...,\n args: {\n file: positional({ type: string, displayName: 'file' }),\n },\n handler: ({ file }) => {\n // read the file to the screen\n fs.createReadStream(file).pipe(stdout);\n },\n});\n\n// parse arguments\nrun(app, process.argv.slice(2));\n```\n\nThat works okay. But we can do better. In which ways?\n\n- Error handling is out of the command line argument parser context, and in userland, making things less consistent and pretty.\n- It shows we lack composability and encapsulation ā and we miss a way to distribute shared \"command line\" behavior.\n\nWhat if we had a way to get a `Stream` out of the parser, instead of a plain string? This is where `cmd-ts` gets its power from, custom type decoding:\n\n```ts\n// ReadStream.ts\n\nimport { Type } from 'cmd-ts';\nimport fs from 'fs';\n\n// Type<string, Stream> reads as \"A type from `string` to `Stream`\"\nconst ReadStream: Type<string, Stream> = {\n async from(str) {\n if (!fs.existsSync(str)) {\n // Here is our error handling!\n throw new Error('File not found');\n }\n\n return fs.createReadStream(str);\n },\n};\n```\n\nNow we can use (and share) this type and always get a `Stream`, instead of carrying the implementation detail around:\n\n```ts\n// my-app.ts\n\nimport { command, run, positional } from 'cmd-ts';\n\nconst app = command({\n // name: ...,\n args: {\n stream: positional({ type: ReadStream, displayName: 'file' }),\n },\n handler: ({ stream }) => stream.pipe(process.stdout),\n});\n\n// parse arguments\nrun(app, process.argv.slice(2));\n```\n\nEncapsulating runtime behaviour and safe type conversions can help us with awesome user experience:\n\n- We can throw an error when the file is not found\n- We can try to parse the string as a URI and check if the protocol is HTTP, if so - make an HTTP request and return the body stream\n- We can see if the string is `-`, and when it happens, return `process.stdin` like many Unix applications\n\nAnd the best thing about it ā everything is encapsulated to an easily tested type definition, which can be easily shared and reused. Take a look at [io-ts-types](https://github.com/gcanti/io-ts-types), for instance, which has types like DateFromISOString, NumberFromString and more, which is something we can totally do.\n\n## Inspiration\n\nThis project was previously called `clio-ts`, because it was based on `io-ts`. This is no longer the case, because I want to reduce the dependency count and mental overhead. I might have a function to migrate types between the two.\n" | ||
} |
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
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
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
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
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
332366
27
5571
Updateddebug@^4.3.4
Updateddidyoumean@^1.2.2