Skip to content
Snippets Groups Projects
Commit 2914b9f8 authored by Jonas Johan Solsvik's avatar Jonas Johan Solsvik :video_game:
Browse files

final commit

parent da213959
No related branches found
No related tags found
No related merge requests found
...@@ -235,7 +235,7 @@ DID-CLI's init-function starts with creating a bunch of directories, if they don ...@@ -235,7 +235,7 @@ DID-CLI's init-function starts with creating a bunch of directories, if they don
Let's discuss a refactoring we did of the `read()`-function and its corresponding `read`-command. Let's discuss a refactoring we did of the `read()`-function and its corresponding `read`-command.
**read() before refactor** **read()-function before refactor**
```rust ```rust
fn read(dcem: &str) -> Result<String, std::io::Error> { fn read(dcem: &str) -> Result<String, std::io::Error> {
use std::io::Write; use std::io::Write;
...@@ -279,7 +279,7 @@ Why did I want to refac this function? Because it does too much. It does more th ...@@ -279,7 +279,7 @@ Why did I want to refac this function? Because it does too much. It does more th
1. There was no general "store message in file"-command. 1. There was no general "store message in file"-command.
2. There was no easy way to chain commands together, making it difficult to do both the "store to file"- and the "convert file to human readable"-operation at the same time, which led to the "store to file"-operation being bundled together with other commands for convenience. 2. There was no easy way to chain commands together, making it difficult to do both the "store to file"- and the "convert file to human readable"-operation at the same time, which led to the "store to file"-operation being bundled together with other commands for convenience.
***Example of usage BEFORE refactor:*** ***Example of using the read-command BEFORE refactor:***
```shell ```shell
$ did read $(cat message-to-me.dcem) # Reads AND stores the message in my wallet $ did read $(cat message-to-me.dcem) # Reads AND stores the message in my wallet
Hello Jonas! Hello Jonas!
...@@ -293,13 +293,13 @@ The solution to my problem was: ...@@ -293,13 +293,13 @@ The solution to my problem was:
2. Make sure both the `hold` and `read` could optionally read from `stdin`. 2. Make sure both the `hold` and `read` could optionally read from `stdin`.
3. Make sure `hold` command prints its input to `stdout` unmodified, to make it possible to use the output of `hold` as input to `read`. 3. Make sure `hold` command prints its input to `stdout` unmodified, to make it possible to use the output of `hold` as input to `read`.
***Example of usage AFTER refac:*** ***Example using the read-command AFTER refactor:***
```shell ```shell
$ cat message-to-me.dcem | did hold | did read $ cat message-to-me.dcem | did hold | did read
Hello Jonas! Hello Jonas!
``` ```
***read() after refactor:*** ***read()-function AFTER refactor:***
```rust ```rust
fn read(dcem: &str) -> Result<String, std::io::Error> { fn read(dcem: &str) -> Result<String, std::io::Error> {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment