Crates.io | config2args |
lib.rs | config2args |
version | 0.2.0 |
source | src |
created_at | 2019-02-28 11:45:02.26447 |
updated_at | 2019-03-22 16:11:58.179594 |
description | A CLI tool which converts config file into GNU option style string |
homepage | https://github.com/serihiro/config2args |
repository | https://github.com/serihiro/config2args |
max_upload_size | |
id | 117767 |
size | 14,226 |
This is a CLI tool which converts config file (JSON is only supported for now) into GNU option style string
$ cat test.json
{
"key1": 1,
"key2": "hello",
"key3": [2,3,4],
"key4": 1.4,
"key5": null,
"a": "b"
}
$ config2args test.json
--key1 1 --key2 hello --key3 2 3 4 --key4 1.4 --key5 -a b
cargo >= 1.32.0
is required. Using rustup is a good way to install rust build tools.
$ cargo install config2args
cargo >= 1.32.0
is required. Using rustup is a good way to install rust build tools.
$ git clone git@github.com:serihiro/config2args.git
$ cd config2args
$ cargo build --release
--
) and short key name (with -
)$ cat test.json
{
"k": 1,
"key": "hello"
}
$ config2args test.json
-k 1 --key hello
$ cat test.json
{
"key1": "a",
"key2": 1,
"key3": 1.4,
"key4": ["a", "b", "c"],
"key5": [1, 1.4, "c"]
}
$ config2args test.json
--key1 a --key2 1 --key3 1.4 --key4 a b c --key5 1 1.4 c
$ cat test.json
{
"_key1": "a",
"_key2": "b",
"key3": "c"
}
$ config2args test.json
a b --key3 c
"aaaa"
, [1, 2, 3]
.$ cat test.json
"abcd"
$ config2args test.json
abcd
$ cat test.json
[1,2,3]
$ config2args test.json
1 2 3
$ cat test.json
{
"key1": 1,
"key2": 2,
"key3": 3,
"key4": {
"k1" : 4,
"k2" : 5,
"a": 6
},
"z": {
"key5": 7,
"b": 8
}
}
$ config2args test.json
--key1 1 --key2 2 --key3 3 --key4.k1 4 --key4.k2 5 --key4.a 6 --z.key5 7 --z.b 8
If the file name of the input file ends with .tera
, the file is evalued as a tera template.
$ cat test.json.tera
{
"_setup_variable_for_tera": "{% set my_var = now() | date(format=\"%Y%m%d%H%M%S\") %}",
"output": "logs/{{my_var}}"
}
$ config2args test.json.tera
--output logs/20190323005419
In many cases, machine learning scripts are implemented with many CLI options.
For example, I often execute a python script like this:
$ python train_imagenet.py \
"$imagenet1k_base/train.ssv" \
"$imagenet1k_base/val.ssv" \
--root "$imagenet1k_base" \
--mean "$imagenet1k_base/mean.npy" \
--gpu 0 \
--arch resnet50 \
--batchsize "$batch_size" \
--val_batchsize "$batch_size" \
--epoch "$epoch" \
--loaderjob 2 \
--out "$output_path"
Of course, this is written in one shell script. But this style is not easy to read and update :(
So I wanted to manage these options with more comfortable format, like JSON or YAML.
$ python train_imagenet.py `config2args config.json`
MIT