diff --git a/apps/cli/src/commands/bookmarks.ts b/apps/cli/src/commands/bookmarks.ts index b3ab5f22..40442ec1 100644 --- a/apps/cli/src/commands/bookmarks.ts +++ b/apps/cli/src/commands/bookmarks.ts @@ -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)}"`, @@ -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)}"`, @@ -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 diff --git a/apps/cli/src/lib/output.ts b/apps/cli/src/lib/output.ts index 50000408..34d86461 100644 --- a/apps/cli/src/lib/output.ts +++ b/apps/cli/src/lib/output.ts @@ -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}`)); } /**