66
77from app .commands import check , download , progress , setup , verify
88from app .commands .version import version
9- from app .utils .click import warn
9+ from app .utils .click import ClickColor , CliContextKey , warn
10+ from app .utils .gitmastery import (
11+ find_exercise_root ,
12+ find_gitmastery_root ,
13+ read_gitmastery_config ,
14+ read_exercise_config ,
15+ )
1016from app .utils .version import Version
1117from app .version import __version__
1218
@@ -24,20 +30,36 @@ def invoke(self, ctx: click.Context) -> None:
2430def cli (ctx , verbose ) -> None :
2531 """Git-Mastery app"""
2632 ctx .ensure_object (dict )
27- ctx .obj ["VERBOSE" ] = verbose
33+
34+ # Attempt to load both Git-Mastery root config and exercise config where possible
35+ gitmastery_root = find_gitmastery_root ()
36+ if gitmastery_root is not None :
37+ root_path , cds = gitmastery_root
38+ gitmastery_root_config = read_gitmastery_config (root_path , cds )
39+ ctx .obj [CliContextKey .GITMASTERY_ROOT_CONFIG ] = gitmastery_root_config
40+
41+ exercise_root = find_exercise_root ()
42+ if exercise_root is not None :
43+ root_path , cds = exercise_root
44+ exercise_root_config = read_exercise_config (root_path , cds )
45+ ctx .obj [CliContextKey .GITMASTERY_EXERCISE_CONFIG ] = exercise_root_config
46+
47+ ctx .obj [CliContextKey .VERBOSE ] = verbose
48+
2849 current_version = Version .parse_version_string (__version__ )
50+ ctx .obj [CliContextKey .VERSION ] = current_version
2951 latest_version = (
3052 requests .get (
3153 "https://github.com/git-mastery/app/releases/latest" , allow_redirects = False
3254 )
3355 .headers ["Location" ]
3456 .rsplit ("/" , 1 )[- 1 ]
3557 )
36- if current_version .is_behind (latest_version ):
58+ if current_version .is_behind (Version . parse_version_string ( latest_version ) ):
3759 warn (
3860 click .style (
3961 f"Your version of Git-Mastery app { current_version } is behind the latest version { latest_version } ." ,
40- fg = "bright_red" ,
62+ fg = ClickColor . BRIGHT_RED ,
4163 )
4264 )
4365 warn ("We strongly recommend upgrading your app." )
@@ -47,10 +69,7 @@ def cli(ctx, verbose) -> None:
4769
4870
4971def start () -> None :
50- cli .add_command (check )
51- cli .add_command (download )
52- cli .add_command (progress )
53- cli .add_command (setup )
54- cli .add_command (verify )
55- cli .add_command (version )
72+ commands = [check , download , progress , setup , verify , version ]
73+ for command in commands :
74+ cli .add_command (command )
5675 cli (obj = {})
0 commit comments