NestedTextTo, CLI conversions with type casting #40
Replies: 8 comments 10 replies
-
That looks like a really nice tool to me! I tried it out on some of my files and it worked flawlessly. I'll leave it to @KenKundert to update the docs, but thanks for sharing! |
Beta Was this translation helpful? Give feedback.
-
Related: my |
Beta Was this translation helpful? Give feedback.
-
Looks like a nice package. I have added it as a related project in the documentation. I also added a comment about Lewis's nt-cli to the documentation. |
Beta Was this translation helpful? Give feedback.
-
Which version of NestedText are you supporting? |
Beta Was this translation helpful? Give feedback.
-
One other thought I just had, which you should feel free to take or leave: the name |
Beta Was this translation helpful? Give feedback.
-
I have some suggestions as well. I wrote some programs that are similar to yours and put them in the examples directory:
I think the JSON translators are pretty good, but the others are after thoughts I put little effort in. You might want to take a look at the error handling in the JSON translators for guidance on how to improve your error handling. One translator I had in the back of my mind to write but never did was a Python translator. It is not uncommon to use Python to hold configuration information and data. Including a Python translator might fit in well with the translators you have already implemented. |
Beta Was this translation helpful? Give feedback.
-
Andyde, I would appreciate it if you would consider doing at least a minor release. I feel a little uncomfortable recommending a package with a version number htat starts with 0.0. Of course you should only do that if your feel its ready to be used by others. If you feel that is not the case, let me know and I will remove the pointer for the time being. |
Beta Was this translation helpful? Give feedback.
-
NestedTextTo now provides automatic generation of the simple "schema" types files, for easier type-preserving round-tripping.
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00
[database]
enabled = true
ports = [ 8000, 8001, 8002 ]
data = [ ["delta", "phi"], [3.14] ]
temp_targets = { cpu = 79.5, case = 72.0 }
[servers]
[servers.alpha]
ip = "10.0.0.1"
role = "frontend"
[servers.beta]
ip = "10.0.0.2"
role = "backend" $ toml2nt sample.toml >sample.nt
$ toml2nt sample.toml --to-schema >sample.types.nt
$ nt2toml sample.nt --schema sample.types.nt title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27 07:32:00-08:00
[database]
enabled = true
ports = [
8000,
8001,
8002,
]
data = [
[
"delta",
"phi",
],
[
3.14,
],
]
[database.temp_targets]
cpu = 79.5
case = 72
[servers.alpha]
ip = "10.0.0.1"
role = "frontend"
[servers.beta]
ip = "10.0.0.2"
role = "backend" $ cat sample.types.nt date:
- owner.dob
boolean:
- database.enabled
number:
- database.ports[0]
- database.ports[1]
- database.ports[2]
- database.data[1][0]
- database.temp_targets.cpu
- database.temp_targets.case
# Above is a schema that literally matches the current data.
# Below, for your review, is a guess at a better schema.
# date:
# - owner.dob
# boolean:
# - database.enabled
# number:
# - database.data
# - database.temp_targets.case
# - database.ports
# - database.temp_targets.cpu I still need to improve the commented suggested "better" schema; in this example, that one fails to properly match the database ports and the |
Beta Was this translation helpful? Give feedback.
-
Hello!
Thanks so much for NestedText, I'm a big fan.
So I made a convenient CLI for converting between it and JSON, YAML, and TOML, with concise type casting (thanks to yamlpath and cattrs especially).
I'm wondering if any Kunderts or other NestedText users would provide any feedback, and if it might get listed as a related project.
The project is on PyPI as
nt2
, and for TOML support should be installed asnt2[toml]
.It may be invoked as
nt2json
,nt2yaml
,nt2toml
,json2nt
,yaml2nt
, ortoml2nt
. More details can be found at the repo itself.Thanks for any response!
Beta Was this translation helpful? Give feedback.
All reactions