11from argparse import Action , Namespace
2+ from typing import Optional
23
4+ from colorama import Fore
35from cvm .commands .command import Command
6+ from cvm .helpers .cli import warning
7+ from cvm .helpers .fs import find_file_in_parent
8+ from cvm .services .application_service import ApplicationService
49from cvm .services .composer_service import ComposerService
510from cvm .services .config_service import ConfigService
611from cvm .services .github_service import GitHubService
7- from cvm .services .application_service import ApplicationService
8- from cvm .helpers .cli import warning
9- from colorama import Fore
1012
1113
1214class ScanCommand (Command ):
@@ -15,9 +17,10 @@ class ScanCommand(Command):
1517
1618 def exec (self , args : Namespace ):
1719 version = None
20+ config_file = ConfigService .find ()
1821
19- if ConfigService . exists () :
20- version = self ._check_local ()
22+ if config_file is not None :
23+ version = self ._check_local (config_file )
2124 else :
2225 version = self ._check_global ()
2326
@@ -26,13 +29,12 @@ def exec(self, args: Namespace):
2629
2730 github_service = GitHubService ('composer' , 'composer' )
2831 composer_service = ComposerService (github_service )
29-
3032 updated_path = composer_service .use_version (version , False )
3133
3234 print (f"export PATH=\" { updated_path } \" ; echo Updated path.;" )
3335
34- def _check_local (self ) :
35- data = ConfigService .read ()
36+ def _check_local (self , config_file : str ) -> Optional [ str ] :
37+ data = ConfigService .read (config_file )
3638 if not ConfigService .validate (data ):
3739 msg = warning (".cvm_config format in current directory is invalid." )
3840 print (f"echo \" { msg } \" " )
@@ -41,7 +43,7 @@ def _check_local(self):
4143
4244 return data ['requires' ]
4345
44- def _check_global (self ):
46+ def _check_global (self ) -> Optional [ str ] :
4547 application_service = ApplicationService ()
4648
4749 return application_service .get ('global' )
0 commit comments