CLI Reference
Command-line interface reference for Morphir .NET tooling
Morphir .NET CLI Reference
The Morphir .NET CLI provides powerful command-line tools for working with Morphir IR files, validating schemas, and managing Morphir projects.
Available Commands
IR Management
- morphir ir verify - Validate Morphir IR JSON files against official schemas
- morphir ir detect-version (coming in Phase 2) - Detect the schema version of an IR file
Project Management
(Future commands will be documented here)
Installation
The Morphir .NET CLI is distributed as a .NET tool. Install it globally with:
dotnet tool install -g Morphir.CLI
Or locally in a project:
dotnet tool install Morphir.CLI
Getting Help
For help with any command, use the --help flag:
morphir --help
morphir ir --help
morphir ir verify --help
Common Workflows
Validating IR Files
The most common workflow is validating Morphir IR JSON files to ensure they conform to the expected schema:
# Validate a single file with auto-detection
morphir ir verify path/to/morphir-ir.json
# Validate with explicit schema version
morphir ir verify --schema-version 3 path/to/morphir-ir.json
# Get JSON output for CI/CD
morphir ir verify --json path/to/morphir-ir.json
# Quiet mode (only errors)
morphir ir verify --quiet path/to/morphir-ir.json
See the morphir ir verify documentation for complete details.
Exit Codes
All Morphir CLI commands use consistent exit codes:
- 0: Success - operation completed successfully
- 1: Validation failure - IR file failed schema validation
- 2: Operational error - file not found, invalid JSON, missing dependencies, etc.
These exit codes are designed for CI/CD integration and scripting.
Configuration
(Future: Configuration file format and options will be documented here)
Troubleshooting
See the Troubleshooting Guide for solutions to common issues.
1 - morphir ir verify
Validate Morphir IR JSON files against official schemas
morphir ir verify
Validate Morphir IR JSON files against the official JSON schemas for format versions 1, 2, and 3.
Synopsis
morphir ir verify <file-path> [options]
Description
The morphir ir verify command validates a Morphir IR JSON file against the appropriate schema specification. The command automatically detects the schema version from the file content, or you can explicitly specify the version to use.
This command is useful for:
- Catching structural errors before IR files are used by other tools
- Validating generated IR from Morphir compilers
- CI/CD integration to ensure IR quality
- Debugging IR issues with detailed error messages
Arguments
<file-path>
Required. Path to the Morphir IR JSON file to validate.
- Supports absolute and relative paths
- File must exist and be readable
- File must contain valid JSON
Examples:
morphir ir verify morphir-ir.json
morphir ir verify ../output/morphir-ir.json
morphir ir verify /absolute/path/to/morphir-ir.json
Options
--schema-version <version>
Explicitly specify the schema version to validate against.
- Valid values:
1, 2, or 3 - Default: Auto-detected from file content
- Use when: Testing version-specific compatibility or overriding auto-detection
Examples:
# Validate against v3 schema regardless of file content
morphir ir verify --schema-version 3 morphir-ir.json
# Test if a v2 IR file is compatible with v3 schema
morphir ir verify --schema-version 3 morphir-ir-v2.json
--json
Output validation results in JSON format instead of human-readable text.
- Default: Human-readable output
- Use when: Parsing results in CI/CD, scripts, or other tools
- Output: Structured JSON with validation details
JSON Output Format:
{
"IsValid": true,
"SchemaVersion": "3",
"DetectionMethod": "auto",
"FilePath": "/path/to/morphir-ir.json",
"Errors": [],
"Timestamp": "2025-12-15T10:30:00Z"
}
For invalid IR:
{
"IsValid": false,
"SchemaVersion": "3",
"DetectionMethod": "auto",
"FilePath": "/path/to/morphir-ir.json",
"Errors": [
{
"Path": "$.distribution[3]",
"Message": "Required properties [\"formatVersion\"] are not present",
"Expected": "required property",
"Found": "undefined (missing)",
"Line": null,
"Column": null
}
],
"Timestamp": "2025-12-15T10:30:00Z"
}
Example:
# Get JSON output for parsing
morphir ir verify --json morphir-ir.json
# Use in scripts
RESULT=$(morphir ir verify --json morphir-ir.json)
echo $RESULT | jq '.IsValid'
--quiet
Suppress all output except for errors.
- Default: Show detailed output
- Use when: Running in CI/CD pipelines where you only care about failures
- Exit code: Still returns 0 (success) or 1 (failure)
Examples:
# Quiet mode - only shows output if validation fails
morphir ir verify --quiet morphir-ir.json
# Use in CI/CD
if morphir ir verify --quiet morphir-ir.json; then
echo "IR is valid"
else
echo "IR validation failed"
exit 1
fi
Exit Codes
| Code | Meaning | Description |
|---|
0 | Success | IR file is valid according to the schema |
1 | Validation failure | IR file failed schema validation (see error output) |
2 | Operational error | File not found, malformed JSON, or other operational issue |
Output
Human-Readable Output (Default)
Valid IR:
Validation Result: ✓ VALID
File: /path/to/morphir-ir.json
Schema Version: v3 (auto)
Timestamp: 2025-12-15 10:30:00 UTC
No validation errors found.
Invalid IR:
Validation Result: ✗ INVALID
File: /path/to/morphir-ir.json
Schema Version: v3 (auto)
Timestamp: 2025-12-15 10:30:00 UTC
Found 2 validation error(s):
Path: $.distribution[3]
Message: Required properties ["formatVersion"] are not present
Expected: required property
Found: undefined (missing)
Path: $.distribution[3].modules[0].name
Message: Value is "string" but should be "array"
Expected: array
Found: string
JSON Output
See the --json option above for the JSON output format specification.
Schema Version Detection
The command automatically detects the schema version by analyzing the IR file structure:
- v1: Detected by presence of v1-specific structure
- v2: Detected by
"formatVersion": 2 field - v3: Detected by
"formatVersion": 3 field
Detection Method in Output:
auto: Version was automatically detectedmanual: Version was explicitly specified via --schema-version
Examples
Basic Validation
Validate a single IR file with auto-detection:
morphir ir verify morphir-ir.json
Explicit Version
Validate against a specific schema version:
morphir ir verify --schema-version 3 morphir-ir.json
CI/CD Integration
Validate IR in a GitHub Actions workflow:
- name: Validate Morphir IR
run: |
dotnet morphir ir verify --json morphir-ir.json > validation-result.json
if [ $? -ne 0 ]; then
cat validation-result.json
exit 1
fi
Script with Error Handling
#!/bin/bash
set -e
echo "Validating Morphir IR files..."
for file in output/*.json; do
echo "Validating $file..."
if morphir ir verify --quiet "$file"; then
echo "✓ $file is valid"
else
echo "✗ $file is invalid"
morphir ir verify "$file" # Show detailed errors
exit 1
fi
done
echo "All IR files are valid!"
JSON Output Parsing
Parse JSON output with jq:
# Check if valid
morphir ir verify --json morphir-ir.json | jq '.IsValid'
# Get error count
morphir ir verify --json morphir-ir.json | jq '.Errors | length'
# Extract error messages
morphir ir verify --json morphir-ir.json | jq '.Errors[].Message'
# Get schema version used
morphir ir verify --json morphir-ir.json | jq '.SchemaVersion'
Common Error Messages
File Not Found
Error: File does not exist: path/to/file.json
Solution: Check the file path and ensure the file exists.
Validation Result: ✗ INVALID
Found 1 validation error(s):
Path: $
Message: Malformed JSON: 'i' is an invalid start of a value. LineNumber: 6 | BytePositionInLine: 4.
Expected: Valid JSON
Found: Invalid JSON syntax
Solution: Fix the JSON syntax error. The error message includes the line and byte position.
Missing Required Field
Path: $.distribution
Message: Required properties ["formatVersion"] are not present
Expected: required property
Found: undefined (missing)
Solution: Add the missing formatVersion field to your IR file.
Type Mismatch
Path: $.distribution[3].modules[0].name
Message: Value is "string" but should be "array"
Expected: array
Found: string
Solution: Change the field type to match the schema requirement (in this case, name should be an array, not a string).
Troubleshooting
Schema Version Not Detected
If auto-detection fails or detects the wrong version:
- Check the
formatVersion field in your JSON (for v2/v3) - Use
--schema-version explicitly to override auto-detection - Verify JSON structure matches the expected schema version
For large IR files (>1MB):
- Validation may take several seconds
- Consider using
--quiet mode in CI/CD to reduce output overhead - (Phase 2 will include performance optimizations for batch processing)
False Positives
If validation fails but you believe the IR is correct:
- Check schema version - ensure you’re validating against the correct version
- Review error messages - they include expected vs. found values
- Consult schema documentation - see Schema Specifications
- Report an issue - if you believe the schema or validator has a bug
- morphir ir detect-version (Phase 2) - Detect schema version without validation
- morphir ir migrate (Phase 3) - Migrate IR between schema versions
See Also
2 - Management Commands
Commands for managing Morphir distributions, tools, and extensions.
Overview
The Morphir CLI provides commands to manage distributions, tools, and extensions with support for:
- Global-first installation (in OS config directory like
~/.config/morphir or ~/.morphir) - Local overrides (per-project in
.morphir/ directory) - Platform-specific artifacts using .NET Runtime Identifiers (e.g.,
linux-x64, win-x64, osx-arm64)
Dist Commands
Manage core Morphir distributions.
dist list
List installed distributions.
morphir dist list [options]
Options:
--platform <rid>: Platform Runtime Identifier (defaults to current platform)--local: List local (project) installations only
Example:
# List all distributions for current platform
morphir dist list
# List distributions for a specific platform
morphir dist list --platform linux-x64
# List project-local distributions
morphir dist list --local
dist install
Install a distribution from a URL.
morphir dist install <url> <version> [options]
Arguments:
<url>: Source URL to download the distribution from<version>: Version string (e.g., 1.0.0, 2.1.3-beta)
Options:
--platform <rid>: Platform Runtime Identifier (defaults to current platform)--local: Install locally (project-specific)
Example:
# Install globally
morphir dist install https://example.com/morphir-dist.tar.gz 1.0.0
# Install locally for project
morphir dist install https://example.com/morphir-dist.tar.gz 1.0.0 --local
# Install for specific platform
morphir dist install https://example.com/morphir-dist.tar.gz 1.0.0 --platform linux-x64
dist use
Set the active distribution version.
morphir dist use <version> [options]
Arguments:
<version>: Version to activate
Options:
--platform <rid>: Platform Runtime Identifier (defaults to current platform)--local: Set in local (project) scope
Example:
# Set global active version
morphir dist use 1.0.0
# Set local active version for current project
morphir dist use 2.0.0 --local
Resolution: Local selection takes precedence over global when both are set.
dist remove
Remove an installed distribution.
morphir dist remove <version> [options]
Arguments:
<version>: Version to remove
Options:
--platform <rid>: Platform Runtime Identifier (defaults to current platform)--local: Remove from local (project) scope
Example:
morphir dist remove 1.0.0
morphir dist remove 1.0.0 --local
dist which
Show the currently active distribution.
morphir dist which [options]
Options:
--platform <rid>: Platform Runtime Identifier (defaults to current platform)
Example:
morphir dist which
# Output: Version 1.0.0 (global) at /home/user/.config/morphir/dist/linux-x64/1.0.0
Manage auxiliary CLI tools and utilities.
List installed tools.
morphir tool list [options]
Options:
--platform <rid>: Platform Runtime Identifier (defaults to current platform)--local: List local (project) installations only
Install a tool from a URL.
morphir tool install <name> <url> <version> [options]
Arguments:
<name>: Tool name<url>: Source URL<version>: Version string
Options:
--platform <rid>: Platform Runtime Identifier (defaults to current platform)--local: Install locally (project-specific)
Example:
morphir tool install morphir-elm-codegen https://example.com/tool.tar.gz 1.0.0
morphir tool install my-formatter https://example.com/formatter.tar.gz 2.1.0 --local
Set the active tool version.
morphir tool use <name> <version> [options]
Arguments:
<name>: Tool name<version>: Version to activate
Options:
--platform <rid>: Platform Runtime Identifier (defaults to current platform)--local: Set in local (project) scope
Remove an installed tool.
morphir tool remove <name> <version> [options]
Show the currently active tool version.
morphir tool which <name> [options]
Options:
--platform <rid>: Platform Runtime Identifier (defaults to current platform)
Extension Commands
Manage optional add-ons and plugins.
Extension commands follow the same pattern as tool commands:
morphir extension list [--platform <rid>] [--local]
morphir extension install <name> <url> <version> [--platform <rid>] [--local]
morphir extension use <name> <version> [--platform <rid>] [--local]
morphir extension remove <name> <version> [--platform <rid>] [--local]
morphir extension which <name> [--platform <rid>]
Morphir uses .NET Runtime Identifiers to manage platform-specific artifacts:
| Platform | RID |
|---|
| Linux x64 | linux-x64 |
| Linux ARM64 | linux-arm64 |
| Windows x64 | win-x64 |
| Windows ARM64 | win-arm64 |
| macOS x64 (Intel) | osx-x64 |
| macOS ARM64 (Apple Silicon) | osx-arm64 |
The CLI automatically detects the current platform when --platform is not specified.
Resolution Rules
When looking for an active artifact, the CLI uses the following precedence:
- Project-local selection (if
.morphir/ exists and selection is set locally) - Global selection (in OS config directory)
- Error if no selection is found
Each artifact category (dist, tool, extension) resolves independently.
Folder Layout
Global (preferred):
~/.config/morphir/ (Linux)
~/Library/Application Support/morphir/ (macOS)
%APPDATA%\Morphir\ (Windows)
dist/
<platform>/
<version>/
bin/
manifest.json
tools/
<platform>/
<tool-name>/
<version>/
bin/
manifest.json
extensions/
<platform>/
<extension-name>/
<version>/
bin/
manifest.json
Local (optional, per project):
.morphir/
dist/...
tools/...
extensions/...
Each installed artifact includes a manifest.json file (JSONC format with comments supported):
{
"name": "morphir-dist",
"version": "1.0.0",
"platform": "linux-x64",
"sourceUrl": "https://example.com/artifact.tar.gz",
"sha256": "abc123...",
"description": "Core Morphir distribution",
"installedAt": "2025-12-23T19:00:00Z",
"metadata": {
"key": "value"
}
}
See Also
3 - Troubleshooting
Solutions to common issues with Morphir .NET CLI
Troubleshooting Guide
This guide covers common issues you may encounter when using the Morphir .NET CLI and how to resolve them.
Installation Issues
Problem: After running dotnet tool install, the morphir command is not found.
Solution:
Check if tools are in PATH:
echo $PATH | grep .dotnet/tools
Add to PATH if missing (Linux/macOS):
export PATH="$PATH:$HOME/.dotnet/tools"
Add to PATH if missing (Windows):
$env:PATH += ";$env:USERPROFILE\.dotnet\tools"
Restart your terminal after modifying PATH
Installation Fails with “Unable to find package”
Problem: dotnet tool install Morphir.CLI fails to find the package.
Solution:
Check NuGet sources:
Add nuget.org if missing:
dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org
Verify package name - ensure you’re using the correct package name
Validation Issues
“File does not exist” Error
Problem:
Error: File does not exist: morphir-ir.json
Solutions:
Check file path:
Use absolute path:
morphir ir verify /full/path/to/morphir-ir.json
Check current directory:
pwd
cd /path/to/ir/files
morphir ir verify morphir-ir.json
Problem:
Message: Malformed JSON: 'i' is an invalid start of a value. LineNumber: 6
Solutions:
Validate JSON syntax with a JSON validator:
cat morphir-ir.json | jq .
Check for common issues:
- Missing commas between array/object elements
- Trailing commas (not allowed in JSON)
- Unquoted keys or values
- Invalid escape sequences
Use a JSON formatter:
cat morphir-ir.json | jq . > morphir-ir-formatted.json
Schema Version Detection Issues
Problem: Auto-detection selects the wrong schema version.
Solutions:
Explicitly specify version:
morphir ir verify --schema-version 3 morphir-ir.json
Check formatVersion field (for v2/v3):
cat morphir-ir.json | jq '.formatVersion'
Verify IR structure:
- v1: No
formatVersion field - v2:
"formatVersion": 2 - v3:
"formatVersion": 3
Validation Fails but IR Appears Correct
Problem: Validation reports errors, but you believe the IR is valid.
Investigation Steps:
Review error messages carefully - they include Expected vs. Found values
Check schema documentation - Schema Specifications
Validate against different versions:
morphir ir verify --schema-version 1 morphir-ir.json
morphir ir verify --schema-version 2 morphir-ir.json
morphir ir verify --schema-version 3 morphir-ir.json
Compare with known-good IR:
# Validate a reference file
morphir ir verify reference-morphir-ir.json
Check for common issues:
- Incorrect tag capitalization (e.g.,
"Public" vs "public") - Missing required fields
- Incorrect array structure
- Type mismatches
Validation Takes Too Long
Problem: Validation of large IR files (>1MB) takes several seconds.
Current Limitations:
- This is expected behavior for large files in Phase 1
- Schema validation is inherently slower for complex, deeply-nested JSON
Workarounds:
Use --quiet mode to reduce output overhead:
morphir ir verify --quiet morphir-ir.json
Validate in parallel (for multiple files):
find . -name "*.json" | xargs -P 4 -I {} morphir ir verify --quiet {}
Phase 2 improvements (coming soon):
- Performance optimizations for batch processing
- Caching and incremental validation
High Memory Usage
Problem: Validation consumes excessive memory for very large IR files.
Solutions:
Check file size:
For files >10MB:
- Consider splitting into smaller modules
- Report the issue with file size details
Increase available memory (if using Docker):
docker run --memory 2g morphir-cli ir verify morphir-ir.json
CI/CD Integration Issues
CI Pipeline Doesn’t Fail on Invalid IR
Problem: Pipeline continues even when validation fails.
Solution: Check exit codes explicitly:
# GitHub Actions
- name: Validate IR
run: |
morphir ir verify morphir-ir.json
if [ $? -ne 0 ]; then
echo "Validation failed"
exit 1
fi
Or use set -e in bash scripts:
#!/bin/bash
set -e # Exit on any error
morphir ir verify morphir-ir.json
echo "Validation succeeded!"
JSON Output Not Parsed Correctly
Problem: CI tools can’t parse JSON output.
Solutions:
Verify JSON format:
morphir ir verify --json morphir-ir.json | jq .
Save to file:
morphir ir verify --json morphir-ir.json > validation-result.json
Check for extra output:
- Use
--quiet with --json to suppress non-JSON output - Some logging may appear on stderr
Permission Denied in Docker
Problem:
Permission denied: /app/morphir-ir.json
Solution: Fix file permissions or use volume mounts:
# In Dockerfile
RUN chmod +r /app/*.json
# Or when running
docker run -v $(pwd):/app:ro morphir-cli ir verify /app/morphir-ir.json
Error Message Reference
Common Validation Errors
Missing Required Field
Path: $.distribution
Message: Required properties ["formatVersion"] are not present
Expected: required property
Found: undefined (missing)
Fix: Add the missing field to your JSON:
{
"formatVersion": 3,
"distribution": [ ... ]
}
Type Mismatch
Path: $.modules[0].name
Message: Value is "string" but should be "array"
Expected: array
Found: string
Fix: Change the field type:
// Incorrect
"name": "MyModule"
// Correct
"name": ["my", "module"]
Invalid Tag Value
Path: $.modules[0].accessControl
Message: Value must be one of: ["Public", "Private"]
Expected: "Public" or "Private"
Found: "public"
Fix: Use correct capitalization:
// Incorrect
"accessControl": "public"
// Correct
"accessControl": "Public"
Array Structure Error
Path: $.distribution[2]
Message: Expected array to have exactly 4 elements
Expected: array of length 4
Found: array of length 3
Fix: Ensure array has the correct number of elements per schema.
Reporting Issues
If you encounter an issue not covered here:
Check existing issues: GitHub Issues
Gather information:
- Morphir .NET CLI version:
morphir --version - .NET SDK version:
dotnet --version - Operating system and version
- Complete error message
- Minimal reproduction steps
Create a new issue with:
- Clear title describing the problem
- Steps to reproduce
- Expected vs. actual behavior
- Environment information
- Sample IR file (if possible) or minimal example
No Active Version Set
Problem: Running morphir dist which or morphir tool which <name> shows “No active version set”.
Solution:
List installed versions:
morphir dist list
morphir tool list
Set an active version:
# Global
morphir dist use <version>
morphir tool use <name> <version>
# Local (project-specific)
morphir dist use <version> --local
morphir tool use <name> <version> --local
Problem: Installation fails with “Platform not supported” or downloaded artifact doesn’t work.
Solution:
Check current platform:
Manually specify platform:
morphir dist install <url> <version> --platform linux-x64
Verify available platforms: Check the distribution documentation for supported platforms.
Local vs Global Confusion
Problem: Setting a version locally but it’s not being used.
Solution:
- Remember precedence: Local (
.morphir/) overrides global (~/.config/morphir/) - Check both scopes:
morphir dist which # Shows resolved version (local > global)
morphir dist list # Shows global installations
morphir dist list --local # Shows local installations
- Clear local selection: Remove the active selection file in
.morphir/dist/active or .morphir/tools/active-<name>
Installation Directory Not Created
Problem: Installation fails because parent directories don’t exist.
Solution:
The CLI should create directories automatically. If this fails:
Manually create directories:
# Global
mkdir -p ~/.config/morphir/{dist,tools,extensions}
# Local
mkdir -p .morphir/{dist,tools,extensions}
Check permissions:
Downloaded Artifact Is Corrupted
Problem: Installation completes but artifacts don’t work or are corrupted.
Solution:
Check manifest for hash:
cat ~/.config/morphir/dist/<platform>/<version>/manifest.json
Verify download integrity (if SHA256 is in manifest):
sha256sum ~/.config/morphir/dist/<platform>/<version>/bin/artifact
Re-download:
morphir dist remove <version>
morphir dist install <url> <version>
Getting Help
See Also