Feature: Update command for each tool (option 3 in tool menu)

HackingTool:
- Add update() method — detects install method from INSTALL_COMMANDS
  and runs the appropriate update:
  git clone → git -C <dir> pull
  pip install → pip install --upgrade
  go install → re-runs go install (fetches latest)
  gem install → gem update
- Checks is_installed first; shows warning if not installed
- Added as option 3 in every tool's OPTIONS menu (Install, Run, Update)
This commit is contained in:
Hardik Zinzuvadiya 2026-03-15 18:13:37 +05:30
parent 81690e3c7c
commit fd8d757461

41
core.py
View file

@ -109,6 +109,7 @@ class HackingTool:
self.OPTIONS.append(("Install", self.install))
if runnable:
self.OPTIONS.append(("Run", self.run))
self.OPTIONS.append(("Update", self.update))
self.OPTIONS.extend(options)
@property
@ -227,6 +228,46 @@ class HackingTool:
def after_uninstall(self): pass
def update(self):
"""Smart update — detects install method and runs the right update command."""
if not self.is_installed:
console.print("[warning]Tool is not installed yet. Install it first.[/warning]")
return
updated = False
for ic in (self.INSTALL_COMMANDS or []):
if "git clone" in ic:
# Extract repo dir name from clone command
parts = ic.split()
repo_urls = [p for p in parts if p.startswith("http")]
if repo_urls:
dirname = repo_urls[0].rstrip("/").rsplit("/", 1)[-1].replace(".git", "")
if os.path.isdir(dirname):
console.print(f"[cyan]→ git -C {dirname} pull[/cyan]")
os.system(f"git -C {dirname} pull")
updated = True
elif "pip install" in ic:
# Re-run pip install (--upgrade)
upgrade_cmd = ic.replace("pip install", "pip install --upgrade")
console.print(f"[cyan]→ {upgrade_cmd}[/cyan]")
os.system(upgrade_cmd)
updated = True
elif "go install" in ic:
# Re-run go install (fetches latest)
console.print(f"[cyan]→ {ic}[/cyan]")
os.system(ic)
updated = True
elif "gem install" in ic:
upgrade_cmd = ic.replace("gem install", "gem update")
console.print(f"[cyan]→ {upgrade_cmd}[/cyan]")
os.system(upgrade_cmd)
updated = True
if updated:
console.print("[success]✔ Update complete![/success]")
else:
console.print("[dim]No automatic update method available for this tool.[/dim]")
def before_run(self): pass
def run(self):