Skip to content

Commit

Permalink
changed the logging to log created bookmarks as an array
Browse files Browse the repository at this point in the history
switch all log output that is just a status to stderr
  • Loading branch information
kamtschatka committed May 26, 2024
1 parent 9cf601a commit e2a76ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
16 changes: 12 additions & 4 deletions apps/cli/src/commands/bookmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,23 @@ bookmarkCmd
.action(async (opts) => {
const api = getAPIClient();

const results: object[] = [];

const promises = [
...opts.link.map((url) =>
api.bookmarks.createBookmark
.mutate({ type: "link", url })
.then(printBookmark)
.then((bookmark: ZBookmark) => {
results.push(normalizeBookmark(bookmark));
})
.catch(printError(`Failed to add a link bookmark for url "${url}"`)),
),
...opts.note.map((text) =>
api.bookmarks.createBookmark
.mutate({ type: "text", text })
.then(printBookmark)
.then((bookmark: ZBookmark) => {
results.push(normalizeBookmark(bookmark));
})
.catch(
printError(
`Failed to add a text bookmark with text "${text.substring(0, 50)}"`,
Expand All @@ -82,7 +88,9 @@ bookmarkCmd
promises.push(
api.bookmarks.createBookmark
.mutate({ type: "text", text })
.then(printBookmark)
.then((bookmark: ZBookmark) => {
results.push(normalizeBookmark(bookmark));
})
.catch(
printError(
`Failed to add a text bookmark with text "${text.substring(0, 50)}"`,
Expand All @@ -91,8 +99,8 @@ bookmarkCmd
);
}

// TODO: if you choose JSON output, the output would be multiple JSONs and not a single one, so it would not be parsable --> change behavior?
await Promise.allSettled(promises);
printObject(results);
});

bookmarkCmd
Expand Down
17 changes: 2 additions & 15 deletions apps/cli/src/lib/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,8 @@ export function printObject(
*/
export function printStatusMessage(success: boolean, message: unknown): void {
const status = success ? "Success" : "Error";
if (getGlobalOptions().json) {
console.log(
JSON.stringify(
{
status,
message,
},
null,
4,
),
);
} else {
const colorFunction = success ? chalk.green : chalk.red;
console.log(colorFunction(`${status}: ${message}`));
}
const colorFunction = success ? chalk.green : chalk.red;
console.error(colorFunction(`${status}: ${message}`));
}

/**
Expand Down

0 comments on commit e2a76ab

Please sign in to comment.