Crates.io | rmarshal |
lib.rs | rmarshal |
version | 0.1.1 |
source | src |
created_at | 2022-01-09 15:27:12.673749 |
updated_at | 2022-01-15 17:17:49.629362 |
description | Document remarshaller. |
homepage | https://github.com/tvbaron/rmarshal |
repository | https://github.com/tvbaron/rmarshal |
max_upload_size | |
id | 510887 |
size | 137,260 |
rmarshal is a document remarshaller.
rmarshal [INPUT...] COMMAND [OUTPUT...]
Inputs and outputs are expressed in the same way. Before the first command, everything is interpreted as an input. After the last command, everything is interpreted as an output.
A PATH may be replaced by - to express either stdin or stdout depending on the context.
See the CLI Syntax for more details.
Commands consume and produce documents.
The copy command produces the same number of documents it consumes without any alteration. The goal is to change the format of files.
rmarshal [INPUT...] --copy [OUTPUT...]
$ cat data.json
{"name":"Althea","fingers":10}
$ rmarshal data.json --copy out.yaml
$ cat out.yaml
---
name: Althea
fingers: 10
The merge command consumes multiple documents and produces one.
rmarshal INPUT... --merge [--depth DEPTH] OUTPUT
The depth is meant for array and object values. It indicates the merging depth.
For example:
No depth option or a negative value indicates an infinite depth.
The render command consumes multiple documents and produces one string-based one.
rmarshal [INPUT...] --render PATH OUTPUT
The engine recognizes certain tags in the provided template and converts them based on the following rules:
<% Lua code. %>
<%= Lua expression -- replaced with result. %>
<%# Comment -- not rendered. %>
% A line of Lua code -- treated as <% line %>
%% replaced with % if first thing on a line and % processing is used
<%% or %%> -- replaced with <% or %> respectively.
Any leading whitespace are removed if the directive starts with <%-
.
Any trailing whitespace are removed if the directive ends with -%>
.
$ cat data.json
{"name":"Althea","fingers":10}
$ cat report
% local data = ctx:get_input(1)
My name is <%= data:get('name') %> and I have <%= data:get('fingers') %> fingers!
$ rmarshal data.json --render report out
$ cat out
My name is Althea and I have 10 fingers!
The transform command consumes and produces multiple documents.
rmarshal [INPUT...] --transform PATH [OUTPUT...]
See the Lua Prelude for more details.
$ cat data.json
{"name":"Althea","fingers":10}
$ cat script.lua
local data = ctx:get_input(1)
data:set("name", "James Hook")
data:set("rank", "captain")
data:set("fingers", 5)
ctx:set_output(data)
$ rmarshal data.json --transform script.lua out.yaml
$ cat out.yaml
---
name: James Hook
rank: captain
fingers: 5
Other commands are check, concat, pack and unpack.
Available file formats are plain, json, toml, yaml and lua.
The plain format is the unformatted format.
MIT.