Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't use .once more than once. #146

Closed
mjpieters opened this issue Jul 10, 2022 · 1 comment · Fixed by #147
Closed

Can't use .once more than once. #146

mjpieters opened this issue Jul 10, 2022 · 1 comment · Fixed by #147

Comments

@mjpieters
Copy link
Contributor

I expect the .once command to work more than once in a session, each time resulting in the next query output to be written to a designated file.

Instead, you can use .once just once in a session. After that you have to restart litecli. It doesn't matter what the arguments are; executing .once a second time in the same session has no effect.

This is caused by the written_to_once_file flag; it is set to True when output is sent to a file, but then never set back to False.

With written_to_once_file set to True, the next time you execute .once, the set_once() command still sets once_file, but immediately afterwards, unset_once_if_written() is executed after the command completes, which sets once_file back to None, so by the time your next output-producing command is run, nothing will be written out to the file.

@mjpieters
Copy link
Contributor Author

I can confirm that changing unset_once_if_written to:

@export
def unset_once_if_written():
    """Unset the once file, if it has been written to."""
    global once_file, written_to_once_file
    if written_to_once_file:
        once_file = written_to_once_file = None

fixes the issue. Clearing written_to_once_file makes sure that the trigger doesn't fire forever for later commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant