1
2
3
4
5
6 package gov.nist.secauto.metaschema.cli.processor.command;
7
8 import gov.nist.secauto.metaschema.core.util.ObjectUtils;
9 import gov.nist.secauto.metaschema.core.util.UriUtils;
10
11 import java.net.URI;
12 import java.net.URISyntaxException;
13 import java.nio.file.Path;
14 import java.nio.file.Paths;
15 import java.util.Collection;
16 import java.util.Collections;
17
18 import edu.umd.cs.findbugs.annotations.NonNull;
19 import nl.talsmasoftware.lazy4j.Lazy;
20
21 public abstract class AbstractTerminalCommand implements ICommand {
22 private static Lazy<Path> currentWorkingDirectory = Lazy.lazy(() -> Paths.get("").toAbsolutePath());
23
24 @SuppressWarnings("null")
25 @Override
26 public Collection<ICommand> getSubCommands() {
27 return Collections.emptyList();
28 }
29
30 @Override
31 public boolean isSubCommandRequired() {
32 return false;
33 }
34
35 @NonNull
36 protected static Path getCurrentWorkingDirectory() {
37 return ObjectUtils.notNull(currentWorkingDirectory.get());
38 }
39
40 @NonNull
41 protected static Path resolveAgainstCWD(@NonNull Path path) {
42 return ObjectUtils.notNull(getCurrentWorkingDirectory().resolve(path).normalize());
43 }
44
45 @NonNull
46 protected static URI resolveAgainstCWD(@NonNull URI uri) {
47 return ObjectUtils.notNull(getCurrentWorkingDirectory().toUri().resolve(uri.normalize()));
48 }
49
50 @NonNull
51 protected static URI resolveAgainstCWD(@NonNull String uri) throws URISyntaxException {
52 return UriUtils.toUri(uri, ObjectUtils.notNull(getCurrentWorkingDirectory().toUri()));
53 }
54 }