repository
0.0.0-20241209120313-f802dd574d4a
Repository: https://github.com/s4bb4t/verche.git
Documentation: pkg.go.dev
# README
Verche
Overview
Verche is a command-line tool designed to help manage and update the go.mod
file in Go projects. It ensures your dependencies are up to date and compliant with your project's requirements.
Features
-
Manual and Automatic Modes:
- Manual Mode: Prompts you to review changes to dependencies manually.
- Automatic Mode: Updates all dependencies to the latest permissible versions.
-
Dependency Analysis:
- Reads the
go.mod
file line by line. - Identifies outdated dependencies and fetches the latest versions using an artifact repository.
- Reads the
-
Go Version Management:
- Updates the Go version in your
go.mod
file based on the specified version.
- Updates the Go version in your
-
File Management:
- Uses a temporary file (
verched_go.mod
) for intermediate updates to prevent data loss. - Overwrites
go.mod
with validated updates.
- Uses a temporary file (
-
Cleanup and Validation:
- Runs
go mod tidy
to ensure dependency coherence after updates.
- Runs
Installation
Prerequisites
- Go: Version 1.21 or higher.
Steps
-
Clone the repository:
git clone https://github.com/s4bb4t/verche.git cd verche
-
Install dependencies:
go mod tidy
-
Build the executable:
cd cmd/checker go build -o verche
-
Add the executable to your system's PATH:
sudo mv verche /usr/local/bin/
Usage
Run Verche with the required flags:
verche -in <project_directory> -v <golang_version> -m <method>
Flags:
-in
(required): Path to the project directory containinggo.mod
.-v
(optional): Go version to set ingo.mod
(default:1.23.0
).-m
(optional): Method of operation (manual
orauto
).
Example Commands:
-
Update dependencies automatically:
verche -in ./my_project -v 1.23.0 -m auto
-
Review updates manually:
verche -in ./my_project -v 1.23.0 -m manual
Internals
Configuration (pkg/config
)
- Defines project paths and the Go version.
- Loads flags and validates input.
- Constructs file paths for
go.mod
andverched_go.mod
.
Update Process (pkg/updater
)
-
File Parsing:
- Reads
go.mod
line by line. - Uses regex to extract dependency names and versions.
- Reads
-
Dependency Resolution:
- Fetches metadata for the latest permissible versions of dependencies.
- Resolves conflicts based on semantic versioning.
-
File Writing:
- Updates the
go.mod
file with the latest versions. - Uses a temporary file to ensure safe operations.
- Updates the
-
Cleanup:
- Runs
go mod tidy
to finalize changes.
- Runs
Error Handling
- Detects and reports issues during file access or dependency resolution.
- Provides detailed error messages for troubleshooting.
Common Issues
Missing Flags
- Ensure the
-in
flag is provided:verche -in ./my_project
Permissions
- Ensure you have write permissions for the project directory:
chmod +w ./my_project/go.mod
Dependency Resolution
- If a dependency cannot be resolved, verify its name and repository status.
Contribution
For any questions, contact the maintainer at [email protected].