Skip to content

Commit

Permalink
refactor: modernize the sample tests (#185)
Browse files Browse the repository at this point in the history
* refactor: modernize the sample tests

* lintalicious
  • Loading branch information
JustinBeckwith authored and NimJay committed Nov 10, 2022
1 parent b1544e6 commit a417749
Show file tree
Hide file tree
Showing 18 changed files with 819 additions and 928 deletions.
1 change: 1 addition & 0 deletions cloud-language/snippets/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
rules:
no-console: off
node/no-missing-require: off
197 changes: 95 additions & 102 deletions cloud-language/snippets/analyze.v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,105 +346,98 @@ async function classifyTextInFile(bucketName, fileName) {
// [END language_classify_gcs]
}

async function main() {
require(`yargs`)
.demand(1)
.command(
`sentiment-text <text>`,
`Detects sentiment of a string.`,
{},
opts => analyzeSentimentOfText(opts.text)
)
.command(
`sentiment-file <bucketName> <fileName>`,
`Detects sentiment in a file in Google Cloud Storage.`,
{},
opts => analyzeSentimentInFile(opts.bucketName, opts.fileName)
)
.command(
`entities-text <text>`,
`Detects entities in a string.`,
{},
opts => analyzeEntitiesOfText(opts.text)
)
.command(
`entities-file <bucketName> <fileName>`,
`Detects entities in a file in Google Cloud Storage.`,
{},
opts => analyzeEntitiesInFile(opts.bucketName, opts.fileName)
)
.command(`syntax-text <text>`, `Detects syntax of a string.`, {}, opts =>
analyzeSyntaxOfText(opts.text)
)
.command(
`syntax-file <bucketName> <fileName>`,
`Detects syntax in a file in Google Cloud Storage.`,
{},
opts => analyzeSyntaxInFile(opts.bucketName, opts.fileName)
)
.command(
`entity-sentiment-text <text>`,
`Detects sentiment of the entities in a string.`,
{},
opts => analyzeEntitySentimentOfText(opts.text)
)
.command(
`entity-sentiment-file <bucketName> <fileName>`,
`Detects sentiment of the entities in a file in Google Cloud Storage.`,
{},
opts => analyzeEntitySentimentInFile(opts.bucketName, opts.fileName)
)
.command(`classify-text <text>`, `Classifies text of a string.`, {}, opts =>
classifyTextOfText(opts.text)
)
.command(
`classify-file <bucketName> <fileName>`,
`Classifies text in a file in Google Cloud Storage.`,
{},
opts => classifyTextInFile(opts.bucketName, opts.fileName)
)
.example(
`node $0 sentiment-text "President Obama is speaking at the White House."`
)
.example(
`node $0 sentiment-file my-bucket file.txt`,
`Detects sentiment in gs://my-bucket/file.txt`
)
.example(
`node $0 entities-text "President Obama is speaking at the White House."`
)
.example(
`node $0 entities-file my-bucket file.txt`,
`Detects entities in gs://my-bucket/file.txt`
)
.example(
`node $0 syntax-text "President Obama is speaking at the White House."`
)
.example(
`node $0 syntax-file my-bucket file.txt`,
`Detects syntax in gs://my-bucket/file.txt`
)
.example(
`node $0 entity-sentiment-text "President Obama is speaking at the White House."`
)
.example(
`node $0 entity-sentiment-file my-bucket file.txt`,
`Detects sentiment of entities in gs://my-bucket/file.txt`
)
.example(
`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."`
)
.example(
`node $0 classify-file my-bucket android_text.txt`,
`Detects syntax in gs://my-bucket/android_text.txt`
)
.wrap(120)
.recommendCommands()
.epilogue(
`For more information, see https://cloud.google.com/natural-language/docs`
)
.help()
.strict().argv;
}

main().catch(console.error);
require(`yargs`)
.demand(1)
.command(
`sentiment-text <text>`,
`Detects sentiment of a string.`,
{},
opts => analyzeSentimentOfText(opts.text)
)
.command(
`sentiment-file <bucketName> <fileName>`,
`Detects sentiment in a file in Google Cloud Storage.`,
{},
opts => analyzeSentimentInFile(opts.bucketName, opts.fileName)
)
.command(`entities-text <text>`, `Detects entities in a string.`, {}, opts =>
analyzeEntitiesOfText(opts.text)
)
.command(
`entities-file <bucketName> <fileName>`,
`Detects entities in a file in Google Cloud Storage.`,
{},
opts => analyzeEntitiesInFile(opts.bucketName, opts.fileName)
)
.command(`syntax-text <text>`, `Detects syntax of a string.`, {}, opts =>
analyzeSyntaxOfText(opts.text)
)
.command(
`syntax-file <bucketName> <fileName>`,
`Detects syntax in a file in Google Cloud Storage.`,
{},
opts => analyzeSyntaxInFile(opts.bucketName, opts.fileName)
)
.command(
`entity-sentiment-text <text>`,
`Detects sentiment of the entities in a string.`,
{},
opts => analyzeEntitySentimentOfText(opts.text)
)
.command(
`entity-sentiment-file <bucketName> <fileName>`,
`Detects sentiment of the entities in a file in Google Cloud Storage.`,
{},
opts => analyzeEntitySentimentInFile(opts.bucketName, opts.fileName)
)
.command(`classify-text <text>`, `Classifies text of a string.`, {}, opts =>
classifyTextOfText(opts.text)
)
.command(
`classify-file <bucketName> <fileName>`,
`Classifies text in a file in Google Cloud Storage.`,
{},
opts => classifyTextInFile(opts.bucketName, opts.fileName)
)
.example(
`node $0 sentiment-text "President Obama is speaking at the White House."`
)
.example(
`node $0 sentiment-file my-bucket file.txt`,
`Detects sentiment in gs://my-bucket/file.txt`
)
.example(
`node $0 entities-text "President Obama is speaking at the White House."`
)
.example(
`node $0 entities-file my-bucket file.txt`,
`Detects entities in gs://my-bucket/file.txt`
)
.example(
`node $0 syntax-text "President Obama is speaking at the White House."`
)
.example(
`node $0 syntax-file my-bucket file.txt`,
`Detects syntax in gs://my-bucket/file.txt`
)
.example(
`node $0 entity-sentiment-text "President Obama is speaking at the White House."`
)
.example(
`node $0 entity-sentiment-file my-bucket file.txt`,
`Detects sentiment of entities in gs://my-bucket/file.txt`
)
.example(
`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."`
)
.example(
`node $0 classify-file my-bucket android_text.txt`,
`Detects syntax in gs://my-bucket/android_text.txt`
)
.wrap(120)
.recommendCommands()
.epilogue(
`For more information, see https://cloud.google.com/natural-language/docs`
)
.help()
.strict().argv;
Loading

0 comments on commit a417749

Please sign in to comment.