From Annvix
There is a bunch of changes that were done in the arguement parsing in srv. It is a little complex so I thought some design/overview documentation would be helpful.
Design Considerations:
- Need to be able to support multiple actions in a single instance
- Need to be able to support multiple arguements to each action
- This is very important for the dependency tracking stuff because we can just push the dependencies to the arguement list of the action (ordering is important)
- Needs a simple error checking framework -- don't want complicated set of nesting of logic.
- Parser needs to be easily extendable
- Add more actions
- Add more error checks
Implementation:
- Rewrote all actions functions to accept an arguement, instead of using the global $SERVICE
- Made status & list support multiple services
- We utilize bash arrays
- Bash only supports integer indexes (would be nice with hashes), so we index each action to an integer ($<ACTION>_NDX)
- $ACTIONS is an array index based on action index, for all action tokens
- $ACTION_ARGS is an array indexed based on action index, that contains a space seperated list of arguements
- We parse the command line arguements
- We compare the cli arg to the $ACTIONS for the token, if it is an action, then we set the last action found ($LAST_ACTION)
- If it is not a token, then it will be an arguement to the last found action ($LAST_ACTION)
- We need to check because some actions don't have arguements (list is in the $CHECK_NO_ARGS variable)
- If an arguement but have no last found action, then it is an error (action not found)
- We then error check the arguements
- We check that all arguements that require arguements exist (listed in the $CHECK_REQ_ARGS variable)
- We then loop each arguement and based on the action, we check $CHECK_ADD_DIR, $CHECK_SRV_DIR, $CHECK_NO_SRV_DIR variables for each check
- We then do loop action and perform it.
- For most services, we loop each arguement and run the action once per arguement
- Some services, we run with all arguements (such as list & status)
Misc:
It allows you do do stuff like:
srv add <service1> stop <service2> status
Which will add service1, stop service2 and then print a list of all status
You can also do:
srv add <service1> <service2> <service3> list <service4>
You will even support stuff like:
srv add <service1> add <service2> <service3> add <service4>
It should catch errors like:
srv add <service1> -q <service2>
srv add del <service1>
srv