Open raczak opened 5 years ago
May I propose a way to structure this code:
There are 5 parameters needed before the parser can run:
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.
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 😄
Hi, the application only need 4 parameters :
all
or maxItem
)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
.
For better clarity in the file, we should split cmd.js file into to files.