-
Notifications
You must be signed in to change notification settings - Fork 7
feat: simplify-log-colorization #484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fe748dc
fa3eb91
4e519d1
bed5356
f1e5936
48e8502
8d3682d
29fe179
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# flags.result-format.summary | ||
|
||
Format of the test results. | ||
|
||
# flags.code-coverage.summary | ||
|
||
Retrieve code coverage results. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); | |
const messages = Messages.loadMessages('@salesforce/plugin-apex', 'list'); | ||
|
||
export type LogListResult = LogRecord[]; | ||
type LogForTable = Omit<LogRecord, 'DurationMilliseconds' | 'User'> & { DurationMilliseconds: string; User: string }; | ||
|
||
export default class Log extends SfCommand<LogListResult> { | ||
public static readonly summary = messages.getMessage('summary'); | ||
|
@@ -35,61 +36,45 @@ export default class Log extends SfCommand<LogListResult> { | |
public async run(): Promise<LogListResult> { | ||
const { flags } = await this.parse(Log); | ||
|
||
const conn = flags['target-org'].getConnection(flags['api-version']); | ||
const logService = new LogService(conn); | ||
const logRecords = await logService.getLogRecords(); | ||
const logService = new LogService(flags['target-org'].getConnection(flags['api-version'])); | ||
const logRecords = (await logService.getLogRecords()).map(formatStartTime); | ||
|
||
if (logRecords.length === 0) { | ||
this.log(messages.getMessage('noDebugLogsFound')); | ||
return []; | ||
} | ||
|
||
logRecords.map((logRecord) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was doing mutation on the records. You'll see UT that were relying on that side effect to pass. |
||
logRecord.StartTime = this.formatTime(logRecord.StartTime); | ||
}); | ||
|
||
if (!flags.json) { | ||
// while not required to prevent table output, save a few iterations if only printing json | ||
const cleanLogs = logRecords.map((logRecord) => ({ | ||
app: logRecord.Application, | ||
duration: String(logRecord.DurationMilliseconds), | ||
id: logRecord.Id, | ||
location: logRecord.Location, | ||
size: String(logRecord.LogLength), | ||
user: logRecord.LogUser.Name, | ||
operation: logRecord.Operation, | ||
request: logRecord.Request, | ||
time: logRecord.StartTime, | ||
status: logRecord.Status, | ||
})); | ||
|
||
this.table( | ||
cleanLogs, | ||
{ | ||
app: { header: messages.getMessage('appColHeader') }, | ||
duration: { header: messages.getMessage('durationColHeader') }, | ||
id: { header: messages.getMessage('idColHeader') }, | ||
location: { header: messages.getMessage('locationColHeader') }, | ||
size: { header: messages.getMessage('sizeColHeader') }, | ||
user: { header: messages.getMessage('userColHeader') }, | ||
operation: { header: messages.getMessage('operationColHeader') }, | ||
request: { header: messages.getMessage('requestColHeader') }, | ||
time: { header: messages.getMessage('timeColHeader') }, | ||
status: { header: messages.getMessage('statusColHeader') }, | ||
}, | ||
{ 'no-truncate': true } | ||
); | ||
this.table(logRecords.map(formatForTable), tableHeaders, { 'no-truncate': true }); | ||
} | ||
|
||
return logRecords; | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
private formatTime(time: string): string { | ||
const milliIndex = time.indexOf('.'); | ||
if (milliIndex !== -1) { | ||
return time.substring(0, milliIndex) + time.substring(milliIndex + 4); | ||
} | ||
return time; | ||
} | ||
} | ||
|
||
const formatForTable = (logRecord: LogRecord): LogForTable => ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's really only 2 fields that needed transorming. The rest can use the name the server uses |
||
...logRecord, | ||
DurationMilliseconds: String(logRecord.DurationMilliseconds), | ||
User: logRecord.LogUser.Name, | ||
}); | ||
|
||
export const formatStartTime = (lr: LogRecord): LogRecord => ({ ...lr, StartTime: formatTime(lr.StartTime) }); | ||
|
||
const formatTime = (time: string): string => { | ||
const msIndex = time.indexOf('.'); | ||
return msIndex !== -1 ? time.substring(0, msIndex) + time.substring(msIndex + 4) : time; | ||
}; | ||
|
||
const tableHeaders = { | ||
Application: { header: 'Application' }, | ||
DurationMilliseconds: { header: 'Duration (ms)' }, | ||
Id: { header: 'Id' }, | ||
Location: { header: 'Location' }, | ||
LogLength: { header: 'Size (B)' }, | ||
User: { header: 'Log User' }, | ||
Operation: { header: 'Operation' }, | ||
Request: { header: 'Request' }, | ||
StartTime: { header: 'Start Time' }, | ||
Status: { header: 'Status' }, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2023, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { Messages } from '@salesforce/core'; | ||
import { Flags } from '@salesforce/sf-plugins-core'; | ||
|
||
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); | ||
const messages = Messages.loadMessages('@salesforce/plugin-apex', 'flags'); | ||
|
||
export const resultFormatFlag = Flags.string({ | ||
deprecateAliases: true, | ||
aliases: ['resultformat'], | ||
char: 'r', | ||
summary: messages.getMessage('flags.result-format.summary'), | ||
options: ['human', 'tap', 'junit', 'json'] as const, | ||
default: 'human', | ||
}); | ||
|
||
export const codeCoverageFlag = Flags.boolean({ | ||
aliases: ['codecoverage'], | ||
deprecateAliases: true, | ||
char: 'c', | ||
summary: messages.getMessage('flags.code-coverage.summary'), | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a message for table headers seemed silly--we don't normally do that