Spaces:
Sleeping
Sleeping
File size: 4,213 Bytes
87d538c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
#!/usr/bin/env python
"""
CofifoAIWO CLI-Starter
Dieses Skript stellt eine interaktive Kommandozeile für CofifoAIWO bereit.
"""
import os
import sys
import subprocess
from pathlib import Path
# Pfad zum Basisverzeichnis
BASE_DIR = Path(__file__).resolve().parent
COMBINE_FILES_PY = BASE_DIR / "combine_files.py"
def print_header():
"""Druckt einen Kopf für die CLI."""
print("\n" + "=" * 60)
print(" CofifoAIWO CLI")
print("=" * 60)
print("Combine Files for AI Workflows - CLI-Mode")
print("Entwickelt von: https://github.com/ogerly")
print("-" * 60)
def print_commands():
"""Zeigt verfügbare Befehle an."""
print("\nVerfügbare Befehle:")
print("1: Shortcuts auflisten")
print("2: Shortcut hinzufügen")
print("3: Shortcut verwenden")
print("4: Shortcut entfernen")
print("5: Hilfe anzeigen")
print("6: Web-Interface starten")
print("0: Beenden")
def list_shortcuts():
"""Listet alle verfügbaren Shortcuts auf."""
subprocess.run([sys.executable, COMBINE_FILES_PY, "--list"])
def add_shortcut():
"""Fügt einen neuen Shortcut hinzu."""
name = input("\nName des Shortcuts: ")
print("\nPfade eingeben (einer pro Zeile, leere Zeile zum Beenden):")
paths = []
while True:
path = input("> ")
if not path:
break
paths.append(path)
if paths:
command = [sys.executable, COMBINE_FILES_PY, "--add", name] + paths
subprocess.run(command)
else:
print("Keine Pfade angegeben. Shortcut wurde nicht erstellt.")
def use_shortcut():
"""Verwendet einen Shortcut, um eine Ausgabedatei zu generieren."""
# Zuerst alle verfügbaren Shortcuts anzeigen
list_shortcuts()
name = input("\nName des zu verwendenden Shortcuts: ")
output_file = input("Name der Ausgabedatei: ")
include_tree = input("Verzeichnisstruktur einbeziehen (j/n)? ").lower() in ["j", "ja"]
command = [sys.executable, COMBINE_FILES_PY, "--use", name, output_file]
if include_tree:
command.append("--tree")
subprocess.run(command)
def remove_shortcut():
"""Entfernt einen Shortcut."""
# Zuerst alle verfügbaren Shortcuts anzeigen
list_shortcuts()
name = input("\nName des zu entfernenden Shortcuts: ")
confirm = input(f"Möchtest du den Shortcut '{name}' wirklich entfernen (j/n)? ").lower()
if confirm in ["j", "ja"]:
subprocess.run([sys.executable, COMBINE_FILES_PY, "--remove", name])
else:
print("Löschvorgang abgebrochen.")
def show_help():
"""Zeigt die Hilfe an."""
subprocess.run([sys.executable, COMBINE_FILES_PY, "--help"])
def start_web_interface():
"""Startet das Web-Interface."""
app_py = BASE_DIR / "app.py"
if not app_py.exists():
print(f"Fehler: app.py nicht gefunden: {app_py}")
return
print("\nStarte Web-Interface...")
print("Die Anwendung ist unter http://localhost:5000 erreichbar.")
print("Drücke Strg+C, um zu beenden.")
try:
subprocess.run([sys.executable, app_py])
except KeyboardInterrupt:
print("\nWeb-Interface beendet.")
def main():
"""Hauptfunktion."""
# Überprüfe, ob Kommandozeilenargumente übergeben wurden
if len(sys.argv) > 1:
# Wenn Argumente vorhanden sind, leite sie direkt an combine_files.py weiter
subprocess.run([sys.executable, COMBINE_FILES_PY] + sys.argv[1:])
return
print_header()
while True:
print_commands()
choice = input("\nWähle einen Befehl (0-6): ")
if choice == "0":
print("Auf Wiedersehen!")
break
elif choice == "1":
list_shortcuts()
elif choice == "2":
add_shortcut()
elif choice == "3":
use_shortcut()
elif choice == "4":
remove_shortcut()
elif choice == "5":
show_help()
elif choice == "6":
start_web_interface()
else:
print("Ungültige Eingabe. Bitte wähle 0-6.")
input("\nDrücke Enter, um fortzufahren...")
if __name__ == "__main__":
main() |