examples: relpipe-in-cli v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Thu, 06 Dec 2018 16:06:32 +0100
branchv_0
changeset 185 6cd2e54d90ea
parent 184 9ad44348e6aa
child 186 e33f13c91289
examples: relpipe-in-cli
relpipe-data/examples.xml
--- a/relpipe-data/examples.xml	Thu Dec 06 15:13:28 2018 +0100
+++ b/relpipe-data/examples.xml	Thu Dec 06 16:06:32 2018 +0100
@@ -9,6 +9,118 @@
 	<text xmlns="http://www.w3.org/1999/xhtml">
 		
 		
+		<h3>relpipe-in-cli: Hello Wordl!</h3>
+		
+		<p>
+			Let's start with and obligatory Hello World example.
+		</p>
+		
+		<m:pre jazyk="bash"><![CDATA[relpipe-in-cli generate "relation_from_cli" 3 \
+	"a" "integer" \
+	"b" "string" \
+	"c" "boolean" \
+	"1" "Hello" "true" \
+	"2" "World!" "false"]]></m:pre>
+	
+		<p>
+			This command generates relational data.
+			In order to see them, we need to convert them to some other format.
+			For now, we will use the "tabular" format and pipe relational data to the <code>relpipe-out-tabular</code>.
+		</p>
+		
+		<m:pre jazyk="bash"><![CDATA[relpipe-in-cli generate "relation_from_cli" 3 \
+		"a" "integer" \
+		"b" "string" \
+		"c" "boolean" \
+		"1" "Hello" "true" \
+		"2" "World!" "false" \
+	| relpipe-out-tabular]]></m:pre>
+	
+		<p>Output:</p>
+
+		<pre><![CDATA[relation_from_cli:
+ ╭─────────────┬────────────┬─────────────╮
+ │ a (integer) │ b (string) │ c (boolean) │
+ ├─────────────┼────────────┼─────────────┤
+ │           1 │ Hello      │        true │
+ │           2 │ World!     │       false │
+ ╰─────────────┴────────────┴─────────────╯
+Record count: 2
+]]></pre>
+
+		<p>
+			The syntax is simple as we see above. We specify the name of the relation, number of attributes,
+			and then their definitions (names and types),
+			followed by the data.
+		</p>
+		
+		<h3>relpipe-in-cli: STDIN</h3>
+		
+		<p>
+			The number of CLI arguments is limited and their are passed at once to the process.
+			So there is option to pass the values from STDIN instead of CLI arguments.
+			Values on STDIN are expected to be separated by the null-byte.
+			We can generate such data e.g. using <code>echo</code> and <code>tr</code> (or using <code>printf</code> or other commands):
+		</p>
+		
+		<m:pre jazyk="bash"><![CDATA[echo -e "1\nHello\ntrue\n2\nWorld\nfalse" \
+	| tr \\n \\0 \
+	| relpipe-in-cli generate-from-stdin relation_from_stdin 3 \
+		a integer \
+		b string \
+		c boolean \
+	| relpipe-out-tabular]]></m:pre>
+
+		<p>
+			The output is same as above.
+			We can use this approach to convert various formats to relational data.
+			There are lot of data already in the form of null-separated values e.g. the process arguments:
+		</p>
+		
+		<m:pre jazyk="bash"><![CDATA[cat /proc/$(pidof mc)/cmdline \
+	| relpipe-in-cli generate-from-stdin mc_args 1 a string \
+	| relpipe-out-tabular
+]]></m:pre>
+	
+		<p>If we have <code>mc /etc/ /tmp/</code> running in some other terminal, the output will be:</p>
+		
+		<pre><![CDATA[mc_args:
+ ╭────────────╮
+ │ a (string) │
+ ├────────────┤
+ │ mc         │
+ │ /etc/      │
+ │ /tmp/      │
+ ╰────────────╯
+Record count: 3]]></pre>
+
+		<p>
+			Also the <code>find</code> command can produce data separated by the null-byte:
+		</p>
+		
+		<m:pre jazyk="bash"><![CDATA[find /etc/ -name '*ssh*_*' -print0 \
+	| relpipe-in-cli generate-from-stdin files 1 file_name string \
+	| relpipe-out-tabular]]></m:pre>
+	
+		<p>Will display something like this:</p>
+		
+		<pre><![CDATA[files:
+ ╭───────────────────────────────────╮
+ │ file_name                (string) │
+ ├───────────────────────────────────┤
+ │ /etc/ssh/ssh_host_ecdsa_key       │
+ │ /etc/ssh/sshd_config              │
+ │ /etc/ssh/ssh_host_ed25519_key.pub │
+ │ /etc/ssh/ssh_host_ecdsa_key.pub   │
+ │ /etc/ssh/ssh_host_rsa_key         │
+ │ /etc/ssh/ssh_config               │
+ │ /etc/ssh/ssh_host_ed25519_key     │
+ │ /etc/ssh/ssh_import_id            │
+ │ /etc/ssh/ssh_host_rsa_key.pub     │
+ ╰───────────────────────────────────╯
+Record count: 9]]></pre>
+		
+		
 		<h3>relpipe-tr-validator</h3>
 		
 		<p>