tarekelkurjie / duck.js

An open-source JavaScript project with the sole purpose of rendering a duck on a screen.
https://duckspin.herokuapp.com
MIT License
2 stars 0 forks source link

Add arguments to commands #14

Closed joeymalvinni closed 2 years ago

joeymalvinni commented 2 years ago

Currently, when using a command such as /obama, a single Obama Prism is “spawned” or added to the scene. However, this makes it hard to spawn in many ObamaPrisms at once.

My proposal is to add in arguments. These would operate similar to command-line arguments— you would pass in a command and arguments and receive output.

Example:

/obama <number> -S <size> --minsize <minimum size> --maxsize <maximum size>

This can be used like this:

/obama 5 --minsize 1 --maxsize 6 # randomly create 5 Obamas with a random size between 1 and 6
/obama 100 -S 4 # set the size of 100 Obamas to 4
/obama 2 -S 7 --minsize 3 --maxsize 5 # spawn 2 obamas with min and max size, ignore absolute size or throw error
tarekelkurjie commented 2 years ago

I was already planning on making something similar this but I had put it aside due to complexity. I would basically need to build an interpreter in JavaScript which, although there are libraries available, is a bit of a pain. I ran into the issue of generating the actual JS code needed to render all of this. Also, is there existing code to change the size of the obamas?

joeymalvinni commented 2 years ago

No, it is quite simple to parse arguments, if you would like I can give you a demonstration in a private Github repo of mine.

Consider using modules like argparse, which is easy to implement given that you are already using WebPack.

Also, is there existing code to change the size of the obamas?

No, but can be implemented quite easily.

tarekelkurjie commented 2 years ago

Oh haha, I already started working on a vanilla JS implementation, although I'll look into argparse. Thanks for your help.

tarekelkurjie commented 2 years ago

From what I'm seeing, argparse relies on command-line arguments, when executing a JS file. How could this be implemented in our case? Also, since code executions are required, it could potentially be a big security issue.