77
88from cvm .services .cache_service import CacheService
99from cvm .services .github_service import GitHubService
10+ from cvm .services .application_service import ApplicationService , ComposerSource
1011
1112
1213class ComposerService :
@@ -57,7 +58,7 @@ def _get_setup_path(self) -> pathlib.Path:
5758 setup_path .write_bytes (r .content )
5859 return setup_path
5960
60- def install_version (self , tag_name : str , quiet = False ) -> pathlib . Path :
61+ def install_version (self , tag_name : str , quiet = False ) -> str :
6162 if not self .tag_exists (tag_name ):
6263 logging .error ("Tag {} does not exist." .format (tag_name ))
6364 sys .exit (1 )
@@ -66,16 +67,28 @@ def install_version(self, tag_name: str, quiet=False) -> pathlib.Path:
6667 cache_path = CacheService .make_cache_folder (tag_name )
6768
6869 if ComposerService .cached_version_exists (tag_name ):
69- return cache_path
70+ return str ( cache_path )
7071
7172 cmd = ['php' , str (setup_path ), f'--install-dir={ str (cache_path )} ' , '--filename=composer' , f'--version={ tag_name } ' ]
7273 result = subprocess .run (cmd , stdout = subprocess .PIPE , check = True )
7374 if not quiet :
7475 print (result .stdout .decode ('utf-8' ))
7576
76- return cache_path
77+ return str ( cache_path )
7778
78- def use_version (self , tag_name : str ) -> str :
79- install_path = self .install_version (tag_name , quiet = True )
79+ def use_version (self , tag_name : str , is_global : bool ) -> str :
80+ bin_path = self .install_version (tag_name , quiet = True )
8081
81- return str (install_path )
82+ application_service = ApplicationService ()
83+ application_service .set ('current' , tag_name )
84+
85+ if is_global :
86+ application_service .set ('global' , tag_name )
87+ application_service .set ('source' , ComposerSource .Global .value )
88+ else :
89+ application_service .set ('source' , ComposerSource .Config .value )
90+
91+ application_service .save ()
92+ updated_path = application_service .get_updated_path (bin_path )
93+
94+ return updated_path
0 commit comments