@kaynooo/cli-dev 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +35 -30
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -129,18 +129,14 @@ var FULL_STOP = /\.$/;
|
|
|
129
129
|
function usageLine(usage, colors = paint(process5.stdout)) {
|
|
130
130
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
131
131
|
}
|
|
132
|
-
function helpText(usage, options, colors = paint(process5.stdout), { examples = [],
|
|
133
|
-
return [usageLine(usage, colors),
|
|
132
|
+
function helpText(usage, options, colors = paint(process5.stdout), { examples = [], exits = [] } = {}) {
|
|
133
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
134
134
|
`);
|
|
135
135
|
}
|
|
136
136
|
function exitRows(exits, colors = paint(process5.stdout)) {
|
|
137
137
|
if (exits.length === 0)
|
|
138
138
|
return [];
|
|
139
|
-
|
|
140
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
141
|
-
}
|
|
142
|
-
function replacesRows(replaces, colors = paint(process5.stdout)) {
|
|
143
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
139
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
144
140
|
}
|
|
145
141
|
function wantsHelpJson(env = process5.env) {
|
|
146
142
|
return env.KIT_HELP === "json";
|
|
@@ -599,7 +595,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
599
595
|
header(colors, summary),
|
|
600
596
|
"",
|
|
601
597
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
602
|
-
...replacesRows(replaces, colors),
|
|
603
598
|
"",
|
|
604
599
|
...await commandRows(commands, colors),
|
|
605
600
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -778,7 +773,11 @@ async function printCandidates(found) {
|
|
|
778
773
|
return 0;
|
|
779
774
|
}
|
|
780
775
|
function packageVersion(entry = Bun.main) {
|
|
781
|
-
|
|
776
|
+
let resolved = entry;
|
|
777
|
+
try {
|
|
778
|
+
resolved = realpathSync2(entry);
|
|
779
|
+
} catch {}
|
|
780
|
+
for (let dir = dirname2(resolved);; dir = dirname2(dir)) {
|
|
782
781
|
try {
|
|
783
782
|
const { version } = JSON.parse(readFileSync2(join2(dir, "package.json"), "utf8"));
|
|
784
783
|
if (typeof version === "string")
|
|
@@ -1083,8 +1082,8 @@ function printRows(rows) {
|
|
|
1083
1082
|
}
|
|
1084
1083
|
var PASSWORD_USAGE = `dev password [length] [format] [-b|--bcrypt [password]]: a random password of <length> bytes (default ${DEFAULT_LENGTH}) as hex, base64 (default) or base64url
|
|
1085
1084
|
|
|
1086
|
-
Printed on stdout and copied to the clipboard when a tool for it (wl-copy, xclip, xsel, pbcopy) exists (the copy is said on stderr). With --bcrypt it is the bcrypt hash (cost 10) that prints: of the password given, or of a generated one, which then prints on stderr and is the one copied. Bun writes bcrypt as $2b$, the hash prints with the $2y$ prefix htpasswd -B writes, the one Apache, nginx and traefik basic auth all accept
|
|
1087
|
-
|
|
1085
|
+
Printed on stdout and copied to the clipboard when a tool for it (wl-copy, xclip, xsel, pbcopy) exists (the copy is said on stderr). With --bcrypt it is the bcrypt hash (cost 10) that prints: of the password given, or of a generated one, which then prints on stderr and is the one copied. Bun writes bcrypt as $2b$, the hash prints with the $2y$ prefix htpasswd -B writes, the one Apache, nginx and traefik basic auth all accept.`;
|
|
1086
|
+
var PASSWORD_EXITS = [[0, "it printed the password or hash"], [2, "a usage error"]];
|
|
1088
1087
|
var PASSWORD_OPTIONS = {
|
|
1089
1088
|
bcrypt: { type: "string", short: "b", optional: { bare: "" }, description: "print the bcrypt hash of the password given, or of a generated one" },
|
|
1090
1089
|
"no-copy": { type: "boolean", description: "leave the clipboard alone" },
|
|
@@ -1093,6 +1092,7 @@ var PASSWORD_OPTIONS = {
|
|
|
1093
1092
|
var FORMAT_NOTES = { hex: "hexadecimal", base64: "base64", base64url: "url-safe base64" };
|
|
1094
1093
|
async function password(args) {
|
|
1095
1094
|
const { values, positionals } = parse(args, PASSWORD_USAGE, PASSWORD_OPTIONS, {
|
|
1095
|
+
exits: PASSWORD_EXITS,
|
|
1096
1096
|
positionals: ["[length]", "[format]"],
|
|
1097
1097
|
candidates: { "[length]": () => ["16", "24", "32", "48", "64"], "[format]": () => FORMATS.map((format) => [format, FORMAT_NOTES[format]]) },
|
|
1098
1098
|
replaces: 'openssl rand -base64 32 and htpasswd -bnBC 10 "" <password>',
|
|
@@ -1119,14 +1119,15 @@ async function password(args) {
|
|
|
1119
1119
|
}
|
|
1120
1120
|
var JWT_USAGE = `dev jwt [token]: the header and payload of a JWT, with iat, nbf and exp as local and UTC dates and how far from now
|
|
1121
1121
|
|
|
1122
|
-
The token is the argument or what is piped on stdin, a leading "Bearer " is ignored. The signature is not verified
|
|
1123
|
-
|
|
1122
|
+
The token is the argument or what is piped on stdin, a leading "Bearer " is ignored. The signature is not verified.`;
|
|
1123
|
+
var JWT_EXITS = [[0, "it decoded the token"], [1, "it is not a JWT"], [2, "a usage error"]];
|
|
1124
1124
|
var JWT_OPTIONS = {
|
|
1125
1125
|
zone: ZONE_OPTION,
|
|
1126
1126
|
json: jsonOption("{header, payload, claims: [{claim, epoch, local, utc, relative}], signatureBytes}")
|
|
1127
1127
|
};
|
|
1128
1128
|
async function jwt(args) {
|
|
1129
1129
|
const { values, positionals } = parse(args, JWT_USAGE, JWT_OPTIONS, {
|
|
1130
|
+
exits: JWT_EXITS,
|
|
1130
1131
|
positionals: ["[token]"],
|
|
1131
1132
|
replaces: "pasting a token into jwt.io or decoding its segments with base64 and jq",
|
|
1132
1133
|
examples: ["dev jwt eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MDAwMDAwMDB9.c2ln", ["pbpaste | dev jwt --json", "for a script"]]
|
|
@@ -1153,14 +1154,15 @@ ${JSON.stringify(decoded.payload, null, 2)}`);
|
|
|
1153
1154
|
}
|
|
1154
1155
|
var TS_USAGE = `dev ts [value]: a time as local and UTC dates, whatever it is written as
|
|
1155
1156
|
|
|
1156
|
-
The value is epoch seconds or milliseconds (told apart by size: from 1e11 up it is milliseconds), an ISO date or date-time (read in the local zone when it gives none), or a duration such as 90m or 2h30m, shown with the date that far from now. Without a value it is now; "-" reads the value on stdin
|
|
1157
|
-
|
|
1157
|
+
The value is epoch seconds or milliseconds (told apart by size: from 1e11 up it is milliseconds), an ISO date or date-time (read in the local zone when it gives none), or a duration such as 90m or 2h30m, shown with the date that far from now. Without a value it is now; "-" reads the value on stdin.`;
|
|
1158
|
+
var TS_EXITS = [[0, "it converted the value"], [1, "it is none of those"], [2, "a usage error"]];
|
|
1158
1159
|
var TS_OPTIONS = {
|
|
1159
1160
|
zone: ZONE_OPTION,
|
|
1160
1161
|
json: jsonOption("{kind, ms, seconds, local, utc, relative} or, for a duration, {kind, ms, seconds, human, fromNow}")
|
|
1161
1162
|
};
|
|
1162
1163
|
async function ts(args) {
|
|
1163
1164
|
const { values, positionals } = parse(args, TS_USAGE, TS_OPTIONS, {
|
|
1165
|
+
exits: TS_EXITS,
|
|
1164
1166
|
positionals: ["[value]"],
|
|
1165
1167
|
replaces: "date -d @<seconds> and date -u, and doing the milliseconds division by hand",
|
|
1166
1168
|
examples: ["dev ts 1700000000", ["dev ts 2h30m", "the date 2h30m from now"], ["dev ts 2024-05-06T08:09:10Z --zone Europe/Paris", "that instant in Paris"]]
|
|
@@ -1179,12 +1181,12 @@ async function ts(args) {
|
|
|
1179
1181
|
printRows([["local", converted.local], ["utc", converted.utc], ["seconds", String(converted.seconds)], ["ms", String(converted.ms)], ["relative", converted.relative]]);
|
|
1180
1182
|
return 0;
|
|
1181
1183
|
}
|
|
1182
|
-
var UUID_USAGE = `dev uuid [-n <count>] [--v7]: random UUIDs, version 4 or, with --v7, version 7 (time-ordered)
|
|
1183
|
-
|
|
1184
|
-
Exits 0 when it printed them, 2 on a usage error.`;
|
|
1184
|
+
var UUID_USAGE = `dev uuid [-n <count>] [--v7]: random UUIDs, version 4 or, with --v7, version 7 (time-ordered)`;
|
|
1185
|
+
var UUID_EXITS = [[0, "it printed them"], [2, "a usage error"]];
|
|
1185
1186
|
var COUNT_OPTION = { type: "string", short: "n", description: "how many to print (default 1)" };
|
|
1186
1187
|
function uuid(args) {
|
|
1187
1188
|
const { values } = parse(args, UUID_USAGE, { n: COUNT_OPTION, v7: { type: "boolean", description: "a version 7 UUID, which sorts by creation time" }, json: jsonOption('["uuid"]') }, {
|
|
1189
|
+
exits: UUID_EXITS,
|
|
1188
1190
|
positionals: [],
|
|
1189
1191
|
replaces: 'uuidgen and python -c "import uuid"',
|
|
1190
1192
|
examples: ["dev uuid", ["dev uuid -n 5 --v7", "five time-ordered UUIDs"]]
|
|
@@ -1193,11 +1195,11 @@ function uuid(args) {
|
|
|
1193
1195
|
printIds(ids, values.json === true);
|
|
1194
1196
|
return 0;
|
|
1195
1197
|
}
|
|
1196
|
-
var ULID_USAGE = `dev ulid [-n <count>]: random ULIDs, 26 sortable characters of time and randomness
|
|
1197
|
-
|
|
1198
|
-
Exits 0 when it printed them, 2 on a usage error.`;
|
|
1198
|
+
var ULID_USAGE = `dev ulid [-n <count>]: random ULIDs, 26 sortable characters of time and randomness`;
|
|
1199
|
+
var ULID_EXITS = [[0, "it printed them"], [2, "a usage error"]];
|
|
1199
1200
|
function ulidCommand(args) {
|
|
1200
1201
|
const { values } = parse(args, ULID_USAGE, { n: COUNT_OPTION, json: jsonOption('["ulid"]') }, {
|
|
1202
|
+
exits: ULID_EXITS,
|
|
1201
1203
|
positionals: [],
|
|
1202
1204
|
replaces: "installing a ulid package to mint one",
|
|
1203
1205
|
examples: ["dev ulid", ["dev ulid -n 3", "three ULIDs"]]
|
|
@@ -1214,8 +1216,8 @@ function printIds(ids, json) {
|
|
|
1214
1216
|
}
|
|
1215
1217
|
var B64_USAGE = `dev b64 [-d] [--url] [text]: base64 of the text, or with -d the text behind a base64 one
|
|
1216
1218
|
|
|
1217
|
-
The text is the argument or what is piped on stdin, taken as is (a piped trailing newline is encoded, as base64 does). With --url the output is URL-safe and unpadded. Decoding takes either alphabet, padded or not, and writes the raw bytes
|
|
1218
|
-
|
|
1219
|
+
The text is the argument or what is piped on stdin, taken as is (a piped trailing newline is encoded, as base64 does). With --url the output is URL-safe and unpadded. Decoding takes either alphabet, padded or not, and writes the raw bytes.`;
|
|
1220
|
+
var B64_EXITS = [[0, "it printed the result"], [1, "-d is given text that is not base64"], [2, "a usage error"]];
|
|
1219
1221
|
var B64_OPTIONS = {
|
|
1220
1222
|
decode: { type: "boolean", short: "d", description: "decode instead of encode" },
|
|
1221
1223
|
url: { type: "boolean", description: "URL-safe alphabet without padding, when encoding" },
|
|
@@ -1223,6 +1225,7 @@ var B64_OPTIONS = {
|
|
|
1223
1225
|
};
|
|
1224
1226
|
async function b64(args) {
|
|
1225
1227
|
const { values, positionals } = parse(args, B64_USAGE, B64_OPTIONS, {
|
|
1228
|
+
exits: B64_EXITS,
|
|
1226
1229
|
positionals: ["[text]"],
|
|
1227
1230
|
replaces: "base64 and base64 -d, which leave the URL-safe alphabet to tr",
|
|
1228
1231
|
examples: ["dev b64 hello", ["echo aGVsbG8 | dev b64 -d", "decoded, padding optional"]]
|
|
@@ -1245,10 +1248,11 @@ async function b64(args) {
|
|
|
1245
1248
|
}
|
|
1246
1249
|
var URL_USAGE = `dev url [url]: the parts of a URL and its query decoded, one per line
|
|
1247
1250
|
|
|
1248
|
-
The URL is the argument or what is piped on stdin, and has to include its scheme
|
|
1249
|
-
|
|
1251
|
+
The URL is the argument or what is piped on stdin, and has to include its scheme.`;
|
|
1252
|
+
var URL_EXITS = [[0, "it printed the parts"], [1, "the text is not a URL"], [2, "a usage error"]];
|
|
1250
1253
|
async function url(args) {
|
|
1251
1254
|
const { values, positionals } = parse(args, URL_USAGE, { json: jsonOption("{href, protocol, username, password, host, hostname, port, pathname, query: [{key, value}], hash}") }, {
|
|
1255
|
+
exits: URL_EXITS,
|
|
1252
1256
|
positionals: ["[url]"],
|
|
1253
1257
|
replaces: "reading a long query string by eye or decoding it with python urllib",
|
|
1254
1258
|
examples: ['dev url "https://example.com:8443/a%20b?q=x%26y&page=2#top"', ['dev url "https://example.com/?a=1" --json', "for a script"]]
|
|
@@ -1264,11 +1268,11 @@ async function url(args) {
|
|
|
1264
1268
|
printRows([...shown, ...query.map(({ key, value }) => [`?${key}`, value])]);
|
|
1265
1269
|
return 0;
|
|
1266
1270
|
}
|
|
1267
|
-
var HASH_USAGE = `dev hash <sha256|sha1|md5|sha512> [file]: the hex digest of a file, or of what is piped on stdin
|
|
1268
|
-
|
|
1269
|
-
Exits 0 when it printed the digest, 1 when the file does not exist, 2 on a usage error.`;
|
|
1271
|
+
var HASH_USAGE = `dev hash <sha256|sha1|md5|sha512> [file]: the hex digest of a file, or of what is piped on stdin`;
|
|
1272
|
+
var HASH_EXITS = [[0, "it printed the digest"], [1, "the file does not exist"], [2, "a usage error"]];
|
|
1270
1273
|
async function hash(args) {
|
|
1271
1274
|
const { values, positionals } = parse(args, HASH_USAGE, { json: jsonOption("{algorithm, hash, bytes}") }, {
|
|
1275
|
+
exits: HASH_EXITS,
|
|
1272
1276
|
positionals: ["<algorithm>", "[file]"],
|
|
1273
1277
|
candidates: { "<algorithm>": () => [...ALGORITHMS] },
|
|
1274
1278
|
replaces: "sha256sum, sha1sum and md5sum, which print the file name beside the digest",
|
|
@@ -1294,10 +1298,11 @@ async function hash(args) {
|
|
|
1294
1298
|
}
|
|
1295
1299
|
var IP_USAGE = `dev ip [-4|-6]: the public IP address of this host, as a web service sees it
|
|
1296
1300
|
|
|
1297
|
-
-4 or -6 asks over that IP family only, which fails when the host has no route over it
|
|
1298
|
-
|
|
1301
|
+
-4 or -6 asks over that IP family only, which fails when the host has no route over it.`;
|
|
1302
|
+
var IP_EXITS = [[0, "it printed the address"], [1, "the service could not be reached"], [2, "a usage error"]];
|
|
1299
1303
|
async function ip(args) {
|
|
1300
1304
|
const { values } = parse(args, IP_USAGE, { 4: { type: "boolean", short: "4", description: "over IPv4 only" }, 6: { type: "boolean", short: "6", description: "over IPv6 only" }, json: jsonOption("{ip, family?}") }, {
|
|
1305
|
+
exits: IP_EXITS,
|
|
1301
1306
|
replaces: "curl https://ipecho.net/plain typed from memory",
|
|
1302
1307
|
examples: ["dev ip", ["dev ip -6", "the IPv6 address"]]
|
|
1303
1308
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-dev",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"description": "dev: small developer utilities in one bin: random passwords and bcrypt hashes, JWT decoding, timestamps, UUIDs and ULIDs, base64, URL parts and file hashes.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -36,6 +36,6 @@
|
|
|
36
36
|
"dev": "$npm_execpath src/cli.ts"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@kaynooo/cli-kit": "0.38.
|
|
39
|
+
"@kaynooo/cli-kit": "0.38.2"
|
|
40
40
|
}
|
|
41
41
|
}
|