mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 06:14:59 +00:00
- Implemented component schema validation in `component_schema.lua`. - Created metadata schema validation in `metadata_schema.lua`. - Developed structure validation logic in `structure_validator.lua`. - Introduced Lua file validation functions in `lua_validator.lua`. - Added integration tests for validation logic in `validate.test.lua`. - Created unit tests for component, metadata, and structure validation. - Added SVG icon for package representation. - Established a main validation orchestrator in `validate.lua` to coordinate the validation process.
173 lines
3.9 KiB
Lua
173 lines
3.9 KiB
Lua
-- CLI tool for validating packages
|
|
-- Usage: lua cli.lua <package_name> [options]
|
|
|
|
local validate = require("validate")
|
|
|
|
local M = {}
|
|
|
|
-- Parse command line arguments
|
|
function M.parse_args(args)
|
|
local options = {
|
|
package_name = nil,
|
|
skipStructure = false,
|
|
skipLua = false,
|
|
verbose = false,
|
|
json_output = false
|
|
}
|
|
|
|
local i = 1
|
|
while i <= #args do
|
|
local arg = args[i]
|
|
|
|
if arg == "--skip-structure" then
|
|
options.skipStructure = true
|
|
elseif arg == "--skip-lua" then
|
|
options.skipLua = true
|
|
elseif arg == "--verbose" or arg == "-v" then
|
|
options.verbose = true
|
|
elseif arg == "--json" then
|
|
options.json_output = true
|
|
elseif arg == "--help" or arg == "-h" then
|
|
M.print_help()
|
|
os.exit(0)
|
|
elseif not options.package_name then
|
|
options.package_name = arg
|
|
end
|
|
|
|
i = i + 1
|
|
end
|
|
|
|
return options
|
|
end
|
|
|
|
-- Print help message
|
|
function M.print_help()
|
|
print([[
|
|
Package Validator CLI
|
|
|
|
Usage:
|
|
lua cli.lua <package_name> [options]
|
|
|
|
Arguments:
|
|
package_name Name of the package to validate
|
|
|
|
Options:
|
|
--skip-structure Skip folder structure validation
|
|
--skip-lua Skip Lua file validation
|
|
--verbose, -v Show detailed validation information
|
|
--json Output results as JSON
|
|
--help, -h Show this help message
|
|
|
|
Examples:
|
|
# Validate audit_log package
|
|
lua cli.lua audit_log
|
|
|
|
# Validate with verbose output
|
|
lua cli.lua audit_log --verbose
|
|
|
|
# Skip structure validation
|
|
lua cli.lua audit_log --skip-structure
|
|
|
|
# Output as JSON (for CI/CD integration)
|
|
lua cli.lua audit_log --json
|
|
|
|
Exit Codes:
|
|
0 - Validation passed
|
|
1 - Validation failed
|
|
2 - Invalid arguments or package not found
|
|
]])
|
|
end
|
|
|
|
-- Output results as JSON
|
|
function M.output_json(results)
|
|
local json_output = {
|
|
valid = results.valid,
|
|
errors = results.errors,
|
|
warnings = results.warnings
|
|
}
|
|
|
|
-- Simple JSON serialization
|
|
local function serialize_array(arr)
|
|
local items = {}
|
|
for _, item in ipairs(arr) do
|
|
table.insert(items, '"' .. item:gsub('"', '\\"') .. '"')
|
|
end
|
|
return "[" .. table.concat(items, ",") .. "]"
|
|
end
|
|
|
|
print("{")
|
|
print(' "valid": ' .. tostring(results.valid) .. ',')
|
|
print(' "errors": ' .. serialize_array(results.errors) .. ',')
|
|
print(' "warnings": ' .. serialize_array(results.warnings))
|
|
print("}")
|
|
end
|
|
|
|
-- Output results in human-readable format
|
|
function M.output_human(results, verbose)
|
|
local output = validate.format_results(results)
|
|
print(output)
|
|
|
|
if verbose and #results.errors > 0 then
|
|
print("\n--- Detailed Error Information ---")
|
|
for i, err in ipairs(results.errors) do
|
|
print(i .. ". " .. err)
|
|
end
|
|
end
|
|
|
|
if verbose and #results.warnings > 0 then
|
|
print("\n--- Detailed Warning Information ---")
|
|
for i, warn in ipairs(results.warnings) do
|
|
print(i .. ". " .. warn)
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Main entry point
|
|
function M.run(args)
|
|
local options = M.parse_args(args)
|
|
|
|
if not options.package_name then
|
|
print("Error: Package name is required")
|
|
print("Use --help for usage information")
|
|
os.exit(2)
|
|
end
|
|
|
|
-- Construct package path
|
|
local package_path = "packages/" .. options.package_name .. "/seed"
|
|
|
|
-- Check if package exists
|
|
local metadata_file = io.open(package_path .. "/metadata.json", "r")
|
|
if not metadata_file then
|
|
print("Error: Package '" .. options.package_name .. "' not found")
|
|
os.exit(2)
|
|
end
|
|
metadata_file:close()
|
|
|
|
-- Validate package
|
|
local results = validate.validate_package(package_path, {
|
|
skipStructure = options.skipStructure,
|
|
skipLua = options.skipLua
|
|
})
|
|
|
|
-- Output results
|
|
if options.json_output then
|
|
M.output_json(results)
|
|
else
|
|
M.output_human(results, options.verbose)
|
|
end
|
|
|
|
-- Exit with appropriate code
|
|
if results.valid then
|
|
os.exit(0)
|
|
else
|
|
os.exit(1)
|
|
end
|
|
end
|
|
|
|
return M
|
|
|
|
-- If run directly, execute main
|
|
if arg then
|
|
M.run(arg)
|
|
end
|