random-bunny/src/helpers/outputHelper.ts
Ethan Lane 3b2da358b3
All checks were successful
Stage / build (push) Successful in 9s
Stage / rsync (push) Successful in 6s
Fix bug where you weren't able to use both the -q and -j flags at the same time (#227)
- Fix bug where if you supplied both `-q`/`--query-metadata` and `-j`/`--json` the query metadata wasn't added to the output
- Update tests

#181

Reviewed-on: #227
Reviewed-by: VylpesTester <tester@vylpes.com>
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
2024-12-07 22:21:43 +00:00

32 lines
No EOL
857 B
TypeScript

import ICliOptions from "../contracts/ICliOptions";
import IReturnResult from "../contracts/IReturnResult";
export default class OutputHelper {
public static GenerateOutput(response: IReturnResult, options: ICliOptions): string {
const result = response.Result!;
let outputObject = {};
outputObject = { ...result };
if (options.queryMetadata) {
outputObject = { ...outputObject, ...response.Query }
}
if (options.json) {
return JSON.stringify(outputObject);
}
return this.GetFriendlyObjectText(outputObject);
}
private static GetFriendlyObjectText<T>(object: T): string {
const output: string[] = [];
for (const key in object) {
output.push(`${key} = ${object[key]}`);
}
return output.join("\n");
}
}