yuzutech / kroki-cli

A Kroki CLI
MIT License
65 stars 6 forks source link

Fails to get --config option to function (Kroki CLI) #39

Open DaLynxx opened 1 week ago

DaLynxx commented 1 week ago

Hello,

I might be missing somthing when using Kroki cli.

I'm trying to get Kroki-CLI to work while using it's --config option. (Windows 11, Kroki CLI version 0.5.0)

Using the environment variables it works fine to re-direct to my own kroki renderingserver. However, if i try to get it via a .yml file it always goes to render at demo.kroki.io (Validating via Wireshark).

One test for "failure" is to have a) evn variable KROKI_ENDPOINT set to a server that does not have kroki installed (for example localhost) i then get the expected fail mesage:

fail to generate the image: Get "https://localhost:8000/seqdiag/svg/eNoqTi1MyUxMV6jm5VJQSCrKLy9OLVJQ0LVTKE9NKk4tKkstUojOSUxKzVGwVVBydw1R0M_MS0mt0Msoyc1RirVG1mWjq4vQZU2MeQH-wSEK-kk5-en6yfm5ual5JVAjEYpBWlMSSxKTEotTkXR6-gW7BoUo4NIFcgpMF1431vJyAQIAAP__hp9RJA==": dial tcp [::1]:8000: connectex: No connection could be made because the target machine actively refused it.

However, if I create a config.yml with

endpoint: 'http://localhost:8000'
timeout: '30s'

The kroki convert command (with --config config.yml) will happily generate me an svg using demo.kroki.io. It does not seem to be a "fallback to demo.kroki.io" because if the endpoint in the file is specified to the kroki server that I have locally it still directs the rendering to demo.kroki.io.

What am I doing wrong?

ggrossetie commented 1 week ago

I think it's related to https://github.com/spf13/viper/issues/1784. Adding viper.SetConfigType("yaml") before reading the configuration file seems to fix this issue: https://github.com/yuzutech/kroki-cli/blob/d923cdd8336257d0f19f2993c112853859f68607/pkg/convert.go#L216

Feel free to submit a pull request.