mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-01 18:52:23 +02:00
Silent stderr output during app init for some commands (#293)
Avoid confusing the user for the commands outputing text to the user. fix #277
This commit is contained in:
parent
f2a53eb1e3
commit
1c9120e68b
1 changed files with 12 additions and 0 deletions
|
@ -3,6 +3,7 @@
|
|||
import os
|
||||
import pkgutil
|
||||
import random
|
||||
import sys
|
||||
from getpass import getpass
|
||||
|
||||
from flask_script import Manager, Command, Option
|
||||
|
@ -56,9 +57,20 @@ class ConfigTemplate(Command):
|
|||
|
||||
|
||||
def main():
|
||||
QUIET_COMMANDS = ('generate_password_hash', 'generate-config')
|
||||
|
||||
backup_stderr = sys.stderr
|
||||
# Hack to divert stderr for commands generating content to stdout
|
||||
# to avoid confusing the user
|
||||
if len(sys.argv) > 1 and sys.argv[1] in QUIET_COMMANDS:
|
||||
sys.stderr = open(os.devnull, 'w')
|
||||
|
||||
app = create_app()
|
||||
Migrate(app, db)
|
||||
|
||||
# Restore stderr (among other: to be able to display help)
|
||||
sys.stderr = backup_stderr
|
||||
|
||||
manager = Manager(app)
|
||||
manager.add_command('db', MigrateCommand)
|
||||
manager.add_command('generate_password_hash', GeneratePasswordHash)
|
||||
|
|
Loading…
Reference in a new issue