@@ -17,38 +17,42 @@ def __init__(self, sdk: socketdev, api_token: str):
1717
1818 def _ensure_coana_cli_installed (self , version : Optional [str ] = None ) -> str :
1919 """
20- Check if @coana-tech/cli is installed, and install it if not present .
20+ Check if @coana-tech/cli is installed, and install/update it if needed .
2121
2222 Args:
23- version: Specific version to install (e.g., '1.2.3')
23+ version: Specific version to install (e.g., '1.2.3'). If None, updates to latest.
2424
2525 Returns:
2626 str: The package specifier to use with npx
2727 """
2828 # Determine the package specifier
2929 package_spec = f"@coana-tech/cli@{ version } " if version else "@coana-tech/cli"
3030
31- # Check if the package is already available
32- try :
33- check_cmd = ["npm" , "list" , "-g" , "@coana-tech/cli" , "--depth=0" ]
34- result = subprocess .run (
35- check_cmd ,
36- capture_output = True ,
37- text = True ,
38- timeout = 10
39- )
40-
41- # If npm list succeeds and mentions the package, it's installed
42- if result .returncode == 0 and "@coana-tech/cli" in result .stdout :
43- log .debug (f"@coana-tech/cli is already installed globally" )
44- return package_spec
31+ # If a specific version is requested, check if it's already installed
32+ if version :
33+ try :
34+ check_cmd = ["npm" , "list" , "-g" , "@coana-tech/cli" , "--depth=0" ]
35+ result = subprocess .run (
36+ check_cmd ,
37+ capture_output = True ,
38+ text = True ,
39+ timeout = 10
40+ )
4541
46- except Exception as e :
47- log .debug (f"Could not check for existing @coana-tech/cli installation: { e } " )
48-
49- # Package not found or check failed - install it
50- log .info ("Downloading reachability analysis plugin (@coana-tech/cli)..." )
51- log .info ("This may take a moment on first run..." )
42+ # If npm list succeeds and mentions the specific version, it's installed
43+ if result .returncode == 0 and f"@coana-tech/cli@{ version } " in result .stdout :
44+ log .debug (f"@coana-tech/cli@{ version } is already installed globally" )
45+ return package_spec
46+
47+ except Exception as e :
48+ log .debug (f"Could not check for existing @coana-tech/cli installation: { e } " )
49+
50+ # Install or update the package
51+ if version :
52+ log .info (f"Installing reachability analysis plugin (@coana-tech/cli@{ version } )..." )
53+ else :
54+ log .info ("Updating reachability analysis plugin (@coana-tech/cli) to latest version..." )
55+ log .info ("This may take a moment..." )
5256
5357 try :
5458 install_cmd = ["npm" , "install" , "-g" , package_spec ]
0 commit comments