zero-to-prod/validate-semver-cli

A CLI for validating a semantic version string.

v1.1.0 2025-01-28 00:00 UTC

This package is auto-updated.

Last update: 2025-09-02 11:28:20 UTC


README

Repo GitHub Actions Workflow Status GitHub Actions Workflow Status GitHub Actions Workflow Status Packagist Downloads php Packagist Version License wakatime Hits-of-Code

Contents

Introduction

A CLI for validating a semantic version string.

Requirements

  • PHP 8.1 or higher.

Installation

Install Zerotoprod\ValidateSemverCli via Composer:

composer require zero-to-prod/validate-semver-cli

This will add the package to your project's dependencies and create an autoloader entry for it.

Documentation Publishing

You can publish this README to your local documentation directory.

This can be useful for providing documentation for AI agents.

This can be done using the included script:

# Publish to default location (./docs/zero-to-prod/validate-semver-cli)
vendor/bin/zero-to-prod-validate-semver-cli

# Publish to custom directory
vendor/bin/zero-to-prod-validate-semver-cli /path/to/your/docs

Automatic Documentation Publishing

You can automatically publish documentation by adding the following to your composer.json:

{
    "scripts": {
        "post-install-cmd": [
            "zero-to-prod-validate-semver-cli"
        ],
        "post-update-cmd": [
            "zero-to-prod-validate-semver-cli"
        ]
    }
}

Usage

Run this command to see the available commands:

vendor/bin/validate-semver-cli list

Available Commands

The CLI provides three main commands for working with semantic version validation:

validate-semver-cli:validate

Validates a semantic version string and returns the string if valid, or empty output if invalid.

Usage:

vendor/bin/validate-semver-cli validate-semver-cli:validate <semver>

Arguments:

  • semver (required) - The semantic version string to validate

Examples:

Valid semantic version:

vendor/bin/validate-semver-cli validate-semver-cli:validate "1.2.3"

Output:

1.2.3

Valid semantic version with pre-release:

vendor/bin/validate-semver-cli validate-semver-cli:validate "2.0.0-alpha.1"

Output:

2.0.0-alpha.1

Valid semantic version with build metadata:

vendor/bin/validate-semver-cli validate-semver-cli:validate "1.0.0+20230101"

Output:

1.0.0+20230101

Invalid semantic version:

vendor/bin/validate-semver-cli validate-semver-cli:validate "1.2"

Output:


validate-semver-cli:show-regex

Displays the regular expression pattern used to validate semantic version strings.

Usage:

vendor/bin/validate-semver-cli validate-semver-cli:show-regex

Arguments: None

Example:

vendor/bin/validate-semver-cli validate-semver-cli:show-regex

Output:

^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$

validate-semver-cli:src

Displays the project's source repository URL.

Usage:

vendor/bin/validate-semver-cli validate-semver-cli:src

Arguments: None

Example:

vendor/bin/validate-semver-cli validate-semver-cli:src

Output:

https://github.com/zero-to-prod/validate-semver-cli

Docker Image

You can also run the cli using the docker image:

docker run --rm davidsmith3/validate-semver-cli

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page if you want to contribute.

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Commit changes (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature-branch).
  5. Create a new Pull Request.