Skip to content

Package: ListManagedFilesArgsInterpreter

ListManagedFilesArgsInterpreter

nameinstructionbranchcomplexitylinemethod
ListManagedFilesArgsInterpreter(DataManagerPresentationControl, DataManagerPresentation, UsageArgsInterpreter)
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
doRun(ApplicationArguments)
M: 0 C: 66
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 14
100%
M: 0 C: 1
100%
printUsage()
M: 0 C: 32
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * *********************************************************************************************************************
3: *
4: * SolidBlue 3: Data safety
5: * http://tidalwave.it/projects/solidblue3
6: *
7: * Copyright (C) 2023 - 2023 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/solidblue3j-src
23: * git clone https://github.com/tidalwave-it/solidblue3j-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.datamanager.application.nogui.args;
28:
29: import jakarta.annotation.Nonnull;
30: import java.util.Set;
31: import org.springframework.boot.ApplicationArguments;
32: import org.springframework.core.annotation.Order;
33: import org.springframework.stereotype.Component;
34: import it.tidalwave.datamanager.application.nogui.DataManagerPresentation;
35: import it.tidalwave.datamanager.application.nogui.DataManagerPresentationControl;
36: import static it.tidalwave.datamanager.application.nogui.DataManagerPresentationControl.ManagedFileOptions.with;
37: import static it.tidalwave.datamanager.application.nogui.args.ArgumentsUtils.*;
38:
39: /***********************************************************************************************************************
40: *
41: * The command line args interpreter for the {@code list-files} command.
42: *
43: * @author Fabrizio Giudici
44: *
45: **********************************************************************************************************************/
46: @Component @Order(0)
47: public class ListManagedFilesArgsInterpreter extends ArgsInterpreterSupport implements UsageCapable
48: {
49: private static final String COMMAND = "list-files";
50: private static final String O_FINGERPRINTS = "fingerprints";
51: private static final String O_MAX = "max";
52: private static final String O_REGEX = "regex";
53: private static final String O_FINGERPRINT = "fingerprint";
54: private static final String O_MISSING = "missing";
55:
56: @Nonnull
57: private final DataManagerPresentationControl presentationControl;
58:
59: @Nonnull
60: private final DataManagerPresentation presentation;
61:
62: @Nonnull
63: private final UsageArgsInterpreter usageArgsInterpreter;
64:
65: /*******************************************************************************************************************
66: * {@inheritDoc}
67: ******************************************************************************************************************/
68: public ListManagedFilesArgsInterpreter (@Nonnull final DataManagerPresentationControl presentationControl,
69: @Nonnull final DataManagerPresentation presentation,
70: @Nonnull final UsageArgsInterpreter usageArgsInterpreter)
71: {
72: super(COMMAND, Set.of(O_FINGERPRINTS, O_MAX, O_REGEX, O_MISSING, O_FINGERPRINT), presentation);
73: this.presentationControl = presentationControl;
74: this.presentation = presentation;
75: this.usageArgsInterpreter = usageArgsInterpreter;
76: }
77:
78: /*******************************************************************************************************************
79: * {@inheritDoc}
80: ******************************************************************************************************************/
81: @Override
82: protected void doRun (@Nonnull final ApplicationArguments args)
83: {
84: final var fingerprints = args.containsOption(O_FINGERPRINTS);
85: final var max = getIntOption(args, O_MAX);
86: final var regex = getStringOption(args, O_REGEX);
87: final var fingerprint = getStringOption(args, O_FINGERPRINT);
88: final var missingFiles = args.containsOption(O_MISSING);
89:
90:• if ((regex.isPresent() || missingFiles) && max.isPresent())
91: {
92: presentation.notifyError("--%s cannot be used with --%s or --%s".formatted(O_MAX, O_REGEX, O_MISSING));
93: }
94: else
95: {
96: usageArgsInterpreter.disableUsage();
97: presentationControl.renderManagedFiles(with().renderFingerprints(fingerprints)
98: .max(max)
99: .regex(regex)
100: .fingerprint(fingerprint)
101: .missingFiles(missingFiles));
102: }
103: }
104:
105: /*******************************************************************************************************************
106: * {@inheritDoc}
107: ******************************************************************************************************************/
108: @Override
109: public void printUsage()
110: {
111: presentation.output("""
112: solidblue3 %1$s [--%2$s=<n>] [--%3$s=<regex>] [--%4$s=<value> [--%5$s] [--%6$s]
113: list files on the console
114: --%2$s=<n> the max number of files to list
115: --%3$s=<regex> a filter for the files to list
116: --%4$s=<value> filter file(s) with that fingerprint
117: --%5$s only list files no more in the filesystem
118: --%6$s also render fingerprints
119:
120: --max cannot be used with --regex and --missing
121: """.formatted("list-files", O_MAX, O_REGEX, O_FINGERPRINT, O_MISSING, O_FINGERPRINTS));
122: }
123: }