@@ -0,0 +1,172 @@
2+title = "Write and Modify"
7+Here we'll look at creating, changing and deleting files by passing clay an `%info` tagged `task:clay`.
11+- [Introduction](#introduction)
12+- [Add File](#add-file)
13+- [Delete File](#delete-file)
14+- [Mutate File](#mutate-file)
15+- [Multiple Changes](#multiple-changes)
19+An `%info` task looks like:
22+[%info des=desk dit=nori] :: internal edit
25+While the `desk` part is self-evident, the `nori` part is the following structure:
28++$ nori :: repository action
29+ $% [%& p=soba] :: delta
33+The `%|` tag is not currently supported and will crash with a `%labelling-not-implemented` if used, so we can focus on the `%&` part. A `soba` is the following structure:
36++$ soba (list [p=path q=miso]) :: delta
39+This is just a list of changes so you can make more than one change in one request. The `path` is just the path to a file like `/gen/hood/hi/hoon` and the `miso` is the following structure:
43+ $% [%del ~] :: delete
44+ [%ins p=cage] :: insert
45+ [%dif p=cage] :: mutate from diff
46+ [%mut p=cage] :: mutate from raw
49+- `%del` - Delete a file.
50+- `%ins` - Insert file. This will also replace an existing file.
51+- `%dif` - this has not yet been implemented so will crash with a `%dif-not-implemented` error.
52+- `%mut` - Change a file. At the time of writing this behaves identically to `%ins` so its use merely informs the reader.
54+Clay does not give any response to an `%info` task so don't expect a sign back.
56+Now we'll look at some example threads:
65+=, strand=strand:spider
70+=/ uarg !< (unit (pair path @t)) arg
72+ (strand-fail:strand %no-arg ~)
75+=/ =task:clay [%info %home %& [[path %ins %txt !>(wain)] ~]]
76+=/ =card:agent:gall [%pass /info %arvo %c task]
77+;< ~ bind:m (send-raw-card:strandio card)
81+Save it in `/ted/add-file.hoon`, `|commit %home` and run it like:
84+> -add-file /foo/txt 'foo'
85++ /~zod/home/22/foo/txt
88+If you have a look in the home of your pier you'll see there's now a file called `foo.txt` with the text `foo` in it.
90+We've created the cage of the content like `[%txt !>(wain)]`, if you want to write something besides a text file you'd just give it the appropriate mark and vase.
92+Here's a breakdown of the `task:clay` we sent:
94+
98+**`delete-file.hoon`**
103+=, strand=strand:spider
108+=/ uarg !< (unit path) arg
110+ (strand-fail:strand %no-arg ~)
112+=/ =task:clay [%info %home %& [path %del ~] ~]
113+=/ =card:agent:gall [%pass /info %arvo %c task]
114+;< ~ bind:m (send-raw-card:strandio card)
118+Save the above code in `ted/delete-file.hoon`, `|commit %home` and run it like:
121+> -delete-file /foo/txt
122+- /~zod/home/24/foo/txt
125+If you have a look in the home of your pier you'll see the `foo.txt` file you created is now gone.
127+Here's a breakdown of the `task:clay` we sent:
129+
133+Identical to the [Add File](#add-file) example, just replace `%ins` with `%mut`.
137+Since `soba:clay` is just a `list` of `miso:clay`, you can add a bunch of `miso:clay` and they'll all be applied. This thread adds three files and then deletes them. Here there's only one type of `miso` in each request but you could mix different types together too.
139+**`multi-change.hoon`**
144+=, strand=strand:spider
149+=/ soba-a :~ [/foo/txt %ins %txt !>(['foo' ~])]
150+ [/bar/txt %ins %txt !>(['bar' ~])]
151+ [/baz/txt %ins %txt !>(['baz' ~])]
153+=/ soba-b :~ [/foo/txt %del ~]
157+;< ~ bind:m (send-raw-card:strandio [%pass /info %arvo %c %info %home %& soba-a])
158+;< ~ bind:m (send-raw-card:strandio [%pass /info %arvo %c %info %home %& soba-b])
162+Save to `ted/multi-change.hoon`, `|commit %home`, and run:
166++ /~zod/home/37/foo/txt
167++ /~zod/home/37/bar/txt
168++ /~zod/home/37/baz/txt
169+- /~zod/home/38/foo/txt
170+- /~zod/home/38/bar/txt
171+- /~zod/home/38/baz/txt