Skip to content

Commit

Permalink
feat (cli): Add info metadata CLI sub-command
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed Sep 6, 2024
1 parent 54da115 commit b5431cd
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 11 deletions.
2 changes: 2 additions & 0 deletions docs/concepts/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Enola uses Metadata about all of its _Things_ when rendering them:
* image of a logo; e.g. from [favicon](https://de.wikipedia.org/wiki/Favicon) or something like that; or an 😃 Emoji!
* curie is a compact URI; a shorter form of the original "long" IRI of the Thing.

[The `info metadata` sub-command](../use/info/index.md) is a handy tool to test this.

<!-- The following documents the dev.enola.thing.metadata.ThingMetadataProvider service; keep it updated, if it ever changes. -->

## Label
Expand Down
9 changes: 9 additions & 0 deletions docs/use/info/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ $ ./enola info detect --file-scheme picasso.thing.yaml

Note that this file does not exist, this is fine; the type of its content is determine by the extension (in this case).

## Metadata

```bash cd ../.././..
$ ./enola info metadata --load=test/metadata-label-property.ttl https://example.org/test-metadata-label-property
...
```

[Metadata](../../concepts/metadata.md) explains what this is about.

## Screencast

![Demo](script.svg)
2 changes: 1 addition & 1 deletion java/dev/enola/cli/InfoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
@Command(
name = "info",
description = "Provides various information",
subcommands = {ExtensionsInfoCommand.class, DetectCommand.class})
subcommands = {ExtensionsInfoCommand.class, DetectCommand.class, MetadataCommand.class})
public class InfoCommand {}
38 changes: 38 additions & 0 deletions java/dev/enola/cli/MetadataCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2024 The Enola <https://enola.dev> Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.enola.cli;

import dev.enola.core.proto.EnolaServiceGrpc;
import dev.enola.web.EnolaThingProvider;

import picocli.CommandLine;

@CommandLine.Command(name = "metadata", description = "Provides metadata for a given IRI")
public class MetadataCommand extends CommandWithModel {

@CommandLine.Parameters(index = "0", paramLabel = "iri", description = "IRI")
String iri;

@Override
protected void run(EnolaServiceGrpc.EnolaServiceBlockingStub service) throws Exception {
var mdp = getMetadataProvider(new EnolaThingProvider(service));

var metadata = mdp.get(iri);
spec.commandLine().getOut().println(metadata);
}
}
16 changes: 6 additions & 10 deletions java/dev/enola/thing/metadata/ThingMetadataProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,12 @@ public class ThingMetadataProviderTest {
private final String THING_LABEL = "DaThang!";

private final ThingProvider test =
new ThingProvider() {

@Override
public @Nullable Thing get(String iri) {
var builder = ImmutableThing.builder();
builder.set(KIRI.SCHEMA.NAME, THING_LABEL);
builder.set(KIRI.DC.DESCRIPTION, "...");
builder.iri(THING_IRI);
return builder.build();
}
iri -> {
var builder = ImmutableThing.builder();
builder.set(KIRI.SCHEMA.NAME, THING_LABEL);
builder.set(KIRI.DC.DESCRIPTION, "...");
builder.iri(THING_IRI);
return builder.build();
};

private final ThingProvider error =
Expand Down
25 changes: 25 additions & 0 deletions test/metadata-label-property.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2024 The Enola <https://enola.dev> Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

@prefix enola: <https://enola.dev/>.
@prefix example: <https://example.org/>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.

example:test-metadata-label-property-class a rdfs:Class;
enola:label-property enola:altlab.

example:test-metadata-label-property a example:test-metadata-label-property-class;
enola:altlab "LABEL".

0 comments on commit b5431cd

Please sign in to comment.