dbcli/litecli

`startup_commands` fails when config value is a single string.

gvoysey opened this issue · 4 comments

Using litecli version 1.10.1, installed with pipx on linux; base python is a pyenv-installed 3.10.10.

Given the following contents of ~/.config/litecli/config:

[startup_commands]
commands = ".tables"

loading litecli fails:

.
Could not execute all startup commands:
Not connected to database.
(none)>

If the config is changed to add a trailing comma:

[startup_commands]
commands = ".tables",

then the .tables command is correctly executed.

I suspect this is because without the comma, python is iterating the over the string ".tables", not the list [".tables",]:

litecli/litecli/main.py

Lines 591 to 596 in 9d5bcf0

for command in self.startup_commands["commands"]:
try:
res = sqlexecute.run(command)
except Exception as e:
click.echo(command)
self.echo(str(e), err=True, fg="red")

Adding a print above L592 confirms.
Without a comma:
self.startup_commands={'commands': '.tables'}

With a comma:
self.startup_commands={'commands': ['.tables']}

That is quite the embarrassing bug. Thanks for reporting it. Looking into it now.

if it's any consolation, i accidentally loop over the characters of a string instead of strings in a list at least once a quarter!

I've released a new version with the bug fix. Thanks again for reporting.