Conversation
* fix: write the help for new command * fix: add info about --result-format behavior
src/commands/data/search.ts
Outdated
| if (flags['result-format'] !== 'json') this.spinner.start(messages.getMessage('queryRunningMessage')); | ||
| const queryResult = await conn.search(queryString); | ||
| if (!this.jsonEnabled()) { | ||
| // once we overrode result-format summary, undefined became a flag option, but the default is human |
There was a problem hiding this comment.
I'll make a note to ask Mike about this when he gets back
mshanemc
left a comment
There was a problem hiding this comment.
most are comment/questions, some of which might need changes depending on the answer.
definitely fix
- that empty string thing
- ut using plugins-core's stubs
| // --file will be present if flags.query isn't. Oclif exactlyOne isn't quite that clever | ||
| const queryString = flags.query ?? fs.readFileSync(flags.file as string, 'utf8'); | ||
| const conn = flags['target-org'].getConnection(flags['api-version']); | ||
| if (flags['result-format'] !== 'json') this.spinner.start(messages.getMessage('queryRunningMessage')); |
There was a problem hiding this comment.
is it the result format or the json-enabled-ness that matters for spinners?
ex: Imagine I want --result-format csv --json because I'm a CI script. I want to get that 0/1 and file location as json output BUT I want a csv file written. I wouldn't want a spinner.
There was a problem hiding this comment.
this is carried from data query, but this.spinner should be respecting the --json flag
src/reporters/search/reporter.ts
Outdated
| import { SearchResult } from '@jsforce/jsforce-node'; | ||
|
|
||
| export abstract class SearchReporter { | ||
| public types: string[]; |
There was a problem hiding this comment.
this iterates the records to collect unique types, then each reporter iterates the records again to filter one type at a time.
Why not have a Map of <type, Record[]>. Then you already have them organized (and once we can use Map.groupBy it'll be even cleaner!)
src/reporters/search/reporter.ts
Outdated
| public types: string[]; | ||
| public ux = new Ux(); | ||
| protected constructor(public result: SearchResult) { | ||
| this.types = [...new Set(this.result.searchRecords.map((row) => row.attributes?.type ?? ''))]; |
There was a problem hiding this comment.
what's the important of the empty string? When does it come back empty? Leave a comment for the next person who reads this and wonders.
| this.types.map((type) => { | ||
| const filtered = this.result.searchRecords.filter((t) => t.attributes?.type === type); | ||
| // remove 'attributes' property from result and csv output | ||
| filtered.map((r) => delete r.attributes); |
There was a problem hiding this comment.
both the filter and the removal of attributes seem common to both classes. Probably a shared fn?
Or, if you do move to the Map idea, then the value could be filtered to remove attributes via kit/omit .map((r) => omit(r, 'attributes'));
| import { JsonSearchReporter } from './reporters/search/reporter.js'; | ||
| import { CsvSearchReporter } from './reporters/search/csvSearchReporter.js'; | ||
|
|
||
| export const displaySearchResults = (queryResult: SearchResult, resultFormat: 'human' | 'json' | 'csv'): void => { |
There was a problem hiding this comment.
if you wanted to do this without classes, this would be a function that decides which reporter function(ux, results) to call.
then you wouldn't need all the new and display() etc both here and in the tests
| }); | ||
|
|
||
| it('will write two csv files', () => { | ||
| const logStub = $$.SANDBOX.stub(Ux.prototype, 'log'); |
There was a problem hiding this comment.
you should use the ux tubs from sf-plugins-core.
|
|
||
| it('will write two csv files', () => { | ||
| const logStub = $$.SANDBOX.stub(Ux.prototype, 'log'); | ||
| const writeFileStub = $$.SANDBOX.stub(fs, 'writeFileSync'); |
There was a problem hiding this comment.
idea: rather than the fs stubbing, I think this would be better to write to a temp dir (and then use mocha-snap to snapshot and commit them).
Then we'd detect accidental changes (ex: to.include would pass if you accidentally included the attributes stuff)
| }); | ||
|
|
||
| it('will write two tables', () => { | ||
| const tableStub = $$.SANDBOX.stub(Ux.prototype, 'table'); |
There was a problem hiding this comment.
the sf-plugins-core ux stub has table on it already
| const cols = Object.keys(filtered[0]).join(','); | ||
| const body = filtered.map((r) => Object.values(r).join(',')).join(os.EOL); | ||
|
|
||
| this.ux.log(`Written to ${type}.csv`); |
There was a problem hiding this comment.
wouldn't the empty string be really bad here?
100d4a9 to
dc2e427
Compare
messages/data.search.md
Outdated
|
|
||
| # flags.file.summary | ||
|
|
||
| File that contains the SOQL query. |
There was a problem hiding this comment.
| File that contains the SOQL query. | |
| File that contains the SOSL query. |
messages/data.search.md
Outdated
| @@ -0,0 +1,31 @@ | |||
| # summary | |||
|
|
|||
| Execute a SOSL query. | |||
There was a problem hiding this comment.
probably for Juliet...I think we should link to the SOSL syntax docs
|
QA notes:
🎨 I don't think the word
✅ query with file throws good error |
* refactor: use oclif custom flag * refactor: exclusive json * style: remove the word "results" from table heads * test: no "Results" in test assertions
|
✅ : no ➜ ../../oss/plugin-data/bin/run.js data search --file query.txt -r json --json
{
"name": "Error",
"message": "The following error occurred:\n \u001b[2m--json=true cannot also be provided when using --result-format\u001b[22m\nSee more help with --help",
"exitCode": 2,
"context": "DataSearchCommand",
"stack": "Error: The following error occurred:\n \u001b[2m--json=true cannot also be provided when using --result-formats``` |
What does this PR do?
adds
data searchcommand to preform SOSL queriesWhat issues does this PR fix or reference?
@W-16448626@