Compare commits
No commits in common. "feature/181-q-json-flags" and "master" have entirely different histories.
feature/18
...
master
6 changed files with 363 additions and 379 deletions
|
@ -9,12 +9,13 @@ The project can be downloaded as a binary for your system via the [GitHub Releas
|
|||
We currently support:
|
||||
- Linux (x64)
|
||||
- Windows (x64)
|
||||
- macOS (x64, Arm64\*)
|
||||
|
||||
The git repository can also be cloned and ran via `yarn build` and `yarn start`.
|
||||
|
||||
You can produce the binary using the `yarn package` command. This creates the binaries in the `./bin` folder.
|
||||
|
||||
> **NOTE:** As of version 2.4 I will no longer be supporting and building macOS builds as I have no capacity to test and build for it.
|
||||
> **NOTE:** We are aware of a bug in the macOS Arm64 builds failing to execute. For now you're still able to use the x64 builds under Rosetta fine. This will hopefully be fixed in a future release.
|
||||
|
||||
## Default Output
|
||||
|
||||
|
|
16
package.json
16
package.json
|
@ -43,20 +43,24 @@
|
|||
"@eslint/js": "^9.8.0",
|
||||
"@types/eslint": "^9.6.0",
|
||||
"@types/jest": "^29.5.8",
|
||||
"@types/node": "^22.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
||||
"@typescript-eslint/parser": "^8.0.0",
|
||||
"@types/node": "^20.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
||||
"@typescript-eslint/parser": "^7.18.0",
|
||||
"@yao-pkg/pkg": "^5.12.0",
|
||||
"eslint": "^9.8.0",
|
||||
"jest": "^29.7.0",
|
||||
"jest-mock-extended": "^3.0.7",
|
||||
"jest-mock-extended": "^3.0.3",
|
||||
"np": "^10.0.0",
|
||||
"ts-jest": "^29.1.1",
|
||||
"ts-mockito": "^2.6.1",
|
||||
"typescript": "^5.0.0",
|
||||
"typescript-eslint": "^7.18.0"
|
||||
},
|
||||
"resolutions": {},
|
||||
"resolutions": {
|
||||
"np/**/got": "^14.0.0",
|
||||
"**/semver": "^7.5.2",
|
||||
"@babel/traverse": "^7.23.2"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
|
@ -64,6 +68,8 @@
|
|||
"scripts": "dist/**/*.js",
|
||||
"targets": [
|
||||
"latest-linux-x64",
|
||||
"latest-macos-x64",
|
||||
"latest-macos-arm64",
|
||||
"latest-win-x64"
|
||||
],
|
||||
"outputPath": "bin"
|
||||
|
|
|
@ -5,30 +5,29 @@ 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 }
|
||||
}
|
||||
const outputLines: string[] = [];
|
||||
|
||||
if (options.json) {
|
||||
return JSON.stringify(outputObject);
|
||||
return JSON.stringify(result);
|
||||
}
|
||||
|
||||
return this.GetFriendlyObjectText(outputObject);
|
||||
}
|
||||
outputLines.push(`Archived = ${result.Archived}`);
|
||||
outputLines.push(`Author = ${result.Author}`);
|
||||
outputLines.push(`Downvotes = ${result.Downs}`);
|
||||
outputLines.push(`Hidden = ${result.Hidden}`);
|
||||
outputLines.push(`Permalink = ${result.Permalink}`);
|
||||
outputLines.push(`Subreddit = ${result.Subreddit}`);
|
||||
outputLines.push(`Subreddit Subscribers = ${result.SubredditSubscribers}`);
|
||||
outputLines.push(`Title = ${result.Title}`);
|
||||
outputLines.push(`Upvotes = ${result.Ups}`);
|
||||
outputLines.push(`Url = ${result.Url}`);
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
private static GetFriendlyObjectText(object: any): string {
|
||||
const output: string[] = [];
|
||||
|
||||
for (const key in object) {
|
||||
output.push(`${key} = ${object[key]}`);
|
||||
if (options.queryMetadata != null) {
|
||||
outputLines.push(`Query.Subreddit = ${response.Query.subreddit}`);
|
||||
outputLines.push(`Query.Sort By = ${response.Query.sortBy}`);
|
||||
outputLines.push(`Query.Limit = ${response.Query.limit}`);
|
||||
}
|
||||
|
||||
return output.join("\n");
|
||||
return outputLines.join("\n");
|
||||
}
|
||||
/* eslint-enable @typescript-eslint/no-explicit-any */
|
||||
}
|
|
@ -3,32 +3,30 @@
|
|||
exports[`GenerateOutput EXPECT standout output to be returned 1`] = `
|
||||
"Archived = false
|
||||
Author = author
|
||||
Downs = 0
|
||||
Downvotes = 0
|
||||
Hidden = false
|
||||
Permalink = /r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/
|
||||
Subreddit = Rabbits
|
||||
SubredditSubscribers = 654751
|
||||
Subreddit Subscribers = 654751
|
||||
Title = This is my Ms Bear!
|
||||
Ups = 17
|
||||
Upvotes = 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","subreddit":"rabbits","sortBy":"hot","limit":100}"`;
|
||||
|
||||
exports[`GenerateOutput GIVEN options.queryMetadata is supplied, EXPECT query metadata to be added 1`] = `
|
||||
"Archived = false
|
||||
Author = author
|
||||
Downs = 0
|
||||
Downvotes = 0
|
||||
Hidden = false
|
||||
Permalink = /r/Rabbits/comments/1dj8pbt/this_is_my_ms_bear/
|
||||
Subreddit = Rabbits
|
||||
SubredditSubscribers = 654751
|
||||
Subreddit Subscribers = 654751
|
||||
Title = This is my Ms Bear!
|
||||
Ups = 17
|
||||
Upvotes = 17
|
||||
Url = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d
|
||||
subreddit = rabbits
|
||||
sortBy = hot
|
||||
limit = 100"
|
||||
Query.Subreddit = rabbits
|
||||
Query.Sort By = hot
|
||||
Query.Limit = 100"
|
||||
`;
|
||||
|
|
|
@ -102,39 +102,4 @@ describe("GenerateOutput", () => {
|
|||
// Assert
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test("GIVEN options.queryMetadata AND options.json is supplied, EXPECT query metadata to be in JSON format", () => {
|
||||
// Arrange
|
||||
const response = {
|
||||
IsSuccess: true,
|
||||
Query: {
|
||||
subreddit: "rabbits",
|
||||
sortBy: "hot",
|
||||
limit: 100,
|
||||
},
|
||||
Result: {
|
||||
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",
|
||||
},
|
||||
} as IReturnResult;
|
||||
|
||||
const options = {
|
||||
json: true,
|
||||
queryMetadata: true,
|
||||
} as ICliOptions;
|
||||
|
||||
// Act
|
||||
const result = OutputHelper.GenerateOutput(response, options);
|
||||
|
||||
// Assert
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue