Skip to content

Commit

Permalink
fix: fix handling args in command handlers (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mararok authored Oct 2, 2024
1 parent f50841d commit 88258a6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "5.4.5"
"typescript": "5.6.2"
},
"files": [
"bin",
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Generate/GenerateCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class GenerateCommandHandler extends AbstractCommandHandler<GenerateComma
this.generatorChoices = Array.from(generators.values()).map(g => g.choice);
}

public execute(options: GenerateCommandOptions, _args: string[]): AR<void> {
public execute(options: GenerateCommandOptions): AR<void> {
if (!this.helpers.isMonorepo()) {
printError('Current directory is not Monorepo(Nx)');
process.exit(1);
Expand All @@ -34,7 +34,7 @@ export class GenerateCommandHandler extends AbstractCommandHandler<GenerateComma
initial: 0,
choices: this.generatorChoices,
suggest(input: string, choices: Choice[]) {
const found = choices.filter((c) => (c.name as string).toLowerCase().startsWith(input));
const found = choices.filter((c) => c.name.toLowerCase().startsWith(input));
return found;
}
}));
Expand Down
9 changes: 4 additions & 5 deletions src/Command/Package/PackageBumpVersionCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@ import { Changelog } from '../../Util/Changelog/Changelog';

interface PackageBumpVersionCommandOptions {
dryRun?: true;
newVersion: string;
releaseDate?: string;
}

@injectable()
export class PackageBumpVersionCommandHandler extends AbstractCommandHandler<PackageBumpVersionCommandOptions> {
public execute(options: PackageBumpVersionCommandOptions, _args: string[]): AR<void> {
public execute(options: PackageBumpVersionCommandOptions, newVersion: string): AR<void> {
return this.helpers.fs.readJson('package.json').onOk(packageJson => {
packageJson.version = options.newVersion;
packageJson.version = newVersion;
const repositoryUrl = this.extractReposiotryUrlFromPackageJson(packageJson);
if (repositoryUrl.isError()) {
return ERR(repositoryUrl.e);
}
const releaseDate: string = options.releaseDate ?? LocalDate.now(ZoneOffset.UTC).toString();

const updatedChangelog = this.updateChangelog(repositoryUrl.v, options.newVersion, releaseDate);
const updatedChangelog = this.updateChangelog(repositoryUrl.v, newVersion, releaseDate);
return this.save([
{ path: 'package.json', content: JSON.stringify(packageJson, null, 2) },
{ path: 'package.json', content: JSON.stringify(packageJson, null, 2) + '\n' },
{ path: 'CHANGELOG.md', content: updatedChangelog },
], options.dryRun);
}).onOk(() => true as any);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Pulumi/PulumiGenerateProjectCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const PULUMI_PROJECTS_DIR = 'projects';
@injectable()
export class PulumiGenerateProjectCommandHandler extends AbstractCommandHandler<PulumiGenerateProjectCommandOptions> {

public execute(options: PulumiGenerateProjectCommandOptions, _args: string[]): AR<void> {
public execute(options: PulumiGenerateProjectCommandOptions): AR<void> {
return this.prompt().onOk((promptResult) => {
const project = promptResult.project;
const projectPath = PULUMI_PROJECTS_DIR + '/' + project;
Expand Down
2 changes: 1 addition & 1 deletion src/Util/Cli/AbstractCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import type { AR } from '@hexancore/common';
export abstract class AbstractCommandHandler<O extends Record<string, any>> {
public constructor(protected helpers: CommonHelpers) { }

public abstract execute(options: O, args: string[]): AR<void>;
public abstract execute(options: O, ...args: string[]): AR<void>;
}
3 changes: 2 additions & 1 deletion src/Util/Cli/CliBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export class CliBuilder {
}

private createActionHandlerOfCommandHandler(handler: AbstractCommandHandler<any>): any {
return this.actionWrapper((args: string[], options: Record<string, any>) => handler.execute(options, args) as any);

return this.actionWrapper((args: string[], options: Record<string, any>) => handler.execute(options, ...args) as any);
}

private actionWrapper(action: (args: string[], options: Record<string, any>) => AR<void>): ((...args: any[]) => Promise<void>) {
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ __metadata:
ts-node: "npm:^10.9.1"
tsconfig-paths: "npm:^4.2.0"
tslib: "npm:^2.6.3"
typescript: "npm:5.4.5"
typescript: "npm:5.6.2"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -5166,23 +5166,23 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:5.4.5":
version: 5.4.5
resolution: "typescript@npm:5.4.5"
"typescript@npm:5.6.2":
version: 5.6.2
resolution: "typescript@npm:5.6.2"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/2954022ada340fd3d6a9e2b8e534f65d57c92d5f3989a263754a78aba549f7e6529acc1921913560a4b816c46dce7df4a4d29f9f11a3dc0d4213bb76d043251e
checksum: 10c0/3ed8297a8c7c56b7fec282532503d1ac795239d06e7c4966b42d4330c6cf433a170b53bcf93a130a7f14ccc5235de5560df4f1045eb7f3550b46ebed16d3c5e5
languageName: node
linkType: hard

"typescript@patch:typescript@npm%3A5.4.5#optional!builtin<compat/typescript>":
version: 5.4.5
resolution: "typescript@patch:typescript@npm%3A5.4.5#optional!builtin<compat/typescript>::version=5.4.5&hash=5adc0c"
"typescript@patch:typescript@npm%3A5.6.2#optional!builtin<compat/typescript>":
version: 5.6.2
resolution: "typescript@patch:typescript@npm%3A5.6.2#optional!builtin<compat/typescript>::version=5.6.2&hash=379a07"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/db2ad2a16ca829f50427eeb1da155e7a45e598eec7b086d8b4e8ba44e5a235f758e606d681c66992230d3fc3b8995865e5fd0b22a2c95486d0b3200f83072ec9
checksum: 10c0/e6c1662e4852e22fe4bbdca471dca3e3edc74f6f1df043135c44a18a7902037023ccb0abdfb754595ca9028df8920f2f8492c00fc3cbb4309079aae8b7de71cd
languageName: node
linkType: hard

Expand Down

0 comments on commit 88258a6

Please sign in to comment.