Files
main.py
Purpose: This file defines the main entry point for the project. It provides the script to run the
switchvsversion
command-line utility.Usage:
# main.py
import argparse
from pathlib import Path
from switchvsversion import SwitchVsVersion
def main():
"""Parses command line arguments and executes the switchvsversion tool."""
parser = argparse.ArgumentParser(description='Switch between versions of a project.')
parser.add_argument('target_version', type=str, help='The version to switch to (e.g., "v1.0.0").')
parser.add_argument('--path', type=str, default=Path.cwd(), help='The path to the project directory.')
args = parser.parse_args()
# Initialize SwitchVsVersion object
switcher = SwitchVsVersion(args.path, args.target_version)
switcher.switch()
if __name__ == "__main__":
main()
- Code: switchvsversion/main.py
switchvsversion.py
Purpose: This file defines the
SwitchVsVersion
class, responsible for handling the switching between project versions.Usage:
# switchvsversion.py
import os
import re
from pathlib import Path
from typing import Optional
class SwitchVsVersion:
"""Handles switching between versions of a project."""
def __init__(self, project_path: Path, target_version: str) -> None:
"""Initializes the SwitchVsVersion object.
Args:
project_path (Path): The path to the project directory.
target_version (str): The version to switch to.
"""
self.project_path = project_path
self.target_version = target_version
self.available_versions = self._get_available_versions()
self.current_version = self._get_current_version()
def switch(self) -> None:
"""Switches the project to the target version."""
# 1. Check if target version is available
if self.target_version not in self.available_versions:
raise ValueError(f"Version '{self.target_version}' is not available. Available versions: {self.available_versions}")
# 2. Switch files based on the version pattern
# ... [This would contain the code to modify files and directories, depending on your project's version management strategy]
# 3. Update the current version
self.current_version = self.target_version
def _get_available_versions(self) -> list[str]:
"""Returns a list of available versions in the project.
This method should be implemented based on your project's versioning structure.
"""
return [] # Example: override this method with your logic to find versions.
def _get_current_version(self) -> Optional[str]:
"""Returns the current version of the project.
This method should be implemented based on your project's versioning structure.
"""
return None # Example: override this method with your logic to find the current version.