Skip to content

Commit 7cb1e75

Browse files
JustinBeckwithjkwlui
authored andcommitted
refactor: modernize the sample tests (#185)
* refactor: modernize the sample tests * lintalicious
1 parent 0c1c8be commit 7cb1e75

18 files changed

+819
-928
lines changed

cloud-language/snippets/.eslintrc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
---
22
rules:
33
no-console: off
4+
node/no-missing-require: off

cloud-language/snippets/analyze.v1.js

+95-102
Original file line numberDiff line numberDiff line change
@@ -346,105 +346,98 @@ async function classifyTextInFile(bucketName, fileName) {
346346
// [END language_classify_gcs]
347347
}
348348

349-
async function main() {
350-
require(`yargs`)
351-
.demand(1)
352-
.command(
353-
`sentiment-text <text>`,
354-
`Detects sentiment of a string.`,
355-
{},
356-
opts => analyzeSentimentOfText(opts.text)
357-
)
358-
.command(
359-
`sentiment-file <bucketName> <fileName>`,
360-
`Detects sentiment in a file in Google Cloud Storage.`,
361-
{},
362-
opts => analyzeSentimentInFile(opts.bucketName, opts.fileName)
363-
)
364-
.command(
365-
`entities-text <text>`,
366-
`Detects entities in a string.`,
367-
{},
368-
opts => analyzeEntitiesOfText(opts.text)
369-
)
370-
.command(
371-
`entities-file <bucketName> <fileName>`,
372-
`Detects entities in a file in Google Cloud Storage.`,
373-
{},
374-
opts => analyzeEntitiesInFile(opts.bucketName, opts.fileName)
375-
)
376-
.command(`syntax-text <text>`, `Detects syntax of a string.`, {}, opts =>
377-
analyzeSyntaxOfText(opts.text)
378-
)
379-
.command(
380-
`syntax-file <bucketName> <fileName>`,
381-
`Detects syntax in a file in Google Cloud Storage.`,
382-
{},
383-
opts => analyzeSyntaxInFile(opts.bucketName, opts.fileName)
384-
)
385-
.command(
386-
`entity-sentiment-text <text>`,
387-
`Detects sentiment of the entities in a string.`,
388-
{},
389-
opts => analyzeEntitySentimentOfText(opts.text)
390-
)
391-
.command(
392-
`entity-sentiment-file <bucketName> <fileName>`,
393-
`Detects sentiment of the entities in a file in Google Cloud Storage.`,
394-
{},
395-
opts => analyzeEntitySentimentInFile(opts.bucketName, opts.fileName)
396-
)
397-
.command(`classify-text <text>`, `Classifies text of a string.`, {}, opts =>
398-
classifyTextOfText(opts.text)
399-
)
400-
.command(
401-
`classify-file <bucketName> <fileName>`,
402-
`Classifies text in a file in Google Cloud Storage.`,
403-
{},
404-
opts => classifyTextInFile(opts.bucketName, opts.fileName)
405-
)
406-
.example(
407-
`node $0 sentiment-text "President Obama is speaking at the White House."`
408-
)
409-
.example(
410-
`node $0 sentiment-file my-bucket file.txt`,
411-
`Detects sentiment in gs://my-bucket/file.txt`
412-
)
413-
.example(
414-
`node $0 entities-text "President Obama is speaking at the White House."`
415-
)
416-
.example(
417-
`node $0 entities-file my-bucket file.txt`,
418-
`Detects entities in gs://my-bucket/file.txt`
419-
)
420-
.example(
421-
`node $0 syntax-text "President Obama is speaking at the White House."`
422-
)
423-
.example(
424-
`node $0 syntax-file my-bucket file.txt`,
425-
`Detects syntax in gs://my-bucket/file.txt`
426-
)
427-
.example(
428-
`node $0 entity-sentiment-text "President Obama is speaking at the White House."`
429-
)
430-
.example(
431-
`node $0 entity-sentiment-file my-bucket file.txt`,
432-
`Detects sentiment of entities in gs://my-bucket/file.txt`
433-
)
434-
.example(
435-
`node $0 classify-text "Android is a mobile operating system developed by Google, based on the Linux kernel and designed primarily for touchscreen mobile devices such as smartphones and tablets."`
436-
)
437-
.example(
438-
`node $0 classify-file my-bucket android_text.txt`,
439-
`Detects syntax in gs://my-bucket/android_text.txt`
440-
)
441-
.wrap(120)
442-
.recommendCommands()
443-
.epilogue(
444-
`For more information, see https://cloud.google.com/natural-language/docs`
445-
)
446-
.help()
447-
.strict().argv;
448-
}
449-
450-
main().catch(console.error);
349+
require(`yargs`)
350+
.demand(1)
351+
.command(
352+
`sentiment-text <text>`,
353+
`Detects sentiment of a string.`,
354+
{},
355+
opts => analyzeSentimentOfText(opts.text)
356+
)
357+
.command(
358+
`sentiment-file <bucketName> <fileName>`,
359+
`Detects sentiment in a file in Google Cloud Storage.`,
360+
{},
361+
opts => analyzeSentimentInFile(opts.bucketName, opts.fileName)
362+
)
363+
.command(`entities-text <text>`, `Detects entities in a string.`, {}, opts =>
364+
analyzeEntitiesOfText(opts.text)
365+
)
366+
.command(
367+
`entities-file <bucketName> <fileName>`,
368+
`Detects entities in a file in Google Cloud Storage.`,
369+
{},
370+
opts => analyzeEntitiesInFile(opts.bucketName, opts.fileName)
371+
)
372+
.command(`syntax-text <text>`, `Detects syntax of a string.`, {}, opts =>
373+
analyzeSyntaxOfText(opts.text)
374+
)
375+
.command(
376+
`syntax-file <bucketName> <fileName>`,
377+
`Detects syntax in a file in Google Cloud Storage.`,
378+
{},
379+
opts => analyzeSyntaxInFile(opts.bucketName, opts.fileName)
380+
)
381+
.command(
382+
`entity-sentiment-text <text>`,
383+
`Detects sentiment of the entities in a string.`,
384+
{},
385+
opts => analyzeEntitySentimentOfText(opts.text)
386+
)
387+
.command(
388+
`entity-sentiment-file <bucketName> <fileName>`,
389+
`Detects sentiment of the entities in a file in Google Cloud Storage.`,
390+
{},
391+
opts => analyzeEntitySentimentInFile(opts.bucketName, opts.fileName)
392+
)
393+
.command(`classify-text <text>`, `Classifies text of a string.`, {}, opts =>
394+
classifyTextOfText(opts.text)
395+
)
396+
.command(
397+
`classify-file <bucketName> <fileName>`,
398+
`Classifies text in a file in Google Cloud Storage.`,
399+
{},
400+
opts => classifyTextInFile(opts.bucketName, opts.fileName)
401+
)
402+
.example(
403+
`node $0 sentiment-text "President Obama is speaking at the White House."`
404+
)
405+
.example(
406+
`node $0 sentiment-file my-bucket file.txt`,
407+
`Detects sentiment in gs://my-bucket/file.txt`
408+
)
409+
.example(
410+
`node $0 entities-text "President Obama is speaking at the White House."`
411+
)
412+
.example(
413+
`node $0 entities-file my-bucket file.txt`,
414+
`Detects entities in gs://my-bucket/file.txt`
415+
)
416+
.example(
417+
`node $0 syntax-text "President Obama is speaking at the White House."`
418+
)
419+
.example(
420+
`node $0 syntax-file my-bucket file.txt`,
421+
`Detects syntax in gs://my-bucket/file.txt`
422+
)
423+
.example(
424+
`node $0 entity-sentiment-text "President Obama is speaking at the White House."`
425+
)
426+
.example(
427+
`node $0 entity-sentiment-file my-bucket file.txt`,
428+
`Detects sentiment of entities in gs://my-bucket/file.txt`
429+
)
430+
.example(
431+
`node $0 classify-text "Android is a mobile operating system developed by Google, based on the Linux kernel and designed primarily for touchscreen mobile devices such as smartphones and tablets."`
432+
)
433+
.example(
434+
`node $0 classify-file my-bucket android_text.txt`,
435+
`Detects syntax in gs://my-bucket/android_text.txt`
436+
)
437+
.wrap(120)
438+
.recommendCommands()
439+
.epilogue(
440+
`For more information, see https://cloud.google.com/natural-language/docs`
441+
)
442+
.help()
443+
.strict().argv;

0 commit comments

Comments
 (0)