Skip to content

Commit d7c4869

Browse files
committed
If version isn't specific always pull latest coana cli, else make sure we have the specified version
1 parent cdebce0 commit d7c4869

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.2.21"
9+
version = "2.2.22"
1010
requires-python = ">= 3.10"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [

socketsecurity/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.2.21'
2+
__version__ = '2.2.22'
33
USER_AGENT = f'SocketPythonCLI/{__version__}'

socketsecurity/core/tools/reachability.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)