Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions packages/i18n/src/locales/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ const translations: Catalog = {
description: 'Shell log methods',
link: '#',
attributes: {
// TODO(MONGOSH-1995): Print help for the global log property.
info: {
description: 'Writes a custom info message to the log file',
example: 'log.info("Custom info message")',
Expand Down Expand Up @@ -166,6 +165,10 @@ const translations: Catalog = {
description: 'Shell Help',
link: 'https://docs.mongodb.com/manual/reference/method',
attributes: {
log: {
description:
"'log.info(<msg>)': Writes a custom info/warn/error/fatal/debug message to the log file",
},
use: {
description: 'Set current database',
},
Expand All @@ -181,13 +184,13 @@ const translations: Catalog = {
},
show: {
description:
"'show databases'/'show dbs': Print a list of all available databases.\n" +
"'show collections'/'show tables': Print a list of all collections for current database.\n" +
"'show profile': Prints system.profile information.\n" +
"'show users': Print a list of all users for current database.\n" +
"'show roles': Print a list of all roles for current database.\n" +
"'show databases'/'show dbs': Print a list of all available databases\n" +
"'show collections'/'show tables': Print a list of all collections for current database\n" +
"'show profile': Prints system.profile information\n" +
"'show users': Print a list of all users for current database\n" +
"'show roles': Print a list of all roles for current database\n" +
"'show log <type>': log for current connection, if type is not set uses 'global'\n" +
"'show logs': Print all logs.\n",
"'show logs': Print all logs",
},
connect: {
description:
Expand Down
18 changes: 13 additions & 5 deletions packages/shell-api/src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,14 +473,22 @@ function shellApiClassGeneric<T extends { prototype: any }>(
constructor.prototype,
propertyName
);

if (toIgnore.includes(propertyName) || propertyName.startsWith('_')) {
continue;
}

const isMethod =
descriptor?.value && typeof descriptor.value === 'function';
if (
!isMethod ||
toIgnore.includes(propertyName) ||
propertyName.startsWith('_')
)
if (!isMethod) {
const attributeHelpKeyPrefix = `${classHelpKeyPrefix}.attributes.${propertyName}`;
classHelp.attr.push({
name: propertyName,
description: `${attributeHelpKeyPrefix}.description`,
});
continue;
}

let method: any = (descriptor as any).value;

if ((constructor as any)[addSourceToResultsSymbol]) {
Expand Down
5 changes: 5 additions & 0 deletions packages/shell-api/src/shell-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { dirname } from 'path';
import { ShellUserConfig } from '@mongosh/types';
import i18n from '@mongosh/i18n';
import { MONGOSH_VERSION } from './mongosh-version';
import type { ShellLog } from './shell-log';

const instanceStateSymbol = Symbol.for('@@mongosh.instanceState');
const loadCallNestingLevelSymbol = Symbol.for('@@mongosh.loadCallNestingLevel');
Expand Down Expand Up @@ -188,6 +189,10 @@ export default class ShellApi extends ShellApiClass {
this.config = new ShellConfig(instanceState);
}

get log(): ShellLog {
return this[instanceStateSymbol].shellLog;
}

get _instanceState(): ShellInstanceState {
return this[instanceStateSymbol];
}
Expand Down
3 changes: 1 addition & 2 deletions packages/shell-api/src/shell-instance-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ export default class ShellInstanceState {
setCtx(contextObject: any): void {
this.context = contextObject;
Object.assign(contextObject, this.shellApi);
contextObject.log = this.shellLog;
for (const name of Object.getOwnPropertyNames(ShellApi.prototype)) {
const { shellApi } = this;
if (
Expand Down Expand Up @@ -365,8 +366,6 @@ export default class ShellInstanceState {
});
}

contextObject.log = this.shellLog;

this.messageBus.emit('mongosh:setCtx', { method: 'setCtx', arguments: {} });
}

Expand Down
Loading