@abhishekwl/dict_cli 中文文档教程

发布于 4年前 浏览 19 更新于 3年前

dict (Stack Finance Task)

强大的基于 CLI 的同义词库可供使用。 专注于代码结构和文件组织。 使用 commander(CLI 操作)和 chalk(控制台着色)构建。 对 dictionaryapi.com 进行 API 调用以获取给定单词的定义、同义词、反义词和用法示例。

Usage

Usage: dict [options] [command]

Options:
  -v, --version   Displays the current version of the CLI
  -h, --help      display help for command

Commands:
  def <word>      Display definitions of a word
  syn <word>      Display synonyms of a word
  ant <word>      Display antonyms of a word
  ex <word>       Display examples of a word
  play            Let's play a game
  help [command]  display help for command

Directory Structure

.
├── README.md
├── index.js
├── package.json
├── src
│&nbsp;&nbsp; ├── shared
│&nbsp;&nbsp; │&nbsp;&nbsp; ├── commands.metadata.json
│&nbsp;&nbsp; │&nbsp;&nbsp; ├── constants.js
│&nbsp;&nbsp; │&nbsp;&nbsp; └── random.words.txt
│&nbsp;&nbsp; ├── thesaurus
│&nbsp;&nbsp; │&nbsp;&nbsp; ├── controller
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; ├── antonym.controller.js
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; ├── definition.controller.js
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; ├── example.controller.js
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; ├── full-dict.controller.js
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; ├── play.controller.js
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; └── synonym.controller.js
│&nbsp;&nbsp; │&nbsp;&nbsp; ├── enums
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; └── command.enum.js
│&nbsp;&nbsp; │&nbsp;&nbsp; ├── helpers
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; └── play.helper.js
│&nbsp;&nbsp; │&nbsp;&nbsp; └── services
│&nbsp;&nbsp; │&nbsp;&nbsp;     └── thesaurus.service.js
│&nbsp;&nbsp; └── util
│&nbsp;&nbsp;     └── index.js
└── yarn.lock

Done so far

  • Implemented enums for command names.
  • Separation of concerns, service layer deals with API calls, controller deals with CLI interaction, helpers aid controllers with functions specific to the module.
  • shared directory contains globally shared resources such as constants and command information.
  • Utility functions are stored in util directory.
  • Error management at every stage with try/catch being implemented with various error types at the service level as well as the controller level.
  • Minimalist index.js entrypoint with necessary imports only.

Possible Enhancements

  • Fetch API key from environment variables, storing it in code to make testing easier.
  • Use jsconfig paths to make relative imports easier.
  • Implements typescript to ensure types.
  • Improve CLI interface (prettify).
  • Display a friendly did you mean message if a command is not found.
  • Add autoupdate support to the CLI.
  • Add bash/zsh autocomplete.

Screenshots

  1. Definition

定义

  1. Synonym

同义词

  1. Antonym

Antonym

  1. Example

示例

  1. Full Dictionary

完整词典

  1. Word of the day

每日一语

  1. Game

播放

???? dict (Stack Finance Task)

Robust CLI based thesaurus to play with. Focused on code structure and file organisation. Built using commander (CLI operations) and chalk (console coloring). Makes API calls to dictionaryapi.com to fetch definitions, synonyms, antonyms and usage examples of a given word.

???? Usage

Usage: dict [options] [command]

Options:
  -v, --version   Displays the current version of the CLI
  -h, --help      display help for command

Commands:
  def <word>      Display definitions of a word
  syn <word>      Display synonyms of a word
  ant <word>      Display antonyms of a word
  ex <word>       Display examples of a word
  play            Let's play a game
  help [command]  display help for command

???? Directory Structure

.
├── README.md
├── index.js
├── package.json
├── src
│&nbsp;&nbsp; ├── shared
│&nbsp;&nbsp; │&nbsp;&nbsp; ├── commands.metadata.json
│&nbsp;&nbsp; │&nbsp;&nbsp; ├── constants.js
│&nbsp;&nbsp; │&nbsp;&nbsp; └── random.words.txt
│&nbsp;&nbsp; ├── thesaurus
│&nbsp;&nbsp; │&nbsp;&nbsp; ├── controller
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; ├── antonym.controller.js
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; ├── definition.controller.js
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; ├── example.controller.js
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; ├── full-dict.controller.js
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; ├── play.controller.js
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; └── synonym.controller.js
│&nbsp;&nbsp; │&nbsp;&nbsp; ├── enums
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; └── command.enum.js
│&nbsp;&nbsp; │&nbsp;&nbsp; ├── helpers
│&nbsp;&nbsp; │&nbsp;&nbsp; │&nbsp;&nbsp; └── play.helper.js
│&nbsp;&nbsp; │&nbsp;&nbsp; └── services
│&nbsp;&nbsp; │&nbsp;&nbsp;     └── thesaurus.service.js
│&nbsp;&nbsp; └── util
│&nbsp;&nbsp;     └── index.js
└── yarn.lock

???? Done so far

  • Implemented enums for command names.
  • Separation of concerns, service layer deals with API calls, controller deals with CLI interaction, helpers aid controllers with functions specific to the module.
  • shared directory contains globally shared resources such as constants and command information.
  • Utility functions are stored in util directory.
  • Error management at every stage with try/catch being implemented with various error types at the service level as well as the controller level.
  • Minimalist index.js entrypoint with necessary imports only.

???? Possible Enhancements

  • Fetch API key from environment variables, storing it in code to make testing easier.
  • Use jsconfig paths to make relative imports easier.
  • Implements typescript to ensure types.
  • Improve CLI interface (prettify).
  • Display a friendly did you mean message if a command is not found.
  • Add autoupdate support to the CLI.
  • Add bash/zsh autocomplete.

???? Screenshots

  1. Definition

Definition

  1. Synonym

Synonym

  1. Antonym

Antonym

  1. Example

Example

  1. Full Dictionary

Full Dict

  1. Word of the day

Word of the day

  1. Game

Play

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文