nip/examples/json-output-demo.nim

89 lines
2.9 KiB
Nim
Executable File

#!/usr/bin/env nim
## JSON Output Demo for NIP Package Manager
## Demonstrates comprehensive machine-readable output formats
import std/[os, strutils, json]
proc runCommand(cmd: string): void =
echo "🔹 Command: ", cmd
let result = execShellCmd(cmd)
if result != 0:
echo "❌ Command failed with exit code: ", result
echo ""
proc main() =
echo """
╔══════════════════════════════════════════════════════════════╗
║ NIP JSON Output Demo ║
║ Machine-Readable Package Management ║
╚══════════════════════════════════════════════════════════════╝
This demo showcases the comprehensive JSON output capabilities of NIP,
enabling automation, tooling integration, and AI-friendly interfaces.
Features demonstrated:
• Complete package metadata with CAS paths and CIDs
• Variant fingerprint information
• Integrity status monitoring
• Installation and dependency data
• Multiple output formats (JSON, YAML, KDL)
"""
# Ensure we're in the right directory
if not fileExists("src/nip.out"):
echo "❌ Error: nip.out not found. Please run 'nim c -d:release src/nip.nim' first"
quit(1)
echo "🚀 Starting JSON Output Demo..."
echo "=" .repeat(60)
# Demo 1: Enhanced Search with JSON
echo "\n📊 Demo 1: Enhanced Search (JSON)"
echo "-" .repeat(40)
runCommand("./src/nip.out search firefox --json")
# Demo 2: Package Listing with JSON
echo "\n📦 Demo 2: Package Listing (JSON)"
echo "-" .repeat(40)
runCommand("./src/nip.out list --json")
# Demo 3: Package Information with JSON
echo "\n📋 Demo 3: Package Information (JSON)"
echo "-" .repeat(40)
runCommand("./src/nip.out show firefox --json")
# Demo 4: YAML Output Format
echo "\n📄 Demo 4: YAML Output Format"
echo "-" .repeat(40)
runCommand("./src/nip.out search firefox --yaml")
# Demo 5: KDL Output Format
echo "\n📝 Demo 5: KDL Output Format"
echo "-" .repeat(40)
runCommand("./src/nip.out search firefox --kdl")
echo "\n✅ JSON Output Demo Complete!"
echo """
The NIP package manager now provides:
✓ Comprehensive JSON output with complete metadata
✓ CAS paths and Content Identifiers (CIDs)
✓ Variant fingerprint information
✓ Integrity status monitoring
✓ Multiple structured formats (JSON, YAML, KDL)
✓ AI and automation-friendly interfaces
✓ Stable schema for tooling integration
Perfect for:
• CI/CD pipeline integration
• Infrastructure as Code
• Package management automation
• AI assistant integration
• Custom tooling development
• System monitoring and reporting
🎉 Ready for production automation!
"""
when isMainModule:
main()