Skip to content
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

Separate module "inquirer" & "commander" from cmd.js file #32

Open
raczak opened this issue Mar 21, 2019 · 3 comments
Open

Separate module "inquirer" & "commander" from cmd.js file #32

raczak opened this issue Mar 21, 2019 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@raczak
Copy link
Collaborator

raczak commented Mar 21, 2019

For better clarity in the file, we should split cmd.js file into to files.

@raczak raczak added the enhancement New feature or request label Mar 21, 2019
@hagabaka
Copy link
Contributor

May I propose a way to structure this code:

There are 5 parameters needed before the parser can run:

  • game
  • language
  • item main category
  • item sub category
  • item limit

Each parameter can be obtained from a list of sources, which currently include command line options and user response from an interactive prompt. In the future we could add the ability to read values from a configuration file or even a GUI dialog like with dialog-node.

So cmd.js should contain specification of the parameters it needs to obtain, including description, choices, etc. It also contains a list of information sources ([commander, inquirer]) from which to get the values of parameters. Then for each parameter, cmd.js will try to get its value from the first source, and if that fails, from the second source, and so on. After all parameter values are obtained, it bundles them in an object and returns it.

Each information source would be defined in its own file, which has some initialization code and exports a function which takes in the parameter specification (name, description, type, filter, etc), and returns a Promise which either resolves to the parameter value or rejects.

An information source could have special cases, for example the commander source would check one option to get the value of both the main category and sub category. But ideally special casing should be minimized to keep the code simple.

Finally, since the role of cmd.js is to provide parameters for the parser, I would rename it to getParameters.js or something like that.

@raczak
Copy link
Collaborator Author

raczak commented Mar 29, 2019

Hi @hagabaka , thank you so much for your help on this topic. I will try to put this in place asap.
I will soon add you to contributors in the README.md 😄

@Darkilen
Copy link
Member

Hi, the application only need 4 parameters :

  • game
  • language
  • item limit (currently separate in two variables, all or maxItem)
  • item category

In fact, there is no real sub-category. With inquirer, we ask for a "sub"-category only when weapons or equipments are selected, but we define the variable "category" with the sub-category and ignore values weapons or equipments.

Darkilen added a commit to Darkilen/crawlit-dofus-encyclopedia-parser that referenced this issue Apr 3, 2019
 - Split commander and inquirer modules (fix dofapi#32)
 - Clean code & add some comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants