1010from .helper import CommandHelper
1111
1212
13- def register_backup_db (subparsers : argparse ._SubParsersAction ):
14- def call (** kwargs ):
15- helper = CommandHelper ()
16-
17- settings = (
18- f"{ helper .project_id } .settings.production"
19- if helper .is_production ()
20- else f"{ helper .project_id } .settings.development"
21- )
22-
23- web_container_id = helper .find_running_container_id ("web" )
24- if web_container_id is None :
25- sys .exit ("Web container is not running." )
26-
27- helper .execute_cmd (
28- (
29- f"docker exec --env DJANGO_SETTINGS_MODULE={ settings } "
30- f"{ web_container_id } ./manage.py dbbackup --clean -v 2"
31- )
32- )
33-
34- info = "Backup database in running container stack"
35- parser = subparsers .add_parser (
36- "backup_db" ,
37- help = info ,
38- description = info ,
39- epilog = "For backup location see DBBACKUP_STORAGE_OPTIONS setting" ,
40- )
41- parser .set_defaults (func = call )
42-
43-
4413def register_compose_up (subparsers : argparse ._SubParsersAction ):
4514 def call (build : bool , profile : list [str ], extra_args : list [str ], ** kwargs ):
4615 helper = CommandHelper ()
@@ -64,7 +33,7 @@ def call(build: bool, profile: list[str], extra_args: list[str], **kwargs):
6433 helper .execute_cmd (cmd )
6534
6635 info = "Start stack with docker compose"
67- parser = subparsers .add_parser ("compose_up " , help = info , description = info )
36+ parser = subparsers .add_parser ("compose-up " , help = info , description = info )
6837 parser .add_argument ("--build" , action = "store_true" , help = "Build images before starting" )
6938 parser .add_argument ("--profile" , action = "append" , help = "Docker compose profile(s) to use" )
7039 parser .set_defaults (func = call )
@@ -81,12 +50,68 @@ def call(cleanup: bool, profile: list[str], **kwargs):
8150 helper .execute_cmd (cmd )
8251
8352 info = "Stop stack with docker compose"
84- parser = subparsers .add_parser ("compose_down " , help = info , description = info )
53+ parser = subparsers .add_parser ("compose-down " , help = info , description = info )
8554 parser .add_argument ("--cleanup" , action = "store_true" , help = "Remove orphans and volumes" )
8655 parser .add_argument ("--profile" , action = "append" , help = "Docker compose profile(s) to use" )
8756 parser .set_defaults (func = call )
8857
8958
59+ def register_db_backup (subparsers : argparse ._SubParsersAction ):
60+ def call (** kwargs ):
61+ helper = CommandHelper ()
62+
63+ settings = (
64+ f"{ helper .project_id } .settings.production"
65+ if helper .is_production ()
66+ else f"{ helper .project_id } .settings.development"
67+ )
68+
69+ web_container_id = helper .find_running_container_id ("web" )
70+ if web_container_id is None :
71+ sys .exit ("Web container is not running." )
72+
73+ helper .execute_cmd (
74+ (
75+ f"docker exec --env DJANGO_SETTINGS_MODULE={ settings } "
76+ f"{ web_container_id } ./manage.py dbbackup --clean -v 2"
77+ )
78+ )
79+
80+ info = "Backup database in running container stack"
81+ parser = subparsers .add_parser (
82+ "db-backup" ,
83+ help = info ,
84+ description = info ,
85+ epilog = "For backup location see DBBACKUP_STORAGE_OPTIONS setting" ,
86+ )
87+ parser .set_defaults (func = call )
88+
89+
90+ def register_db_restore (subparsers : argparse ._SubParsersAction ):
91+ def call (** kwargs ):
92+ helper = CommandHelper ()
93+
94+ settings = (
95+ f"{ helper .project_id } .settings.production"
96+ if helper .is_production ()
97+ else f"{ helper .project_id } .settings.development"
98+ )
99+ web_container_id = helper .find_running_container_id ("web" )
100+ if web_container_id is None :
101+ sys .exit ("Web container is not running. Run 'uv run ./manage.py compose-up' first." )
102+
103+ helper .execute_cmd (
104+ (
105+ f"docker exec --env DJANGO_SETTINGS_MODULE={ settings } "
106+ f"{ web_container_id } ./manage.py dbrestore"
107+ )
108+ )
109+
110+ info = "Restore database in container from the last backup"
111+ parser = subparsers .add_parser ("db-restore" , help = info , description = info )
112+ parser .set_defaults (func = call )
113+
114+
90115def register_format_code (subparsers : argparse ._SubParsersAction ):
91116 def call (** kwargs ):
92117 helper = CommandHelper ()
@@ -101,7 +126,7 @@ def call(**kwargs):
101126 helper .execute_cmd ("uv run djlint . --reformat" )
102127
103128 parser = subparsers .add_parser (
104- "format_code " ,
129+ "format-code " ,
105130 help = "Format the source code with ruff and djlint" ,
106131 )
107132 parser .set_defaults (func = call )
@@ -113,7 +138,7 @@ def call(length: int, **kwargs):
113138 print (helper .generate_auth_token (length ))
114139
115140 info = "Generate an authentication token"
116- parser = subparsers .add_parser ("generate_auth_token " , help = info , description = info )
141+ parser = subparsers .add_parser ("generate-auth-token " , help = info , description = info )
117142 parser .add_argument ("--length" , type = int , default = 20 , help = "Length of the token (default: 20)" )
118143 parser .set_defaults (func = call )
119144
@@ -174,7 +199,7 @@ def call(**kwargs):
174199 print (f"Generated chain file at { chain_path .absolute ()} " )
175200
176201 info = "Generate certificate chain file for a signed certificate"
177- parser = subparsers .add_parser ("generate_certificate_chain " , help = info , description = info )
202+ parser = subparsers .add_parser ("generate-certificate-chain " , help = info , description = info )
178203 parser .set_defaults (func = call )
179204
180205
@@ -236,7 +261,7 @@ def call(**kwargs):
236261 print (f"Generated chain file at { chain_path .absolute ()} " )
237262
238263 info = "Generate self-signed certificate files for local development"
239- parser = subparsers .add_parser ("generate_certificate_files " , help = info , description = info )
264+ parser = subparsers .add_parser ("generate-certificate-files " , help = info , description = info )
240265 parser .set_defaults (func = call )
241266
242267
@@ -246,7 +271,7 @@ def call(**kwargs):
246271 print (helper .generate_django_secret_key ())
247272
248273 info = "Generate a Django secret key"
249- parser = subparsers .add_parser ("generate_django_secret_key " , help = info , description = info )
274+ parser = subparsers .add_parser ("generate-django-secret-key " , help = info , description = info )
250275 parser .set_defaults (func = call )
251276
252277
@@ -256,7 +281,7 @@ def call(length: int, **kwargs):
256281 print (helper .generate_secure_password (length ))
257282
258283 info = "Generate a secure password"
259- parser = subparsers .add_parser ("generate_secure_password " , help = info , description = info )
284+ parser = subparsers .add_parser ("generate-secure-password " , help = info , description = info )
260285 parser .add_argument (
261286 "--length" , type = int , default = 12 , help = "Length of the password (default: 12)"
262287 )
@@ -308,7 +333,7 @@ def modify_env_file(domain: str | None = None, uses_https: bool = False):
308333 print ("Successfully initialized .env file." )
309334
310335 info = "Initialize workspace for Github Codespaces or local development"
311- parser = subparsers .add_parser ("init_workspace " , help = info , description = info )
336+ parser = subparsers .add_parser ("init-workspace " , help = info , description = info )
312337 parser .set_defaults (func = call )
313338
314339
@@ -344,32 +369,7 @@ def call(**kwags):
344369 set_key (env_file , "ADMIN_AUTH_TOKEN" , helper .generate_auth_token ())
345370
346371 info = "Randomize secrets in the .env file"
347- parser = subparsers .add_parser ("randomize_env_secrets" , help = info , description = info )
348- parser .set_defaults (func = call )
349-
350-
351- def register_restore_db (subparsers : argparse ._SubParsersAction ):
352- def call (** kwargs ):
353- helper = CommandHelper ()
354-
355- settings = (
356- f"{ helper .project_id } .settings.production"
357- if helper .is_production ()
358- else f"{ helper .project_id } .settings.development"
359- )
360- web_container_id = helper .find_running_container_id ("web" )
361- if web_container_id is None :
362- sys .exit ("Web container is not running. Run 'uv run ./manage.py compose-up' first." )
363-
364- helper .execute_cmd (
365- (
366- f"docker exec --env DJANGO_SETTINGS_MODULE={ settings } "
367- f"{ web_container_id } ./manage.py dbrestore"
368- )
369- )
370-
371- info = "Restore database in container from the last backup"
372- parser = subparsers .add_parser ("restore_db" , help = info , description = info )
372+ parser = subparsers .add_parser ("randomize-env-secrets" , help = info , description = info )
373373 parser .set_defaults (func = call )
374374
375375
@@ -400,7 +400,7 @@ def call(**kwargs):
400400 helper .execute_cmd ("npm outdated" , hidden = True )
401401
402402 info = "Show outdated dependencies"
403- parser = subparsers .add_parser ("show_outdated " , help = info , description = info )
403+ parser = subparsers .add_parser ("show-outdated " , help = info , description = info )
404404 parser .set_defaults (func = call )
405405
406406
@@ -431,7 +431,7 @@ def call(build: bool, **kwargs):
431431 helper .execute_cmd (cmd , env = env )
432432
433433 info = "Deploy stack with docker swarm"
434- parser = subparsers .add_parser ("stack_deploy " , help = info , description = info )
434+ parser = subparsers .add_parser ("stack-deploy " , help = info , description = info )
435435 parser .add_argument ("--build" , action = "store_true" , help = "Build images" )
436436 parser .set_defaults (func = call )
437437
@@ -442,7 +442,7 @@ def call(**kwargs):
442442 helper .execute_cmd (f"docker stack rm { helper .get_stack_name ()} " )
443443
444444 info = "Remove stack from docker swarm"
445- parser = subparsers .add_parser ("stack_rm " , help = info , description = info )
445+ parser = subparsers .add_parser ("stack-rm " , help = info , description = info )
446446 parser .set_defaults (func = call )
447447
448448
@@ -482,7 +482,7 @@ def call(**kwargs):
482482 helper .execute_cmd (f"{ act_path } -P ubuntu-latest=catthehacker/ubuntu:act-latest" )
483483
484484 info = "Try Github Actions locally using Act"
485- parser = subparsers .add_parser ("try_github_actions " , help = info , description = info )
485+ parser = subparsers .add_parser ("try-github-actions " , help = info , description = info )
486486 parser .set_defaults (func = call )
487487
488488
@@ -504,7 +504,7 @@ def call(version: str, **kwargs):
504504 print ("Cancelled" )
505505
506506 info = "Upgrade PostgreSQL volume data"
507- parser = subparsers .add_parser ("upgrade_postgres_volume " , help = info , description = info )
507+ parser = subparsers .add_parser ("upgrade-postgres-volume " , help = info , description = info )
508508 parser .add_argument (
509509 "--version" ,
510510 type = str ,
0 commit comments