Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document version and versiond #2512

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions pkg/version/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# version module

The `version` package provides some utilities to get and display the version of a system, including branch, revision, and the dirty flag status.

## Constants

The following are placeholders that are replaced during the build of the system.

- `Branch`: Represents the branch the system is running of.
- `Revision`: Represents the code revision.
- `Dirty`: Shows if the binary was built from a repo with uncommitted changes.

## Version Interface

The `Version` interface defines two methods for retrieving version information

- `Short() string`: Returns a short representation of the version.
- `String() string`: Returns a detailed representation of the version.

## Functions

### `Current()`

Returns the current version as a `Version` object

### `ShowAndExit(short bool)`

Prints the version information and exits the program

- If `short` is `true`, prints the short version.
- Otherwise, prints the detailed version.

### `Parse(v string)`

Parses a version string using regular expressions and extracts the version and revision. Returns an error if the string is invalid
42 changes: 42 additions & 0 deletions pkg/versioned/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# versioned module

The `versioned` package provides utilities to manage versioned data streams and files. It uses the `blang/semver` package to handle semantic versioning.

## Error Handling

`ErrNotVersioned`: Error raised if the underlying reader has no version information.

`IsNotVersioned`: A function checks if an error is caused by a "not versioned" stream.

## Structs

`Reader`: Represents a versioned reader that can load the version of the data from a stream.

### Fields

- `Reader io.Reader`: The underlying data stream.
- `version Version`: The version of the data.

### Methods

`Version`: Returns the version of the data.

## Functions

`NewVersionedReader`: Creates a `Reader` with a specified version.

`NewReader`: Creates a `Reader` by reading the version from a stream. Fails if the stream lacks version information.

`ReadFile`: Reads the content of a file and its version.

`NewWriter`: Creates a versioned writer that marks data with the provided version.

`WriteFile`: Writes versioned data to a file.

`Parse`: Parses a version string into a `Version` object.

`MustParse`: Parses a version string into a `Version` object. Panics if the parsing fails.

`ParseRange`: Parses a version range string into a `Range` object.

`MustParseRange`: Parses a version range string into a `Range` object. Panics if the parsing fails.
Loading