Define how CLI commands are defined
jmaister opened this issue ยท 7 comments
Use any library from Go to parse the command line and decide what to do.
This task is just to show how the command line works and does not require to code the commands. Printing the options is enough.
Commands:
$ gaa model migrate
$ gaa model create User
$ gaa server -P 8080
os.Args
would be the simplest way to do this IMO.
Is there a structure that the flags and their values should be stored in? Like every -
or --
will be a key in a map and then the following value after it would be the value of the map. Or if it is just a flag like --debug
then the value in the map could be true
Example: gaa model migrate -P 8080 --debug
would result in a flags map structured:
commands: [model, migrate]
flags map:
{
"P": 8080,
"debug": true
}
Excuse the ignorance, but why would a flag matter?
Hypothetically, if we use os.Args
, can't we just have a set of enums or a map of values, then iterate through the arguments and see which match and apply those?
We totally could, I just thought it might be nicer internally in the code to have something to reference rather than looping through an array a bunch. I thought having some internal structure for this stuff would be nice to use within the code
Is there a structure that the flags and their values should be stored in? Like every
-
or--
will be a key in a map and then the following value after it would be the value of the map. Or if it is just a flag like--debug
then the value in the map could betrue
Example:
gaa model migrate -P 8080 --debug
would result in a flags map structured:commands: [model, migrate]
flags map:
{ "P": 8080, "debug": true }
Perfect, this is what it's needed.
This task is a nice programming exercise for using the Go lang. Loop, parse, string manipulation, ... That's why I marked it as a "good first issue".
On the other hand, there are libraries that already handle this.
As we are here to learn Go, I recommend somebody to get this task to start getting into the language.
If everyone's ok with it I'd love to crank out this task over the weekend. I have it started on a fork already as I got quite excited when discussing this
If everyone's ok with it I'd love to crank out this task over the weekend. I have it started on a fork already as I got quite excited when discussing this
Nice, I just assigned this issue to you. You can see it on the top right.