|
| 1 | +# Software Design Document |
| 2 | + |
| 3 | +Reference: Simplification of command option values inheriting configuration |
| 4 | +values from spk config yaml command<br> Authors: Andre Briggs, Dennis Seah |
| 5 | + |
| 6 | +| Revision | Date | Author | Remarks | |
| 7 | +| -------: | ------------ | ----------- | ------------------------------------------------------- | |
| 8 | +| 0.1 | Mar-28, 2020 | Dennis Seah | Initial Draft | |
| 9 | +| 1.0 | Mar-31, 2020 | Dennis Seah | Set revision as 1.0, doc is presented in review meeting | |
| 10 | + |
| 11 | +## 1. Overview |
| 12 | + |
| 13 | +By Design, `spk` command option values inherit from configuration values from |
| 14 | +spk config yaml. This is to help the user from having to provide these values in |
| 15 | +the command line. However, in our generate documents and `commander` generated |
| 16 | +help, users are not informed about these inheritance. In this design doc, we |
| 17 | +propose a way to add this inheritance information in our generated operation |
| 18 | +document; and also a helper function to automatically populate values from |
| 19 | +`config.yaml` to the command option values. |
| 20 | + |
| 21 | +## 2. Out of Scope |
| 22 | + |
| 23 | +This design shall only target making user experience better by providing |
| 24 | +inheritance information in operation help document; and the helper function to |
| 25 | +populate values from `config.yaml` to the command option values. It will |
| 26 | +succinct explain how this function works. |
| 27 | + |
| 28 | +## 3. Design Details |
| 29 | + |
| 30 | +### 3.1 New property in command json file. |
| 31 | + |
| 32 | +Taking this option from `spk deployment onboard` command for example. |
| 33 | + |
| 34 | +``` |
| 35 | + "options": [ |
| 36 | + { |
| 37 | + "arg": "-s, --storage-account-name <storage-account-name>", |
| 38 | + "description": "Azure storage account name", |
| 39 | + "required": true |
| 40 | + }, |
| 41 | +``` |
| 42 | + |
| 43 | +We introduce a new optional property `inherit` |
| 44 | + |
| 45 | +``` |
| 46 | + "options": [ |
| 47 | + { |
| 48 | + "arg": "-s, --storage-account-name <storage-account-name>", |
| 49 | + "description": "Azure storage account name", |
| 50 | + "inherit": "introspection.azure.account_name", |
| 51 | + "required": true |
| 52 | + }, |
| 53 | +``` |
| 54 | + |
| 55 | +With this new property, we have the opportunities to |
| 56 | + |
| 57 | +1. add inheritance information in operation help document; |
| 58 | +1. create helper function to populate values from `config.yaml` to the command |
| 59 | + option values. |
| 60 | +1. developers can have a clear understand of what values in `config.yaml` are |
| 61 | + inherited in which commands. |
| 62 | + |
| 63 | +### 3.2 Add inheritance information in operation help document |
| 64 | + |
| 65 | +In the |
| 66 | +[spk.js](https://github.com/CatalystCode/spk/blob/master/docs/commands/spk.js) |
| 67 | +javascript, we can add code to insert inheritance information like this. |
| 68 | + |
| 69 | +<p style="text-align:center"> |
| 70 | +<img src="inheritFieldInOnBoardDoc.png" width="600px"> |
| 71 | +</p> |
| 72 | + |
| 73 | +### 3.3 Helper function to populate values from config.yaml |
| 74 | + |
| 75 | +the pseudo code is like this |
| 76 | + |
| 77 | +``` |
| 78 | +interface ConfigValues { |
| 79 | + [key:string]: string | ConfigValues | undefined |
| 80 | +} |
| 81 | +
|
| 82 | +interface CommandValues { |
| 83 | + [key:string]: string | undefined |
| 84 | +} |
| 85 | +
|
| 86 | +export const populateInheritValueFromConfig = ( |
| 87 | + options: CommandOption[], # from json decorator |
| 88 | + config: ConfigValues, # from config.yaml |
| 89 | + values: CommandValues # user input |
| 90 | +): void => { |
| 91 | + if [config && options] # do nothing if these are absent |
| 92 | + get options that have inherit property set |
| 93 | + for each of these options |
| 94 | + if values do not contain value for the option |
| 95 | + find the value in config and set it to values object |
| 96 | + } |
| 97 | +}; |
| 98 | +``` |
| 99 | + |
| 100 | +## 4. Dependencies |
| 101 | + |
| 102 | +None |
| 103 | + |
| 104 | +## 5. Risks & Mitigation |
| 105 | + |
| 106 | +None |
| 107 | + |
| 108 | +## 6. Documentation |
| 109 | + |
| 110 | +Document how to add `inherit` property in json file in our developer guide. |
| 111 | + |
| 112 | +\- end - |
0 commit comments