Passing an invalid profile name on the commandline will now show picker

https://forums.ankiweb.net/t/open-with-profiles-to-start/27612
This commit is contained in:
Damien Elmes 2023-03-02 17:13:04 +10:00
parent d9d36078f1
commit d1abfbc6a1
2 changed files with 11 additions and 12 deletions

View file

@ -301,9 +301,10 @@ class AnkiQt(QMainWindow):
self.pendingImport: str | None = None
self.restoring_backup = False
# profile not provided on command line?
if not self.pm.name:
# if there's a single profile, load it automatically
# - if a valid profile was provided on commandline, we load it
# - if an invalid profile was provided, we skip this step and show the picker
# - if no profile was provided, we use this step
if not self.pm.name and not self.pm.invalid_profile_provided_on_commandline:
profs = self.pm.profiles()
name = self.pm.last_loaded_profile_name()
if len(profs) == 1:

View file

@ -123,6 +123,7 @@ class ProfileManager:
self.name: str | None = None
self.db: DB | None = None
self.profile: dict | None = None
self.invalid_profile_provided_on_commandline = False
self.base = str(base)
def setupMeta(self) -> LoadMetaResult:
@ -131,18 +132,15 @@ class ProfileManager:
self.firstRun = res.firstTime
return res
# profile load on startup
# -p profile provided on command line.
def openProfile(self, profile: str) -> None:
if profile:
if profile not in self.profiles():
QMessageBox.critical(
None, tr.qt_misc_error(), tr.profiles_profile_does_not_exist()
)
sys.exit(1)
if profile not in self.profiles():
self.invalid_profile_provided_on_commandline = True
else:
try:
self.load(profile)
except TypeError as exc:
raise Exception("Provided profile does not exist.") from exc
except Exception as exc:
self.invalid_profile_provided_on_commandline = True
# Profile load/save
######################################################################