transfer 全平臺Windows linux mac配置檔案轉換工具

rinetd發表於2018-08-27

transfer

  • 支援全平臺 Windows linux mac
  • 自動檢測轉換檔案格式
  • 支援多種格式相互轉換 HCL ⇄ JSON ⇄ YAML⇄TOML⇄XML⇄plist⇄pickle⇄properties ...

install

$ go get github.com/rinetd/transfer
複製程式碼

Download

https://github.com/rinetd/transfer/releases
複製程式碼

usage

usage:

	transfer [-f] [-s input.yaml] [-t output.json] /path/to/input.yaml [/path/to/output.json]

Converts from one encoding to another. Supported formats (and their file extensions):

	- JSON (.json)
	- TOML (.toml)
	- YAML (.yaml or .yml)
	- HCL (.hcl or .tf)
	- XML (.xml)
	- MSGPACK (.msgpack)
	- PLIST (.plist)
	- BSON (.bson)
	- PICKLE (.pickle)
	- PROPERTIES (.prop or .props or .properties)

複製程式碼

docker usage

# build the transfer image
docker build -t rientd/transfer .
複製程式碼

examples

yaml格式轉換為json

將 ./data/main.yml 轉換到 ./data/main.json 以下幾種命名格式是等價的

$ transfer -f data/main.yaml        (default output `json` format)
$ transfer -f data/main.yaml data/main.json
$ transfer -f -t json data/main.yaml
$ transfer -f -s data/main.yaml     (default output `json` format)
$ transfer -f -s data/main.yaml -t json 
$ transfer -f -s data/main.yaml -t data/main.json 
複製程式碼
Author:
  email: rinetd@163.com
  github: rinetd
menu:
  main:
  - Identifier: categories
    Name: categories
    Pre: <i class='fa fa-category'></i>
    URL: /categories/
    Weight: -102
  - Identifier: tags
    Name: tags
    Pre: <i class='fa fa-tags'></i>
    URL: /tags/
    Weight: -101
theme: hueman

複製程式碼
{
	"Author": {
		"email": "rinetd@163.com",
		"github": "rinetd"
	},
	"menu": {
		"main": [
			{
				"Identifier": "categories",
				"Name": "categories",
				"Pre": "<i class='fa fa-category'></i>",
				"URL": "/categories/",
				"Weight": -102
			},
			{
				"Identifier": "tags",
				"Name": "tags",
				"Pre": "<i class='fa fa-tags'></i>",
				"URL": "/tags/",
				"Weight": -101
			}
		]
	},
	"theme": "hueman"
}
複製程式碼

其他格式轉換:

json -> hcl

$ transfer main.json main.hcl
複製程式碼

yaml -> toml

$ transfer main.yaml main.toml
複製程式碼

相關文章