diff --git a/Makefile b/Makefile index df568526..04bcac72 100644 --- a/Makefile +++ b/Makefile @@ -82,6 +82,9 @@ test-ui: node_modules .PHONY: sandbox-index sandbox-index: compile + $(PREFIX)/bin/sourcemeta-one-index \ + $(SANDBOX)/one-$(SANDBOX_CONFIGURATION).json \ + $(OUTPUT)/sandbox --url $(SANDBOX_URL) --configuration $(PREFIX)/bin/sourcemeta-one-index \ $(SANDBOX)/one-$(SANDBOX_CONFIGURATION).json \ $(OUTPUT)/sandbox --url $(SANDBOX_URL) --profile @@ -142,6 +145,7 @@ docs: mkdocs.yml .PHONY: public public: + $(PREFIX)/bin/sourcemeta-one-index $(PUBLIC)/one.json $(OUTPUT)/public --configuration $(PREFIX)/bin/sourcemeta-one-index $(PUBLIC)/one.json $(OUTPUT)/public --verbose $(PREFIX)/bin/sourcemeta-one-server $(OUTPUT)/public 8000 diff --git a/src/index/index.cc b/src/index/index.cc index 6d741d99..5576bcdc 100644 --- a/src/index/index.cc +++ b/src/index/index.cc @@ -102,9 +102,10 @@ static auto index_main(const std::string_view &program, const auto raw_configuration{sourcemeta::one::Configuration::read( configuration_path, SOURCEMETA_ONE_COLLECTIONS)}; - if (app.contains("verbose")) { - sourcemeta::core::prettify(raw_configuration, std::cerr); - std::cerr << "\n"; + if (app.contains("configuration")) { + sourcemeta::core::prettify(raw_configuration, std::cout); + std::cout << "\n"; + return EXIT_SUCCESS; } auto configuration{sourcemeta::one::Configuration::parse(raw_configuration)}; @@ -600,6 +601,7 @@ auto main(int argc, char *argv[]) noexcept -> int { app.option("concurrency", {"c"}); app.flag("verbose", {"v"}); app.flag("profile", {"p"}); + app.flag("configuration", {"g"}); app.parse(argc, argv); const std::string_view program{argv[0]}; diff --git a/test/cli/CMakeLists.txt b/test/cli/CMakeLists.txt index f5571957..4e80c5ed 100644 --- a/test/cli/CMakeLists.txt +++ b/test/cli/CMakeLists.txt @@ -30,11 +30,14 @@ if(ONE_INDEX) sourcemeta_one_test_cli(common index rebuild-to-empty) sourcemeta_one_test_cli(common index verbose-long) sourcemeta_one_test_cli(common index verbose-short) + sourcemeta_one_test_cli(common index configuration-long) + sourcemeta_one_test_cli(common index configuration-short) sourcemeta_one_test_cli(common index no-base-uri) if(ONE_ENTERPRISE) sourcemeta_one_test_cli(enterprise index no-options) sourcemeta_one_test_cli(enterprise index no-output) + sourcemeta_one_test_cli(enterprise index sourcemeta-std) else() sourcemeta_one_test_cli(community index no-options) sourcemeta_one_test_cli(community index no-output) diff --git a/test/cli/index/common/configuration-long.sh b/test/cli/index/common/configuration-long.sh new file mode 100755 index 00000000..5daf12d2 --- /dev/null +++ b/test/cli/index/common/configuration-long.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +set -o errexit +set -o nounset + +TMP="$(mktemp -d)" +clean() { rm -rf "$TMP"; } +trap clean EXIT + +cat << EOF > "$TMP/one.json" +{ + "url": "https://sourcemeta.com/", + "contents": { + "example": { + "contents": { + "schemas": { + "baseUri": "https://example.com/", + "path": "./schemas" + } + } + } + } +} +EOF + +mkdir "$TMP/schemas" + +cat << 'EOF' > "$TMP/schemas/foo.json" +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://example.com/foo" +} +EOF + +"$1" "$TMP/one.json" "$TMP/output" --configuration | tail -n +2 > "$TMP/output.txt" +cat << EOF > "$TMP/expected.txt" +{ + "url": "https://sourcemeta.com/", + "contents": { + "example": { + "contents": { + "schemas": { + "baseUri": "https://example.com/", + "path": "$(realpath "$TMP")/schemas" + } + } + } + }, + "html": { + "name": "Sourcemeta", + "description": "The next-generation JSON Schema platform" + } +} +EOF +diff "$TMP/output.txt" "$TMP/expected.txt" diff --git a/test/cli/index/common/configuration-short.sh b/test/cli/index/common/configuration-short.sh new file mode 100755 index 00000000..c75b8139 --- /dev/null +++ b/test/cli/index/common/configuration-short.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +set -o errexit +set -o nounset + +TMP="$(mktemp -d)" +clean() { rm -rf "$TMP"; } +trap clean EXIT + +cat << EOF > "$TMP/one.json" +{ + "url": "https://sourcemeta.com/", + "contents": { + "example": { + "contents": { + "schemas": { + "baseUri": "https://example.com/", + "path": "./schemas" + } + } + } + } +} +EOF + +mkdir "$TMP/schemas" + +cat << 'EOF' > "$TMP/schemas/foo.json" +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "https://example.com/foo" +} +EOF + +"$1" "$TMP/one.json" "$TMP/output" -g | tail -n +2 > "$TMP/output.txt" +cat << EOF > "$TMP/expected.txt" +{ + "url": "https://sourcemeta.com/", + "contents": { + "example": { + "contents": { + "schemas": { + "baseUri": "https://example.com/", + "path": "$(realpath "$TMP")/schemas" + } + } + } + }, + "html": { + "name": "Sourcemeta", + "description": "The next-generation JSON Schema platform" + } +} +EOF +diff "$TMP/output.txt" "$TMP/expected.txt" diff --git a/test/cli/index/common/verbose-long.sh b/test/cli/index/common/verbose-long.sh index c35285df..d1af779e 100755 --- a/test/cli/index/common/verbose-long.sh +++ b/test/cli/index/common/verbose-long.sh @@ -46,23 +46,6 @@ remove_threads_information "$TMP/output.txt" cat << EOF > "$TMP/expected.txt" Writing output to: $(realpath "$TMP")/output Using configuration: $(realpath "$TMP")/one.json -{ - "url": "https://sourcemeta.com/", - "contents": { - "example": { - "contents": { - "schemas": { - "baseUri": "https://example.com/", - "path": "$(realpath "$TMP")/schemas" - } - } - } - }, - "html": { - "name": "Sourcemeta", - "description": "The next-generation JSON Schema platform" - } -} Detecting: $(realpath "$TMP")/schemas/foo.json (#1) https://example.com/foo => https://sourcemeta.com/example/schemas/foo (100%) Ingesting: https://sourcemeta.com/example/schemas/foo diff --git a/test/cli/index/common/verbose-short.sh b/test/cli/index/common/verbose-short.sh index 0ae313b5..787282a3 100755 --- a/test/cli/index/common/verbose-short.sh +++ b/test/cli/index/common/verbose-short.sh @@ -46,23 +46,6 @@ remove_threads_information "$TMP/output.txt" cat << EOF > "$TMP/expected.txt" Writing output to: $(realpath "$TMP")/output Using configuration: $(realpath "$TMP")/one.json -{ - "url": "https://sourcemeta.com/", - "contents": { - "example": { - "contents": { - "schemas": { - "baseUri": "https://example.com/", - "path": "$(realpath "$TMP")/schemas" - } - } - } - }, - "html": { - "name": "Sourcemeta", - "description": "The next-generation JSON Schema platform" - } -} Detecting: $(realpath "$TMP")/schemas/foo.json (#1) https://example.com/foo => https://sourcemeta.com/example/schemas/foo (100%) Ingesting: https://sourcemeta.com/example/schemas/foo diff --git a/test/cli/index/community/sourcemeta-std.sh b/test/cli/index/community/sourcemeta-std.sh index 9a8e471f..551ed8d7 100755 --- a/test/cli/index/community/sourcemeta-std.sh +++ b/test/cli/index/community/sourcemeta-std.sh @@ -14,7 +14,7 @@ cat << EOF > "$TMP/one.json" } EOF -"$1" "$TMP/one.json" "$TMP/output" 2> "$TMP/output.txt" && CODE="$?" || CODE="$?" +"$1" "$TMP/one.json" "$TMP/output" --configuration 2> "$TMP/output.txt" && CODE="$?" || CODE="$?" test "$CODE" = "1" || exit 1 cat << EOF > "$TMP/expected.txt" diff --git a/test/cli/index/enterprise/sourcemeta-std.sh b/test/cli/index/enterprise/sourcemeta-std.sh new file mode 100755 index 00000000..fe96d862 --- /dev/null +++ b/test/cli/index/enterprise/sourcemeta-std.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +set -o errexit +set -o nounset + +TMP="$(mktemp -d)" +clean() { rm -rf "$TMP"; } +trap clean EXIT + +cat << EOF > "$TMP/one.json" +{ + "url": "https://example.com/", + "extends": [ "@sourcemeta/std/v0" ] +} +EOF + +"$1" "$TMP/one.json" "$TMP/output" --configuration | tail -n +2 > "$TMP/output.txt" + +cat << EOF > "$TMP/expected.txt" +{ + "contents": { + "sourcemeta": { + "title": "Sourcemeta", + "description": "A provider of premium tooling and services to support JSON Schema use in production", + "email": "hello@sourcemeta.com", + "github": "sourcemeta", + "website": "https://www.sourcemeta.com", + "contents": { + "std": { + "title": "The JSON Schema Standard Library", + "description": "A growing collection of hand-crafted high-quality schemas by Sourcemeta", + "email": "hello@sourcemeta.com", + "github": "sourcemeta/std", + "website": "https://www.sourcemeta/products/std", + "contents": { + "v0": { + "x-sourcemeta-one:provenance": "@sourcemeta/std/v0", + "path": "$ONE_PREFIX/share/sourcemeta/one/collections/sourcemeta/std/v0/schemas/2020-12", + "baseUri": "https://example.com/" + } + } + } + } + } + }, + "url": "https://example.com/", + "html": { + "name": "Sourcemeta", + "description": "The next-generation JSON Schema platform" + } +} +EOF + +diff "$TMP/output.txt" "$TMP/expected.txt"