NASA-AMMOS / aerie-cli

An unofficial CLI for interacting with Aerie planning software
MIT License
3 stars 4 forks source link

Update configurations after clean #68

Closed Navarro-Jonathan closed 1 year ago

Navarro-Jonathan commented 1 year ago

PersistentConfigurationManager will read the persistent files only once for each instance of the program. This is not usually a problem when using the CLI. However, if a user were to call clean through the API, PersistentConfigurationManager's cached configurations would not be updated. This means that subsequent calls using a CLI runner to configurations list, or any API functions would not read the change to the persistent configurations.

Note that this is not a problem in the other functions that alter the persistent files, since they change PersistentConfigurationManager's cached configurations accordingly.

To resolve this, clean now makes PersistentConfigurationManager re-read the persistent files after deleting them. Additionally, the active session is now unset.

cartermak commented 1 year ago

Could we do a similar reset method for the persistent sessions? Something that just runs cls._active_session = None.

Navarro-Jonathan commented 1 year ago

Could we do a similar reset method for the persistent sessions? Something that just runs cls._active_session = None.

In unset_active_session, the .session files are also being deleted: https://github.com/NASA-AMMOS/aerie-cli/blob/5b0d373877b1fc76d42b73f7dbff0ea33eb38833/src/aerie_cli/persistent.py#L177-L197C20

However, we don't need to read the name from the session, and we could remove the call to _load_active_session.

So we could create a reset with something along these lines:

cls._active_session = None

# Get any/all open sessions. List in chronological order, newest first
fs: List[Path] = [
    f for f in SESSION_FILE_DIRECTORY.glob('*.aerie_cli.session')]
if not len(fs):
    return
# Delete all session files
for fn in fs:
    fn.unlink()
cartermak commented 1 year ago

What's the behavior of SESSION_FILE_DIRECTORY.glob('*.aerie_cli.session') when that directory has been deleted, though? Will that line error out?

Navarro-Jonathan commented 1 year ago

What's the behavior of SESSION_FILE_DIRECTORY.glob('*.aerie_cli.session') when that directory has been deleted, though? Will that line error out?

It does not seem to throw any errors even if that directory has been deleted. It just continues silently.