|
1 | 1 | {/* THIS FILE IS GENERATED FROM A TEMPLATE. See scripts/generate-commands-pages.js for more */} |
2 | 2 | export const metadata = { |
3 | | - title: "Set Command", |
4 | | - description: "Set an entry in a document" |
| 3 | + title: "<%= command.name %>", |
| 4 | + description: "<%= command.description %>" |
5 | 5 | } |
6 | 6 |
|
7 | | -# Set |
| 7 | +# <%= command.name %> |
8 | 8 |
|
9 | | -Set an entry in a document {{ className: 'lead' }} |
| 9 | +<%= command.description %> {{ className: 'lead' }} |
10 | 10 |
|
| 11 | +<% if (command.arguments) { %> |
11 | 12 | ### Arguments |
12 | 13 |
|
13 | 14 | | name | necessity | description | |
14 | 15 | | ---- | --------- | ----------- | |
15 | | -| KEY | required | Key to the entry (parsed as UTF-8 string) | |
16 | | -| VALUE | required | Content to store for this entry (parsed as UTF-8 string) | |
17 | | -| author | required | Author of this entry. Required unless the author is set through the console or the IROH_AUTHOR environment variable. | |
| 16 | +<% command.arguments.forEach((arg) => { %> |
| 17 | +| <%= arg.name %> | <%= arg.necessity%> | <%= arg.description %> | |
| 18 | +<% }) %> |
| 19 | +<% } %> |
18 | 20 |
|
19 | 21 | ## Examples |
20 | 22 |
|
21 | 23 | <CodeGroup title="SET"> |
22 | 24 |
|
23 | 25 |
|
24 | 26 | ```text {{ title: 'console' }} |
25 | | -> docs create --use |
26 | | -> set key value |
27 | | -@ydzwyyes…: key = azceusiw… (5 B) |
| 27 | +<%- examples.console %> |
28 | 28 | ``` |
29 | 29 |
|
30 | | -```bash {{ title: 'CLI'}} |
31 | | -# create an author if you haven't already |
32 | | -$ IROH_AUTHOR=$(iroh author create) |
33 | | - |
34 | | -# create a document |
35 | | -$ iroh docs create |
36 | | -created d7bb0092bf6d7ee3cb6bd255e88596d3ca16d50ce6935a7721f2ff836a3c0355 |
| 30 | +<% if (examples.cli) { %> |
| 31 | +```bash {{ title: 'CLI' }} |
| 32 | +<%- examples.cli %> |
| 33 | +``` |
| 34 | +<% } %> |
37 | 35 |
|
38 | | -# set a key |
39 | | -$ iroh doc 674deec7a19fec50fd6f486a5eef20509073ecf7c527b60a27c84baea90d3816 set "key" "value" |
40 | | -@ydzwyyes…: key = azceusiw… (5 B) |
| 36 | +<% if (examples.python) { %> |
| 37 | +```python {{ title: 'python' }} |
| 38 | +<%- examples.python %> |
41 | 39 | ``` |
| 40 | +<% } %> |
42 | 41 |
|
| 42 | +<% if (examples.rust) { %> |
43 | 43 | ```rust {{ title: 'rust' }} |
44 | | -#![cfg(feature = "mem-db")] |
45 | | - |
46 | | -use anyhow::{anyhow, Result}; |
47 | | -use futures::StreamExt; |
48 | | - |
49 | | -use iroh::{ |
50 | | - collection::IrohCollectionParser, |
51 | | - node::Node, |
52 | | - bytes::util::runtime, |
53 | | -}; |
54 | | -use iroh_sync::store::GetFilter; |
55 | | - |
56 | | -#[tokio::main] |
57 | | -async fn main() -> Result<()> { |
58 | | - // build the node |
59 | | - let rt = runtime::Handle::from_currrent(1).unwrap(); |
60 | | - let db = iroh::baomap::mem::Store::new(rt.clone()); |
61 | | - let store = iroh_sync::store::memory::Store::default(); |
62 | | - let node = Node::builder(db, store) |
63 | | - .collection_parser(IrohCollectionParser) |
64 | | - .runtime(&rt) |
65 | | - .bind_addr("127.0.0.1:0".parse()?); |
66 | | - |
67 | | - // start the node & create a client |
68 | | - let node = node.spawn().await?; |
69 | | - let client = node.client(); |
70 | | - |
71 | | - // create a document & author |
72 | | - let author = client.create_author().await?; |
73 | | - let doc = client.create_doc().await?; |
74 | | - |
75 | | - // set the key "key" to "value" |
76 | | - let key = b"key"; |
77 | | - let value = b"value"; |
78 | | - doc.set_bytes(author, key.to_vec(), value.to_vec()).await?; |
79 | | - println!("key is set!"); |
80 | | - |
81 | | - // read the value back |
82 | | - let filter = GetFilter::latest().with_key(key); |
83 | | - let entry = doc.get(filter).await?.next().await.ok_or_else(|| anyhow!("entry not found"))??; |
84 | | - let content = doc.get_content_bytes(&entry).await?; |
85 | | - |
86 | | - println!("value bytes: {:?}", content); |
87 | | - |
88 | | - Ok(()) |
89 | | -} |
| 44 | +<%- examples.rust %> |
90 | 45 | ``` |
91 | | - |
| 46 | +<% } %> |
92 | 47 | </CodeGroup> |
0 commit comments