[IMP] Harmonize run and upgrade cli command. Allow to call command with argument --with-demo / --without-demo like in install-from-csv.

For that purpose, create a new decorator.
[REF] Change the default of install-from-csv to harmonize. (allways False)
This commit is contained in:
Sylvain LE GAL 2024-03-01 15:21:34 +01:00
parent 02c6fa48cf
commit d890a460ea
4 changed files with 27 additions and 7 deletions

View File

@ -3,6 +3,7 @@ from loguru import logger
from odoo_openupgrade_wizard.cli.cli_options import (
database_option,
demo_option,
get_migration_step_from_options,
)
from odoo_openupgrade_wizard.tools.tools_odoo import (
@ -16,11 +17,7 @@ from odoo_openupgrade_wizard.tools.tools_postgres import ensure_database
@click.command()
@database_option
@click.option(
"--with-demo/--whitout-demo",
default=True,
help="Create database with or without demo data.",
)
@demo_option
@click.pass_context
def install_from_csv(ctx, database, with_demo):
migration_step = get_migration_step_from_options(ctx, 1)

View File

@ -44,6 +44,15 @@ def last_step_option(function):
return function
def demo_option(function):
function = click.option(
"--with-demo/--without-demo",
default=False,
help="Create database with or without demo data.",
)(function)
return function
def database_option(function):
function = click.option(
"-d",

View File

@ -3,6 +3,7 @@ from loguru import logger
from odoo_openupgrade_wizard.cli.cli_options import (
database_option,
demo_option,
get_migration_step_from_options,
step_option,
)
@ -13,6 +14,7 @@ from odoo_openupgrade_wizard.tools.tools_postgres import ensure_database
@click.command()
@step_option
@database_option
@demo_option
@click.option(
"--stop-after-init",
is_flag=True,
@ -36,7 +38,15 @@ from odoo_openupgrade_wizard.tools.tools_postgres import ensure_database
" Let empty to use the defaut execution of the migration step.",
)
@click.pass_context
def run(ctx, step, database, stop_after_init, init_modules, execution_context):
def run(
ctx,
step,
database,
with_demo,
stop_after_init,
init_modules,
execution_context,
):
migration_step = get_migration_step_from_options(ctx, step)
ensure_database(ctx, database, state="present")
try:
@ -47,6 +57,7 @@ def run(ctx, step, database, stop_after_init, init_modules, execution_context):
detached_container=not stop_after_init,
init=init_modules,
stop_after_init=stop_after_init,
demo=with_demo,
execution_context=execution_context,
)
if not stop_after_init:

View File

@ -3,6 +3,7 @@ from loguru import logger
from odoo_openupgrade_wizard.cli.cli_options import (
database_option_required,
demo_option,
first_step_option,
get_migration_steps_from_options,
last_step_option,
@ -21,8 +22,9 @@ from odoo_openupgrade_wizard.tools.tools_postgres import (
@first_step_option
@last_step_option
@database_option_required
@demo_option
@click.pass_context
def upgrade(ctx, first_step, last_step, database):
def upgrade(ctx, first_step, last_step, database, with_demo):
migration_steps = get_migration_steps_from_options(
ctx, first_step, last_step
)
@ -36,6 +38,7 @@ def upgrade(ctx, first_step, last_step, database):
detached_container=False,
update="all",
stop_after_init=True,
demo=with_demo,
)
except (KeyboardInterrupt, SystemExit):
logger.info("Received Keyboard Interrupt or System Exiting...")