ESGF / esgf-download

ESGF data transfer and replication tool
https://esgf.github.io/esgf-download/
BSD 3-Clause "New" or "Revised" License
15 stars 2 forks source link

Trying to generate a config file after modifying values results in a `FileExistsError` #18

Closed Zeitsperre closed 1 year ago

Zeitsperre commented 1 year ago

Example workflow:

(esgf) fedora ~ $ esgpull config api.index_node esgf-data.dkrz.de
[api]
index_node = "esgf-data.dkrz.de"

Previous value: esgf-node.ipsl.upmc.fr

Then:

(esgf) fedora ~ $ esgpull config --generate
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────── /home/tjs/.esgpull/config.toml ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
[paths]
auth = "/home/me/.esgpull/auth"
data = "/home/me/.esgpull/data"
db = "/home/me/.esgpull/db"
log = "/home/me/.esgpull/log"
tmp = "/home/me/.esgpull/tmp"

[credentials]
filename = "credentials.toml"

[cli]
page_size = 20

[db]
filename = "esgpull.db"

[download]
chunk_size = 67108864
http_timeout = 20
max_concurrent = 5

[api]
index_node = "esgf-data.dkrz.de"
http_timeout = 20
max_concurrent = 5
page_limit = 50

[api.default_options]
distrib = "false"
latest = "true"
replica = "none"
retracted = "false"

FileExistsError: /home/me/.esgpull/config.toml
See /home/me/.esgpull/log/esgpull-config-2023-07-24_18-31-58.log for error log.
Aborted!
svenrdz commented 1 year ago

There is a clash of behaviours indeed, the --generate flag was added long before implementing a way to modify the configuration from the command line. Here, after setting the api.index_node value, the file is created and contains only that value. All other options are using their defaults, loaded at runtime.

I'm curious about what you expected from this workflow, do you think --generate should fill in the blanks and write all missing defaults to the existing file?

Since the idea behind the --generate flag was to create a file that contains the default config, another possible output is a prompt asking for permission to overwrite the existing file with defaults only.

Zeitsperre commented 1 year ago

I'm curious about what you expected from this workflow, do you think --generate should fill in the blanks and write all missing defaults to the existing file?

Since the idea behind the --generate flag was to create a file that contains the default config, another possible output is a prompt asking for permission to overwrite the existing file with defaults only.

I guess I would have expected it to fill out the entire working configuration, including any existing modifications already present in config.toml, with a prompt to overwrite the existing configuration, but I would be happy with it generating a default config and asking for overwrite permissions, rather than failing.

I will admit that this is very much a specific UX trip fall, but given that I ran into this problem on first usage and the fix is quite simple, I figured why not address it.

svenrdz commented 1 year ago

There were a few parts of the config implementation that I wanted to improve, so I took the opportunity to implement the behaviour of filling an existing config file with missing options, as you describe.

I will admit that this is very much a specific UX trip fall, but given that I ran into this problem on first usage and the fix is quite simple, I figured why not address it.

Having used a good number of CLI tools with very pleasing UX, I feel it's always rewarding to spend some time on it. :) Thanks for pointing it out!