ssato / python-anyconfig

Python library provides common APIs to load and dump configuration files in various formats
MIT License
275 stars 31 forks source link

fix: re-enable output type guessing from output file name #132

Closed masatake closed 2 years ago

masatake commented 2 years ago

The refactoring done in a4a53ab900045b023777b06c160ea43197fe24d3 introduced unexpected side-effect. With the commit anyconfig lost the function to guess the output type from the output file name:

$ cat foo.json
{"a": 1}
$ anyconfig_cli -o foo.yml foo.json
$ cat foo.yml
cat foo.yml
{"a": 1}$

anyconfig_cli emits JSON output though YAML output guessed from 'foo.yml' is execpted,

Signed-off-by: Masatake YAMATO yamato@redhat.com

ssato commented 2 years ago

Thanks a lot! Good Catch. I'll look into its details this weekend.

ssato commented 2 years ago

The fix you proposed may resolve a problem but IMHO, the CLI code itself is fragile and buggy and I don't want to apply your fixes now. Instead, I tried to clean up and re-organize its code in the branch named 'fix/cli-test-cases'.

It seems worked well and I'll try to apply changes after I confirmed that it works.

So, sorry but wait for a while, please.

ssato commented 2 years ago

FYI. I think that I could fix this and make sure it works with some test cases added in 22acbd1

ssato commented 2 years ago

It should be resolved in the latest version, 0.12.0.

$ rpm -q python3-anyconfig    # It is available from my copr repo.
python3-anyconfig-0.12.0-1.fc34.noarch
$ cat << EOF > /tmp/foo.json
heredoc> {"a": 1}
heredoc> EOF
$ anyconfig_cli -o /tmp/foo.yml /tmp/foo.json
$ cat /tmp/foo.yml
a: 1
$
masatake commented 2 years ago

I tried the new version and I confirmed it worked fine. Thank you.