|
| 1 | +# Oasis CLI Examples |
| 2 | + |
| 3 | +This folder contains example scenarios for the Oasis CLI. The snippets are |
| 4 | +included in the documentation and also serve as a check for potential |
| 5 | +regressions in the CLI. |
| 6 | + |
| 7 | +Each example is stored inside its own folder. The folder contains: |
| 8 | + |
| 9 | +- one or more invocation files, |
| 10 | +- output file for each invocation file with the content of the resulting |
| 11 | + standard output, |
| 12 | +- input and output artifacts |
| 13 | +- `config` folder containing custom config file to be used for the scenario. |
| 14 | + |
| 15 | +## Invocation files |
| 16 | + |
| 17 | +Invocation files have `.in` extension and they will be executed in |
| 18 | +alphabetic order. This is important, if you have destructive operations (e.g |
| 19 | +adding or removing a wallet) where the order of execution should be respected. |
| 20 | +In this case, name the files starting with a number, for example `00-create.in`. |
| 21 | + |
| 22 | +Each `.in` file begins with `oasis` command, which will be replaced with the |
| 23 | +path to the actual Oasis CLI command when generating example outputs. |
| 24 | + |
| 25 | +An example invocation file content to create a new wallet: |
| 26 | + |
| 27 | +``` |
| 28 | +oasis wallet create john |
| 29 | +``` |
| 30 | + |
| 31 | +### Non-Interactive Execution |
| 32 | + |
| 33 | +If you want to invoke Oasis in a non-interactive mode (by appending |
| 34 | +`-y -o /dev/null` parameters), name the invocation file by appending `.y` after |
| 35 | +the `NUMBER`. For example `00.in` becomes `00.y.in`. |
| 36 | + |
| 37 | +### Custom Config Files |
| 38 | + |
| 39 | +Sometimes, you want to use a predefined config file for the Oasis CLI. Put |
| 40 | +your desired Oasis CLI config folder inside the `config` subfolder inside the |
| 41 | +example folder. Upon example invocation, the folder will be copied over to a |
| 42 | +temporary location and provided to CLI with `--config` parameter. Then, the |
| 43 | +example will be invoked beginning with the provided config file. This way, you |
| 44 | +can prepare and execute specific CLI scenarios without a dozen of presteps. |
| 45 | + |
| 46 | +### Example Artifacts |
| 47 | + |
| 48 | +If an example requires external files such as a JSON file containing an entity |
| 49 | +descriptor or a raw transaction, simply put it alongside the input file. |
| 50 | +Assume the working directory will be the one that the input file resides in. |
| 51 | +The same goes for the output artifacts (e.g. signed transaction). |
| 52 | + |
| 53 | +## Output Files |
| 54 | + |
| 55 | +The Oasis CLI output for the given input will be stored in a file named the same |
| 56 | +as the corresponding invocation file, but having `.out` extension instead of |
| 57 | +`.in`. |
| 58 | + |
| 59 | +Scenarios should be designed in a way that the output files remain equal unless |
| 60 | +a different behavior of the Oasis CLI is expected. |
| 61 | + |
| 62 | +## Static examples |
| 63 | + |
| 64 | +If you do not want the example to be executed, but you simply want to store |
| 65 | +Oasis CLI execution snippets for example to be included in the documentation, |
| 66 | +append `.static` to the corresponding `.in` and `.out` files. Such files will |
| 67 | +not be tested and regenerated each time, but you will have to update it |
| 68 | +manually. We discourage using this mechanism, but it may be useful in cases when |
| 69 | +the output is expected to change and would not make sense to update it each time |
| 70 | +(e.g. `oasis network status` returns the current block height). |
| 71 | + |
| 72 | +## Running Examples |
| 73 | + |
| 74 | +To run the examples and generate outputs, invoke in the top-level directory: |
| 75 | + |
| 76 | +```sh |
| 77 | +make examples |
| 78 | +``` |
0 commit comments