semver-extra

Crates.iosemver-extra
lib.rssemver-extra
version0.2.5
sourcesrc
created_at2024-06-27 03:03:06.495519
updated_at2024-07-03 03:11:12.479008
descriptionHelper functions for the semver crate, complete with a CLI tool.
homepagehttps://github.com/nicholaschiasson/semver-extra
repositoryhttps://github.com/nicholaschiasson/semver-extra
max_upload_size
id1285044
size32,184
Nicholas Omer Chiasson (nicholaschiasson)

documentation

README

semver-extra

github crates.io docs.rs build license

Helper functions for the semver crate, complete with a CLI tool.

CLI

This project also publishes a binary application for use on the command line.

Installation

For now, crates.io is the only place this is being distributed.

cargo install semver-extra

Usage

A Rust implementation of the https://semver.org/ specification

Usage: semver [VERSION] [COMMAND]

Commands:
  increment  Increment a component of the version, resetting those of lower significance [aliases: i]
  get        Output a specific component of the version [aliases: g]
  help       Print this message or the help of the given subcommand(s)

Arguments:
  [VERSION]  The input semantic version. If omitted, input is taken from stdin

Options:
  -h, --help     Print help
  -V, --version  Print version

Example

Attempt to parse input as a semantic version

semver hello.world
error: invalid value 'hello.world' for '[VERSION]': unexpected character 'h' while parsing major version number

For more information, try '--help'.

Bump minor version

semver 1.2.3 increment minor
1.3.0

Get prerelease component of version

semver 1.0.0-rc.12 get prerelease
rc.12

Pipe command output as semver input

echo 1.0.2 | semver i
1.0.3

Docker

This project also publishes a docker image, exposing the CLI tool.

Installation

You can pull the image from GitHub's container registry:

docker pull ghcr.io/nicholaschiasson/semver-extra:latest

Or for more convenience, you can reference the image in a docker compose file:

---
services:
  semver:
    image: ghcr.io/nicholaschiasson/semver-extra:latest

For extra convenience, you can create an alias to the docker compose command:

echo 'alias semver="docker compose --file path/to/docker-compose.yml run --rm semver"' >> "${HOME}/.bashrc"
source "${HOME}"/.bashrc

After that, you should be able to simply run semver to invoke the container.

Usage

The docker image entrypoint is the semver CLI binary itself, meaning the usage is the exact same as indicated above.

Examples

Use docker image directly

docker run ghcr.io/nicholaschiasson/semver-extra 1.2.3 i major
2.0.0

Use docker compose service

docker compose run semver 12.34.56 i
12.34.57

Development

Prerequisites

How-to

Create the development shell environment. Necessary to run all other commands.

nix develop

Build with cargo.

just build

Check the code with cargo's built-in fast static analysis.

just check

Remove build files.

just clean

Format the code.

just format

Check the code with clippy for better static analysis.

just lint

Run the application.

just run

Run tests with cargo's built-in test runner.

just test

Watch for code changes and rebuild.

just watch

All just commands can accept additional command line arguments after a --.

For example: run the application with a flag to report the version.

just run -- --version

Tips and Recommendations

Open IDE from Development Shell

To get linking to rust binaries in your IDE, you should open the development shell from your terminal and then open your IDE from that shell session. This will carry over the development shell's environment into your IDE.

For example if you work with VSCode.

cd path/to/this/project
nix develop
code .

By doing this, you can install the rust-analyzer VSCode extension and it will work properly since it will be able to point to the correct rust binaries and libraries. You will also have access in VSCode to any packages installed by the nix flake.

To Do

  • Dockerfile
  • Tests
  • Github Action
  • Support #![no-std]
  • Support prerelease version incrementing
  • Support range operations
  • Rip off other features of node-semver if we find they are actually valuable
Commit count: 22

cargo fmt