diff --git a/commands/cms/__tests__/fetch.test.ts b/commands/cms/__tests__/fetch.test.ts index f84af6fc6..3fe850407 100644 --- a/commands/cms/__tests__/fetch.test.ts +++ b/commands/cms/__tests__/fetch.test.ts @@ -61,6 +61,10 @@ describe('commands/cms/fetch', () => { }); expect(optionsSpy).toHaveBeenCalledWith({ assetVersion: expect.objectContaining({ type: 'number' }), + quiet: expect.objectContaining({ + type: 'boolean', + default: false, + }), }); expect(addConfigOptions).toHaveBeenCalledTimes(1); diff --git a/commands/cms/fetch.ts b/commands/cms/fetch.ts index dfcf26d26..3d7b38193 100644 --- a/commands/cms/fetch.ts +++ b/commands/cms/fetch.ts @@ -6,6 +6,7 @@ import { addOverwriteOptions, getCmsPublishMode, } from '../../lib/commonOpts.js'; +import { LOG_LEVEL, setLogLevel } from '@hubspot/local-dev-lib/logger'; import { resolveLocalPath } from '../../lib/filesystem.js'; import { validateCmsPublishMode } from '../../lib/validation.js'; import { trackCommandUsage } from '../../lib/usageTracking.js'; @@ -30,6 +31,7 @@ export type FetchCommandArgs = { staging?: boolean; assetVersion?: number; overwrite?: boolean; + quiet?: boolean; } & ConfigArgs & AccountArgs & EnvironmentArgs & @@ -54,6 +56,14 @@ async function handler( const { derivedAccountId } = options; const cmsPublishMode = getCmsPublishMode(options); + const shouldQuiet = options.quiet; + const shouldDebug = + Boolean((options as { debug?: boolean }).debug) || + Boolean((options as { networkDebug?: boolean }).networkDebug); + const logLevelToRestore = shouldDebug ? LOG_LEVEL.DEBUG : LOG_LEVEL.LOG; + if (shouldQuiet) { + setLogLevel(LOG_LEVEL.ERROR); + } trackCommandUsage('fetch', { mode: cmsPublishMode }, derivedAccountId); @@ -72,6 +82,15 @@ async function handler( overwrite, } ); + if (shouldQuiet) { + setLogLevel(logLevelToRestore); + uiLogger.success( + commands.cms.subcommands.fetch.success.completed( + src, + resolveLocalPath(dest) + ) + ); + } } catch (err) { logError(err); process.exit(EXIT_CODES.ERROR); @@ -103,6 +122,11 @@ const fetchBuilder = (yargs: Argv): Argv => { type: 'number', describe: commands.cms.subcommands.fetch.options.assetVersion.describe, }, + quiet: { + type: 'boolean', + describe: commands.cms.subcommands.fetch.options.quiet.describe, + default: false, + }, }); addCmsPublishModeOptions(yargs, { read: true }); diff --git a/commands/fetch.ts b/commands/fetch.ts index dc2ac3e94..349b96c5e 100644 --- a/commands/fetch.ts +++ b/commands/fetch.ts @@ -47,6 +47,11 @@ function deprecatedCmsFetchBuilder(yargs: Argv): Argv { type: 'number', describe: commands.cms.subcommands.fetch.options.assetVersion.describe, }, + quiet: { + type: 'boolean', + describe: commands.cms.subcommands.fetch.options.quiet.describe, + default: false, + }, }); addCmsPublishModeOptions(yargs, { read: true }); diff --git a/lang/en.ts b/lang/en.ts index 28b04c6aa..9667378a3 100644 --- a/lang/en.ts +++ b/lang/en.ts @@ -718,6 +718,10 @@ export const commands = { errors: { sourceRequired: 'A source to fetch is required.', }, + success: { + completed: (src: string, dest: string) => + `Completed fetch of "${src}" to "${dest}" from the Design Manager`, + }, options: { staging: { describe: 'Retrieve staged changes for project', @@ -725,6 +729,9 @@ export const commands = { assetVersion: { describe: 'Specify what version of a default asset to fetch', }, + quiet: { + describe: 'reduce fetch output to errors only', + }, }, positionals: { dest: {