-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Initial GET on CLI (re. #72)
- Loading branch information
Showing
14 changed files
with
189 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2023 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.EnolaServiceRegistry; | ||
import dev.enola.core.IDs; | ||
import dev.enola.core.meta.EntityKindRepository; | ||
import dev.enola.core.proto.GetEntityRequest; | ||
import dev.enola.core.proto.ID; | ||
|
||
import picocli.CommandLine; | ||
import picocli.CommandLine.Model.CommandSpec; | ||
import picocli.CommandLine.Parameters; | ||
import picocli.CommandLine.Spec; | ||
|
||
@CommandLine.Command(name = "get", description = "Get Entity") | ||
public class Get extends CommandWithModel { | ||
|
||
// TODO @Parameters(index = "0..*") List<String> ids; | ||
// TODO ID instead of String, with https://picocli.info/#_strongly_typed_everything | ||
@Parameters(index = "0", paramLabel = "id", description = "ID of Entity") | ||
String idString; | ||
|
||
@Spec CommandSpec spec; | ||
|
||
@Override | ||
protected void run(EntityKindRepository ekr) throws Exception { | ||
// TODO Move this from CLI to Core? | ||
EnolaServiceRegistry service = new EnolaServiceRegistry(); | ||
// TODO registry.register(...); | ||
|
||
ID id = IDs.parse(idString); // TODO replace with ITypeConverter | ||
// TODO Validate id; here it must have ns+name+path! | ||
|
||
var request = GetEntityRequest.newBuilder().setId(id).build(); | ||
var response = service.getEntity(request); | ||
var entity = response.getEntity(); | ||
|
||
// TODO Allow formatting it as JSON or YAML, via Resource! | ||
// TODO What else do we do with the Entity?! | ||
spec.commandLine().getOut().println(entity); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
core/impl/src/main/java/dev/enola/core/EnolaServiceRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Copyright 2023 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.core; | ||
|
||
import dev.enola.core.proto.GetEntityRequest; | ||
import dev.enola.core.proto.GetEntityResponse; | ||
import dev.enola.core.proto.ID; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class EnolaServiceRegistry implements EnolaService { | ||
|
||
private final Map<ID, EnolaService> registry; | ||
|
||
public EnolaServiceRegistry() { | ||
registry = new HashMap<>(); | ||
} | ||
|
||
public void register(ID id, EnolaService service) { | ||
var lookup = IDs.withoutPath(id); | ||
var existing = registry.get(lookup); | ||
if (existing != null) { | ||
throw new IllegalArgumentException("Service already registered for: " + lookup); | ||
} | ||
registry.put(lookup, service); | ||
} | ||
|
||
@Override | ||
public GetEntityResponse getEntity(GetEntityRequest r) { | ||
var lookup = IDs.withoutPath(r.getId()); | ||
var delegate = registry.get(lookup); | ||
if (delegate == null) { | ||
throw new IllegalArgumentException("No Connector registered for: " + lookup); | ||
} | ||
return delegate.getEntity(r); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters