metanull/inventory-cli

Powershell modules to interact with the inventory-app's REST Api

★ 0Forks 0PowerShellGitHub ↗Compare

README

MetaNull.InventoryCli

Validate Pull Request Publish to PSGallery PowerShell Gallery

A PowerShell 5+ module designed to manage inventory operations, built following Microsoft's PowerShell best practices and guidelines.

Features

  • PowerShell 5.1+ Compatible: Works with PowerShell 5.1 and later versions
  • Standards Compliant: Follows Microsoft's PowerShell best practices
  • Quality Assured: All code passes PSScriptAnalyzer validation
  • Comprehensive Testing: Full Pester test coverage
  • Automated CI/CD: GitHub Actions for validation and publishing

Installation

From PowerShell Gallery (Recommended)

Install-Module -Name MetaNull.InventoryCli -Repository PSGallery

From Source

  1. Clone the repository:
git clone https://github.com/metanull/inventory-cli.git
cd inventory-cli
  1. Build the module:
cd src/MetaNull.InventoryCli
.\Build.ps1
  1. Import the built module:
Import-Module .\build\MetaNull.InventoryCli\<version>\MetaNull.InventoryCli.psd1

Usage

After installation, you can use the module's functions:

# Import the module
Import-Module MetaNull.InventoryCli

# List available commands
Get-Command -Module MetaNull.InventoryCli

# Get help for specific functions
Get-Help Get-Dummy -Full

Development

This module is built using MetaNull.ModuleMaker, which provides a standardized structure and build process for PowerShell modules.

Prerequisites

Project Structure

src/MetaNull.InventoryCli/
├── Blueprint.psd1          # Module build configuration
├── Build.ps1              # Build script with version management
├── Publish.ps1            # Publishing script for PSGallery
├── Version.psd1           # Version tracking file
├── source/                # Source code directory
│   ├── init/              # Module initialization scripts
│   ├── private/           # Private functions (not exported)
│   ├── public/            # Public functions (exported)
│   └── class/             # PowerShell classes (if any)
├── test/                  # Test directory structure
│   ├── private/           # Tests for private functions
│   └── public/            # Tests for public functions
└── build/                 # Build output directory (generated)

Adding New Functions

  1. Install MetaNull.ModuleMaker:
Install-Module -Name MetaNull.ModuleMaker
  1. Create a new function:
New-FunctionBlueprint -ModulePath "src/MetaNull.InventoryCli" -FunctionName "Get-InventoryItem" -Visibility Public
  1. Implement the function in the generated file
  2. Write comprehensive Pester tests
  3. Run validation and build:
# Run PSScriptAnalyzer
Invoke-ScriptAnalyzer -ExcludeRule PSAvoidUsingConvertToSecureStringWithPlainText -Path "src" -Recurse

# Run tests
Invoke-Pester -Path "src/MetaNull.InventoryCli/test"

# Build the module
.\src\MetaNull.InventoryCli\Build.ps1

Code Quality Standards

  • PSScriptAnalyzer: All code must pass without errors or warnings
  • Approved Verbs: Function names must use Microsoft's approved PowerShell verbs
  • CmdletBinding: All functions must include [CmdletBinding()]
  • OutputType: Functions should specify [OutputType()]
  • Help Documentation: Comprehensive comment-based help required

Testing

Run all tests:

cd src/MetaNull.InventoryCli
Invoke-Pester -Path "test" -CodeCoverage "source/**/*.ps1"

Building and Publishing

Build Module

cd src/MetaNull.InventoryCli

# Build with default increment (build number)
.\Build.ps1

# Build with specific version increment
.\Build.ps1 -IncrementMinor
.\Build.ps1 -IncrementMajor
.\Build.ps1 -IncrementRevision

Publish to PSGallery

# Get your API key from https://www.powershellgallery.com/account/apikeys
$ApiKey = Read-Host -AsSecureString "Enter PSGallery API Key"
$Credential = New-Object PSCredential("apikey", $ApiKey)

# Publish using the provided script
.\Publish.ps1 -Credential $Credential

Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/your-feature-name
  3. Make your changes following the development guidelines
  4. Ensure all tests pass and code quality checks succeed
  5. Commit your changes: git commit -am 'Add your feature'
  6. Push to the branch: git push origin feature/your-feature-name
  7. Create a Pull Request

Pull Request Requirements

  • All code must pass PSScriptAnalyzer validation
  • All tests must pass
  • New functions must have corresponding tests
  • Follow PowerShell best practices and naming conventions
  • Include comprehensive help documentation

CI/CD

This repository uses GitHub Actions for continuous integration and deployment:

  • PR Validation: Automatically runs PSScriptAnalyzer and Pester tests on pull requests
  • Automated Publishing: Publishes to PSGallery on push to main branch or manual trigger

GitHub Secrets

For automated publishing, configure the following secret in your GitHub repository:

  • PSGALLERY_API_KEY: Your PowerShell Gallery API key

Version Management

Versions are automatically managed by the build script using semantic versioning:

  • Major: Breaking changes (Build.ps1 -IncrementMajor)
  • Minor: New features, backward compatible (Build.ps1 -IncrementMinor)
  • Build: Automatic increment on each build
  • Revision: Bug fixes (Build.ps1 -IncrementRevision)

License

This project is licensed under the terms specified in the LICENSE file.

Author

Pascal Havelange

Support

If you encounter any issues or have questions:

  1. Check the existing issues
  2. Create a new issue with detailed information
  3. Follow the issue template if provided

Changelog

See releases for version history and changes.

Contributors

metanull

Issues