https://github.com/jfrog/gomod-absolutizer
A Go library, used to search and replace relative paths in go.mod files to absolute paths.
https://github.com/jfrog/gomod-absolutizer
absolute-paths devops go golang gomod jfrog
Last synced: 3 months ago
JSON representation
A Go library, used to search and replace relative paths in go.mod files to absolute paths.
- Host: GitHub
- URL: https://github.com/jfrog/gomod-absolutizer
- Owner: jfrog
- License: apache-2.0
- Created: 2022-02-24T17:36:05.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-09T13:23:29.000Z (over 1 year ago)
- Last Synced: 2024-07-10T10:37:42.433Z (over 1 year ago)
- Topics: absolute-paths, devops, go, golang, gomod, jfrog
- Language: Go
- Homepage:
- Size: 32.2 KB
- Stars: 4
- Watchers: 7
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Modules Absolutizer
> Supported Go version: 1.18+
Go Modules Absolutizer is a Go library, used to search and replace relative paths in go.mod files to absolute paths.
The library is used by both the [JFrog Idea Plugin](https://github.com/jfrog/jfrog-idea-plugin) and the [JFrog VS Code Extension](https://github.com/jfrog/jfrog-vscode-extension).
## Project status
[](https://github.com/jfrog/gomod-absolutizer/actions/workflows/test.yml) [](https://goreportcard.com/report/github.com/jfrog/gomod-absolutizer)
## Table of Contents
- [Usage](#usage)
- [As script](#as-script)
- [As executable](#as-executable)
- [As library](#as-library)
- [Example](#example)
- [Tests](#tests)
- [Release Notes](#release-notes)
- [Code contributions](#code-contributions)
## Usage
The program expects two flags:
| Flag | Description |
| ----------- | -------------------------------------------------------------------------------------------------- |
| `goModPath` | Path to a go.mod. |
| `wd` | Path to the working directory, which will be concatenated to the relative path in the go.mod file. |
You may use it in multiple ways:
### As script
```sh
go run . -goModPath=/path/to/go.mod -wd=/path/to/wd
```
### As executable
```sh
go build
./gomod-absolutizer -goModPath=/path/to/go.mod -wd=/path/to/wd
```
### As library
```go
import (
absolutizer "github.com/jfrog/gomod-absolutizer"
)
func main() {
args := &absolutizer.AbsolutizeArgs{
GoModPath: "/path/to/go.mod",
WorkingDir: "/path/to/wd",
}
err := absolutizer.Absolutize(args)
// Handle error
}
```
## Example
Given the following go.mod before running this program:
```
replace github.com/jfrog/jfrog-client-go v1.2.3 => github.com/jfrog/jfrog-client-go v1.2.4
replace github.com/jfrog/jfrog-cli-core => ../jfrog-cli-core
```
Running the following command:
```
go run . -goModPath=/Users/frogger/code/jfrog-cli/go.mod -wd=/Users/frogger/code/jfrog-cli
```
Will modify the original go.mod to:
```
replace github.com/jfrog/jfrog-client-go v1.2.3 => github.com/jfrog/jfrog-client-go v1.2.4
replace github.com/jfrog/jfrog-cli-core => /Users/frogger/code/jfrog-cli-core
```
## Tests
To run the tests, execute the following command from within the root directory of the project:
```sh
go test -v ./...
```
# Release Notes
The release notes are available [here](RELEASE.md#release-notes).
# Code Contributions
We welcome community contribution through pull requests.