Skip to content

Commit 7f4b4b4

Browse files
fix: fixed help system which was chocking on chalk symbols for commands with argv
1 parent 7e0f3b2 commit 7f4b4b4

File tree

16 files changed

+68
-52
lines changed

16 files changed

+68
-52
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@
135135
},
136136
"pnpm": {
137137
"overrides": {
138-
"simple-git@<3.3.0": ">=3.3.0",
139-
"simple-git@<3.5.0": ">=3.5.0",
140-
"sharp@<0.30.5": ">=0.30.5"
138+
"simple-git@<3.5.0": ">=3.5.0"
141139
}
142140
}
143141
}

pnpm-lock.yaml

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commands/autoindex/parts/autoindex.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { getMonoRepoPackages, getSubdirectories } from "src/shared/file";
2020
* the file's current directory
2121
*/
2222
export const handler: DoDevopsHandler<IAutoindexOptions> = async ({ opts, observations, argv }) => {
23+
2324
// the sfc flag on CLI is inverted logically
2425
opts = {
2526
...opts,
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import chalk from "chalk";
1+
22
import { IDoDevopsCommand } from "src/@types";
3-
const autoindex = chalk.bgWhite.black`autoindex`;
3+
// const autoindex = chalk.bgWhite.black`autoindex`;
4+
// const autoindexComment = chalk.bgWhiteBright.blackBright`// autoindex`;
45

56
export const description: IDoDevopsCommand["description"] = {
6-
short: `Automates the building of ${chalk.italic`index.ts`} files to aggregate folder's content`,
7-
complete: `Automates the building of ${chalk.italic`index`} files; if you include a comment starting with ${chalk.bold.yellow`\n// #autoindex\n`}in a index file it will be auto-indexed when calling ${chalk.blue`do autoindex`}.
8-
9-
By default ${autoindex} will assume that you are using ${chalk.italic`named`} exports but this can be configured to what you need. Options are: ${chalk.italic`named, default,`} and ${chalk.italic`named-offset`}. To configure, simply add something like ${chalk.bold.yellow`\n// #autoindex:default\n`}to your file.
10-
11-
If you need to exclude certain files you can state the exclusions after the autoindex declaration: ${chalk.bold.yellow`#autoindex, exclude:a,b,c`}`,
7+
short: `Automates the building of index files`,
8+
complete: `Automates the building of index files`
129
};
10+
11+
12+
// {
13+
// short: `Automates the building of ${chalk.italic`index.[ts | js]`} files`,
14+
// complete: `Automates the building of ${chalk.italic`index`} files in a given repo.
15+
16+
// Any index file (JS or TS) which is either completely empty ${chalk.italic`or`} contains a comment
17+
// which looks has a line that starts with ${autoindexComment} will be managed by the ${autoindex}
18+
// command.`,
19+
// };

src/commands/autoindex/parts/options.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import chalk from "chalk";
21
import { IOptionDefinition } from "src/@types/option-types";
32

43
export interface IAutoindexOptions {
54
config: boolean;
65
add: string;
76
glob: string;
7+
/**
8+
* Reports what would happen _if_ you were to run the command without actually making any changes
9+
*/
810
dryRun: boolean;
911
/**
1012
* boolean flag to indicate whether VueJS SFC files should have their default
@@ -35,7 +37,7 @@ export const options: IOptionDefinition = {
3537
multiple: true,
3638
type: String,
3739
group: "local",
38-
description: `${chalk.italic`optionally`} state one or more explicit autoindex files to evaluate instead of glob patterns`,
40+
description: `optionally state one or more explicit autoindex files to evaluate instead of glob patterns`,
3941
typeLabel: "string[]",
4042
},
4143

@@ -71,7 +73,7 @@ export const options: IOptionDefinition = {
7173
alias: "w",
7274
type: Boolean,
7375
group: "local",
74-
description: `watches for changes and runs ${chalk.italic`autoindex`} when detected`,
76+
description: `watches for changes and runs autoindex when detected`,
7577
},
7678
force: {
7779
alias: "f",
@@ -84,6 +86,6 @@ export const options: IOptionDefinition = {
8486
alias: "p",
8587
type: Boolean,
8688
group: "local",
87-
description: `exports -- by default -- will ${chalk.italic`not`} include the file's ${chalk.blue`.js`} extension but sometimes with ES modules you want to include this. If you do then you should set this flag.`,
89+
description: `by default exports do not include the file's .js extension but sometimes with ES modules you want to include this. If you do then you should set this flag.`,
8890
},
8991
};

src/commands/info/parts/thisRepo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from "src/shared/git";
1616
import { askConfirmQuestion, resolvePackageManagerConflict } from "src/shared/interactive";
1717
import { getExternalPackageJson, getPackageJson } from "src/shared/npm";
18-
import { dim, emoji, green } from "src/shared/ui";
18+
import { emoji, green } from "src/shared/ui";
1919
import { monorepoInfo } from "./components/monorepo";
2020
import { currentDirectory } from "src/shared/file/base-paths/currentDirectory";
2121
import { symlinks } from "src/shared/file/utility/symlinks";

src/dd.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { isDevopsError } from "./@type-guards";
5757
// Show help on the command
5858
if (cmdInput.opts.help) {
5959
commandAnnouncement(cmdDefn, cmdInput);
60+
6061
help(observations, cmdDefn);
6162
process.exit();
6263
}

src/shared/core/help.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export function help(
2929
options: globalOptions,
3030
} as Finalized<IDoDevopsCommand>);
3131

32+
console.log({kind,subCommands,description,syntax,options});
33+
34+
3235
const sections: commandLineUsage.Section[] = [
3336
{
3437
header: "Description",

src/shared/core/helpContent.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ import { getObservations } from "../observations";
1818
* command. If not provided a default syntax will be used.
1919
*/
2020
export function getSyntax(fn?: string): string {
21-
if (!fn) {
22-
return "dd [command] <options>";
23-
} else {
21+
if (fn) {
2422
const validCommands = keys(commands);
2523
if ((validCommands as string[]).includes(fn)) {
2624
const defn: IDoDevopsCommand<any> = commands[fn as keyof typeof commands];
2725
const hasSubCommands = defn?.subCommands ? true : false;
2826
return defn.syntax ?? `do ${fn} ${hasSubCommands ? "[command] " : ""}`;
2927
} else {
30-
return `dd [command] <options>\nnote: the command {red ${fn}} is not recognized!`;
28+
const fnName = chalk.red(fn);
29+
return `dd [command] <options>\nnote: the command ${fnName} is not recognized!`;
3130
}
31+
} else {
32+
return "dd [command] <options>";
3233
}
3334
}
3435

src/shared/core/parseCmdArgs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export function parseCmdArgs(cmd: IDoDevopsCommand, incomingArgv: string[]) {
4949
}
5050
);
5151

52-
// opts come from both "local" and "global" options
53-
const opts = { ...(global ? global : {}), ...(local ? local : {}) };
52+
// combine "local" and "global" options
53+
const opts = { ...global, ...local };
5454

5555
const sc = subCommand ? (cmd.greedy ? subCommand?.command[0] : subCommand?.command) : undefined;
5656

src/shared/core/util/argv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { IDoDevopsCommand } from "src/@types/command";
33
import { IOptionDefinition } from "src/@types/option-types";
44

55
/**
6-
* Determines if a given commmand has an `argv` parameter
6+
* Determines if a given command has an `argv` parameter
77
*/
88
export function hasArgv(cmd: IDoDevopsCommand<any>) {
99
return !Object.keys(cmd?.options || {}).every(

src/shared/core/util/commandAnnouncement.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,26 @@ import { doDevopsVersion } from "./doDevopsVersion";
1010
export function commandAnnouncement(cmdDefn?: IDoDevopsCommand, cmd?: ICommandParsing) {
1111
const log = logger(cmd ? cmd.opts : {});
1212
const version = doDevopsVersion();
13-
14-
const argv = cmd && cmd.argv.length > 0 ? ` ${chalk.italic(cmd.argv.join(" "))}` : "";
15-
13+
const argv = cmd && cmd.argv.length > 0
14+
? chalk.italic` ${cmd.argv.join(" ")}`
15+
: "";
16+
1617
const subCmd = cmd && cmd.subCommand ? chalk.dim` ${cmd.subCommand}` : "";
1718

1819
const helpText =
1920
(!cmdDefn && !cmd) || (cmd && cmd.opts?.help)
2021
? cmdDefn
21-
? chalk.gray` [help, v${version}]`
22-
: chalk.gray` v${version}`
22+
? ` [ help, v${version} ]`
23+
: ` v${version}`
2324
: "";
2425

26+
const brand = cmdDefn
27+
? chalk.green.italic.bold(`${cmdDefn.kind}${subCmd}${argv}`)
28+
: chalk.green.italic.bold("Help");
29+
2530
log.info(
2631
chalk.bold(
27-
`\ndo-devops ${chalk.green.italic.bold(
28-
cmdDefn ? `${cmdDefn.kind}${subCmd}${argv}` : "Help"
29-
)}${helpText}\n`
32+
`\ndo-devops ${brand}${chalk.gray(helpText)}\n`
3033
)
3134
);
3235
}

src/shared/core/util/finalizeCommandDefinition.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ export function finalizeCommandDefinition(
3434
? cmdDefn.subCommands(observations, options)
3535
: cmdDefn.subCommands;
3636

37-
const argv = hasArgv(cmdDefn) ? chalk.italic.dim` argv[]}}` : "";
37+
const argv = hasArgv(cmdDefn) ? chalk.italic.dim` argv[]` : "";
38+
const argvStatic = chalk.bold.blue("[argv]:");
39+
console.log({argvOption: getArgvOption(cmdDefn)?.description, argvStatic});
40+
3841
const argvDescription = getArgvOption(cmdDefn)?.description
39-
? `\n\n\t\t${chalk.bold.blue`[argv]:`} ${getArgvOption(cmdDefn)?.description}`
42+
? `\n\n\t\t${argvStatic} ${getArgvOption(cmdDefn)?.description}`
4043
: "";
4144

4245
const subCommandSyntax =
@@ -51,7 +54,7 @@ export function finalizeCommandDefinition(
5154
handler: cmdDefn.handler,
5255
syntax:
5356
cmdDefn.syntax ||
54-
`dd ${cmdDefn.kind}${subCommandSyntax}${argv} [${chalk.italic`options`}]${argvDescription}`,
57+
`dd ${cmdDefn.kind}${subCommandSyntax}${argv} [${chalk.dim.italic`options`}]${argvDescription}`,
5558
description,
5659
subCommands,
5760
options: { ...cmdDefn.options, ...globalOptions },

src/shared/file/crud/write.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { IWriteOptions } from "src/@types";
55
import { interpolateFilePath } from "../../../shared/file/helpers";
66
import path from "node:path";
77
import { isClassification } from "../../../@type-guards";
8+
import chalk from "chalk";
89

910
/**
1011
* **write**
@@ -31,7 +32,7 @@ export function write(filename: string, data: any, options: IWriteOptions = {})
3132

3233
filename = interpolateFilePath(filename);
3334

34-
// avoid collisions if offset avoidence is enabled
35+
// avoid collisions if offset avoidance is enabled
3536
let offset: number | undefined;
3637
while (options.offsetIfExists && fileExists(filename)) {
3738
const before = new RegExp(`-${offset}.(.*)$`);

src/shared/ui/highlightFilepath.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ export function highlightFilepath(
3737
? chalk[highForeground]`${file}}`
3838
: `${file}}`;
3939

40-
return `${filePath}${fileName}`;
40+
return `${fp}${fileName}`;
4141
}

test/hashcode.spec.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
import { describe, it, expect, beforeAll } from "vitest";
2-
import xxhash, { Exports } from "xxhash-wasm";
1+
import { describe, it, expect } from "vitest";
2+
import xxhash from "xxhash-wasm";
3+
const { h32 } = await xxhash();
4+
35

46
describe("Validate that same inputs produce same hash", () => {
57
const person1 = { id: 1, name: "Bob", age: 35 };
68
const person2 = { id: 2, name: "Jane", age: 22 };
79
const person3 = { id: 3, name: "Max", age: 12 };
8-
let xx: Exports["h32"];
9-
beforeAll(async () => {
10-
const { h32 } = await xxhash();
11-
xx = h32;
12-
});
1310

1411
it("different data is different with same seed", () => {
15-
const t1 = xx(JSON.stringify(person1), 0xCA_FE_BA_BE);
16-
const t2 = xx(JSON.stringify(person2), 0xCA_FE_BA_BE);
17-
const t3 = xx(JSON.stringify(person3), 0xCA_FE_BA_BE);
12+
const t1 = h32(JSON.stringify(person1), 0xCA_FE_BA_BE);
13+
const t2 = h32(JSON.stringify(person2), 0xCA_FE_BA_BE);
14+
const t3 = h32(JSON.stringify(person3), 0xCA_FE_BA_BE);
1815

1916
expect(t1).not.toBe(t2);
2017
expect(t1).not.toBe(t3);
@@ -23,9 +20,9 @@ describe("Validate that same inputs produce same hash", () => {
2320
});
2421

2522
it("same hash is always the same, even with same seed", () => {
26-
const t1 = xx(JSON.stringify(person1), 0xCA_FE_BA_BE);
27-
const t2 = xx(JSON.stringify(person1), 0xCA_FE_BA_BE);
28-
const t3 = xx(JSON.stringify(person1), 0xCA_FE_BA_BE);
23+
const t1 = h32(JSON.stringify(person1), 0xCA_FE_BA_BE);
24+
const t2 = h32(JSON.stringify(person1), 0xCA_FE_BA_BE);
25+
const t3 = h32(JSON.stringify(person1), 0xCA_FE_BA_BE);
2926

3027
expect(t1).toBe(t2);
3128
expect(t1).toBe(t3);

0 commit comments

Comments
 (0)