Skip to content

Commit

Permalink
Merge branch 'go_improvements' of https://github.com/asyncapi/modelina
Browse files Browse the repository at this point in the history
…into improve_go
  • Loading branch information
jonaslagoni committed Jan 24, 2025
2 parents a0fc9f1 + 8a06f1a commit 6d300f6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
3 changes: 2 additions & 1 deletion modelina-cli/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/lib
/tmp
/scripts
/test/helpers/init.js
/test/helpers/init.js
/test/fixtures/generate
4 changes: 2 additions & 2 deletions modelina-cli/src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export default class Models extends ModelinaCommand {
try {
document = await readFile(file, 'utf8');
} catch {
throw new Error('Unable to read input file content.');
throw new Error(`Unable to read input file content: ${file}`);
}

const logger = {
info: (message: string) => {
this.log(message);
Expand Down
29 changes: 24 additions & 5 deletions modelina-cli/src/helpers/go.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { GoFileGenerator } from "@asyncapi/modelina";
import { GO_DESCRIPTION_PRESET, GO_COMMON_PRESET, GoCommonPresetOptions, GoFileGenerator } from "@asyncapi/modelina";
import { BuilderReturnType } from "./generate";
import { Flags } from "@oclif/core";

export const GoOclifFlags = { }
export const GoOclifFlags = {
goIncludeComments: Flags.boolean({
description: 'Golang specific, if enabled add comments while generating models.',
required: false,
default: false,
}),
goIncludeTags: Flags.boolean({
description: 'Golang specific, if enabled add tags while generating models.',
required: false,
default: false,
}),
}

/**
* This function builds all the relevant information for the main generate command
Expand All @@ -10,13 +22,20 @@ export const GoOclifFlags = { }
* @returns
*/
export function buildGoGenerator(flags: any): BuilderReturnType {
const { packageName } = flags;
const { packageName, goIncludeComments, goIncludeTags } = flags;

if (packageName === undefined) {
throw new Error('In order to generate models to Go, we need to know which package they are under. Add `--packageName=PACKAGENAME` to set the desired package name.');
}

const fileGenerator = new GoFileGenerator();
const presets = []
if (goIncludeTags) {
const options: GoCommonPresetOptions = { addJsonTag: true };
presets.push({ preset: GO_COMMON_PRESET, options })
}

if (goIncludeComments) { presets.push(GO_DESCRIPTION_PRESET); }
const fileGenerator = new GoFileGenerator({ presets });
const fileOptions = {
packageName
};
Expand Down

0 comments on commit 6d300f6

Please sign in to comment.