From 4866d49c5b931768da286a7045f35310784b244d Mon Sep 17 00:00:00 2001 From: Yuvraj Shekhar Date: Mon, 7 Sep 2026 14:10:29 +0200 Subject: [PATCH] fixed main issue for cli.py and added classes and objects to the code --- insight/cli.py | 63 +++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/insight/cli.py b/insight/cli.py index cebef63..f61a929 100644 --- a/insight/cli.py +++ b/insight/cli.py @@ -5,33 +5,44 @@ from .analyzer import analyze_codebase from .reporter import generate_report -def get_version(): - here = pathlib.Path(__file__).parent.parent - setup_py = here / "setup.py" - with open(setup_py, "r") as f: - content = f.read() - match = re.search(r"version=\"(.*?)\"", content) - if match: - return match.group(1) - return "0.0.0" +class Insight: + def __init__(self): + self.version = self.get_version() -def main(): - parser = argparse.ArgumentParser(description="Insight - Codebase Explainer CLI") - parser.add_argument("--version", action="version", version=f"%(prog)s {get_version()}") - parser.add_argument("path", help="Path to the codebase") - parser.add_argument("-o", "--output", default="report", help="Output report directory") - parser.add_argument("--limit", type=int, default=None, help="Limit number of files analyzed") - args = parser.parse_args() + def get_version(self): + here = pathlib.Path(__file__).parent.parent + setup_py = here / "setup.py" + with open(setup_py, "r") as f: + content = f.read() + match = re.search(r"version=\"(.*?)\"", content) + if match: + return match.group(1) + return "0.0.0" - if not os.path.exists(args.path): - print(f"❌ Error: Path '{args.path}' not found.") - print(f" • Current directory: {os.getcwd()}") - return - - print("Analyzing codebase...") - analysis = analyze_codebase(args.path, limit=args.limit) + def run(self): + parser = argparse.ArgumentParser(description="Insight - Codebase Explainer CLI") + parser.add_argument("--version", action="version", version=f"%(prog)s {self.get_version()}") + parser.add_argument("path", help="Path to the codebase") + parser.add_argument("-o", "--output", default="report", help="Output report directory") + parser.add_argument("--limit", type=int, default=None, help="Limit number of files analyzed") + args = parser.parse_args() - print("Generating reports...") - generate_report(analysis, args.output) + if not os.path.exists(args.path): + print(f"❌ Error: Path '{args.path}' not found.") + print(f" • Current directory: {os.getcwd()}") + return - print(f"Reports saved in {args.output}/") + print("Analyzing codebase...") + analysis = analyze_codebase(args.path, limit=args.limit) + + print("Generating reports...") + generate_report(analysis, args.output) + + print(f"Reports saved in {args.output}/") + +def main(): + insight = Insight() + insight.run() + +if __name__ == "__main__": + main()