This commit is contained in:
parent
3b284484c2
commit
438884b270
2 changed files with 11 additions and 16 deletions
|
@ -5,35 +5,30 @@ export default class OutputHelper {
|
||||||
public static GenerateOutput(response: IReturnResult, options: ICliOptions): string {
|
public static GenerateOutput(response: IReturnResult, options: ICliOptions): string {
|
||||||
const result = response.Result!;
|
const result = response.Result!;
|
||||||
|
|
||||||
let outputObject = {};
|
let outputObject: any = {};
|
||||||
|
|
||||||
outputObject = { ...result };
|
outputObject = { ...result };
|
||||||
|
|
||||||
if (options.queryMetadata) {
|
if (options.queryMetadata) {
|
||||||
this.AppendObject(outputObject, response.Query, "query");
|
outputObject = { ...outputObject, ...response.Query }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.json) {
|
if (options.json) {
|
||||||
return JSON.stringify(outputObject);
|
return JSON.stringify(outputObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.GetFriendlyObjectText(outputObject, "");
|
return this.GetFriendlyObjectText(outputObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
private static GetFriendlyObjectText(object: any, output: string, prefix: string = ""): string {
|
private static GetFriendlyObjectText(object: any): string {
|
||||||
for (const key in object) {
|
let output = "";
|
||||||
if (typeof(object[key]) == "object")
|
|
||||||
return this.GetFriendlyObjectText(object[key], output, `${key}.`);
|
|
||||||
|
|
||||||
output += `${prefix}${key} = ${object[key]}\n`;
|
for (const key in object) {
|
||||||
|
output += `${key} = ${object[key]}\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AppendObject(a: any, b: any, target: string): any {
|
|
||||||
a[target] = { ...b };
|
|
||||||
}
|
|
||||||
/* eslint-enable @typescript-eslint/no-explicit-any */
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
||||||
}
|
}
|
|
@ -16,7 +16,7 @@ Url = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s
|
||||||
|
|
||||||
exports[`GenerateOutput GIVEN options.json is true, EXPECT output to be returned as JSON 1`] = `"{"Archived":false,"Author":"author","Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/","Subreddit":"Rabbits","SubredditSubscribers":654751,"Title":"This is my Ms Bear!","Ups":17,"Url":"https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d"}"`;
|
exports[`GenerateOutput GIVEN options.json is true, EXPECT output to be returned as JSON 1`] = `"{"Archived":false,"Author":"author","Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/","Subreddit":"Rabbits","SubredditSubscribers":654751,"Title":"This is my Ms Bear!","Ups":17,"Url":"https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d"}"`;
|
||||||
|
|
||||||
exports[`GenerateOutput GIVEN options.queryMetadata AND options.json is supplied, EXPECT query metadata to be in JSON format 1`] = `"{"Archived":false,"Author":"author","Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/","Subreddit":"Rabbits","SubredditSubscribers":654751,"Title":"This is my Ms Bear!","Ups":17,"Url":"https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d","query":{"subreddit":"rabbits","sortBy":"hot","limit":100}}"`;
|
exports[`GenerateOutput GIVEN options.queryMetadata AND options.json is supplied, EXPECT query metadata to be in JSON format 1`] = `"{"Archived":false,"Author":"author","Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/","Subreddit":"Rabbits","SubredditSubscribers":654751,"Title":"This is my Ms Bear!","Ups":17,"Url":"https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d","subreddit":"rabbits","sortBy":"hot","limit":100}"`;
|
||||||
|
|
||||||
exports[`GenerateOutput GIVEN options.queryMetadata is supplied, EXPECT query metadata to be added 1`] = `
|
exports[`GenerateOutput GIVEN options.queryMetadata is supplied, EXPECT query metadata to be added 1`] = `
|
||||||
"Archived = false
|
"Archived = false
|
||||||
|
@ -29,8 +29,8 @@ SubredditSubscribers = 654751
|
||||||
Title = This is my Ms Bear!
|
Title = This is my Ms Bear!
|
||||||
Ups = 17
|
Ups = 17
|
||||||
Url = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d
|
Url = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d
|
||||||
query.subreddit = rabbits
|
subreddit = rabbits
|
||||||
query.sortBy = hot
|
sortBy = hot
|
||||||
query.limit = 100
|
limit = 100
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
Loading…
Reference in a new issue