diff --git a/.gitea/workflows/embed.yaml b/.gitea/workflows/embed.yaml index 8530b55..bdc54dc 100644 --- a/.gitea/workflows/embed.yaml +++ b/.gitea/workflows/embed.yaml @@ -34,4 +34,4 @@ jobs: VECTORDB_TOKEN: ${{ secrets.VECTORDB_TOKEN }} run: | cd VectorLoader - python -m src.run --full + python -m src.run diff --git a/setup.py b/setup.py index daef860..488862e 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ tree_structurer_module = Extension( setup( name='prodir', - version='0.0.8', + version='0.0.9', description='A module for analyzing directory structures', ext_modules=[tree_structurer_module], packages=find_packages(where="src"), diff --git a/src/prodir/__main__.py b/src/prodir/__main__.py index d1cc593..f6beed9 100644 --- a/src/prodir/__main__.py +++ b/src/prodir/__main__.py @@ -8,15 +8,19 @@ from prodir import ( ) def main(): + # Create the main parser parser = argparse.ArgumentParser( + prog='prodir', # Set program name to prodir description='Directory structure tool: Display and create directory structures' ) - + # Create subparsers for different commands subparsers = parser.add_subparsers(dest='command', help='Available commands') - + # Display command - display_parser = subparsers.add_parser('display', help='Display directory structure') + display_parser = subparsers.add_parser('display', + prog='prodir display', # Set display command name + help='Display directory structure') display_parser.add_argument( 'path', nargs='?', @@ -28,9 +32,11 @@ def main(): action='store_true', help='Show more detailed output' ) - + # Create command - create_parser = subparsers.add_parser('create', help='Create directory structure') + create_parser = subparsers.add_parser('create', + prog='prodir create', # Set create command name + help='Create directory structure') create_parser.add_argument( 'file', help='File containing the directory structure' @@ -45,58 +51,68 @@ def main(): action='store_true', help='Show more detailed output' ) - + + # Check if a direct path was provided + if len(sys.argv) > 1 and not sys.argv[1].startswith('-') and not sys.argv[1] in ['display', 'create']: + # Convert to display command with path + sys.argv.insert(1, 'display') + args = parser.parse_args() - - # If no command is specified, default to display + + # If no command is specified, use display with current directory if not args.command: args.command = 'display' args.path = os.getcwd() args.verbose = False - + try: create_tree_structurer() - + if args.command == 'display': if args.verbose: print(f"Analyzing directory: {args.path}") - - structure = get_structure(args.path) - for line in structure: - print(line) - + try: + structure = get_structure(args.path) + for line in structure: + print(line) + except FileNotFoundError: + print("Error: Directory does not exist", file=sys.stderr) + sys.exit(1) + except Exception as e: + print(f"Error: {str(e)}", file=sys.stderr) + sys.exit(1) + elif args.command == 'create': if args.verbose: print(f"Creating directory structure in: {args.output}") print(f"Using structure from file: {args.file}") - create_structure_from_file(args.file, args.output) - - if args.verbose: - print("Structure created successfully") - print("\nResulting structure:") - structure = get_structure(args.output) - for line in structure: - print(line) + # Check if the output path exists + if not os.path.exists(args.output): + print(f"Error: The specified output path '{args.output}' does not exist.", file=sys.stderr) + exit(1) + try: + create_structure_from_file(args.file, args.output) + if args.verbose: + print("Structure created successfully") + print("\nResulting structure:") + structure = get_structure(args.output) + for line in structure: + print(line) + except FileNotFoundError as e: + if 'structure file' in str(e): + print("Error: Unable to open structure file", file=sys.stderr) + else: + print("Error: Directory does not exist", file=sys.stderr) + sys.exit(1) + except Exception as e: + print(f"Error: {str(e)}", file=sys.stderr) + sys.exit(1) + except Exception as e: - error_msg = str(e) - if "Directory does not exist" in error_msg: - print(f"Error: The specified directory does not exist: {args.path if args.command == 'display' else args.output}", - file=sys.stderr) - elif "Directory is empty" in error_msg: - print(f"Error: The specified directory is empty: {args.path if args.command == 'display' else args.output}", - file=sys.stderr) - elif "Path is not a directory" in error_msg: - print(f"Error: The specified path is not a directory: {args.path if args.command == 'display' else args.output}", - file=sys.stderr) - elif "Unable to open structure file" in error_msg: - print(f"Error: Unable to open structure file: {args.file}", file=sys.stderr) - elif "Invalid structure format" in error_msg: - print(f"Error: Invalid structure format in {'file' if args.file else 'string'}", file=sys.stderr) - else: - print(f"Error: {error_msg}", file=sys.stderr) + print(f"Error: {str(e)}", file=sys.stderr) sys.exit(1) if __name__ == "__main__": - main() \ No newline at end of file + main()