Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

From data to documents

License

NotificationsYou must be signed in to change notification settings

jojomi/io

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Godoc ReferenceGo VersionLast CommitGo Report CardLicense

Take data, make documents!

Overview

io overview

io is supposed to be a small and useful tool for reworking data from JSON, YAML, or CSV sources into any text or HTML format.

The templates used for the transformation feature all the elements ofGo Templatesplus a set of usefulfunctions.

Gems are theexec functions fromtplfuncs that, combined with the line based matchers and filters,can be used to create dynamic auto-generated documents.

Also, this tool can be used to set up simple and easy includes for the system Hostsfile at/etc/hosts, seehere.

How to Use

Usage:  io [flags]  io [command]Available Commands:  completion  Generate the autocompletion script for the specified shell  help        Help about any command  version     Flags:      --allow-exec               allow execution of commands during templating phase, implies --allow-io and --allow-network      --allow-io                 allow reading and writing files during templating phase      --allow-network            allow network communication during templating phase  -h, --help                     help for io  -i, --input string             input filename including extension optionally with path, or inline JSON if first char is { (default "{}")  -o, --output string            output filename including extension optionally with path  -w, --overwrite stringArray    overwrite input data by path (for YML and JSON inputs only)  -t, --template string          template filename including extension optionally with path      --template-inline string   inline template contentUse "io [command] --help" for more information about a command.

Example

With input data fromtest/input/simple.yml

creator:name:John Doeage:54

and the templatetest/template/creator.html

<h1>Creator:{{ .creator.name }}( {{- .creator.age }}yo)</h1>

you can useio to get this result:

> io -i test/input/simple.yml -t test/template/creator.html<h1>    Creator:    John Doe    (54yo)</h1>

If you want to overwrite values from the input data uses--overwrite like this:

> io --input test/input/simple.yml --template test/template/creator.html --overwrite creator.age=62 --overwrite creator.name=Walther<h1>    Creator:    Walther    (62yo)</h1>

Auto-generate /etc/hosts

Create a file named/etc/hosts.gen:

###########################################################################   update /etc/hosts ONLY like this after editing                       ##   /etc/hosts.d/ and /etc/hosts.gen:                                    ##   sudo io --allow-exec --template /etc/hosts.gen --output /etc/hosts   ############################################################################ Host addresses127.0.0.1  localhost::1        localhost ip6-localhost ip6-loopbackff02::1    ip6-allnodesff02::2    ip6-allrouters{{- /* Loop files*/}}{{- range glob"/etc/hosts.d/*" }}    {{- newline 2 -}}# START {{ . }}    {{- newline -}}    {{ include.| trim }}    {{- newline -}}# END {{ . }}{{- end }}

Now you can place an arbitrary number of files in/etc/hosts.d (create the directory like this:mkdir /etc/hosts.d).These files will be inlined as described in the template. The generated comment makes sure that you always know which source file to edit if there is anything to be changed.

To update the hostsfile the system will use at/etc/hosts, run this:

sudo io --allow-exec --template /etc/hosts.gen --output /etc/hosts

Other content around therange operation is left untouched, but can still only be edited in/etc/hosts.gen otherwise it would be overwritten.

Template Functions

All functions defined injojomi/tplfuncs (theexec* variants are only avaiable when--allow-exec is given when callingio due to security implications)

A quick introduction to Golang Templates can be found atHugo.

How to Install

io Command

go install github.com/jojomi/io/cmd/io@latest

github.com/jojomi/io Library

go get -u github.com/jojomi/io

Who uses it?

io doesitself, seebuild.sh which generates this very document fromdocu/README.tpl.md. It shows how to useexec functions as well, but does not take dynamic input data.

About

From data to documents

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp