Skip to content

Commit 55fbaf2

Browse files
committed
initial implementation of #255
1 parent 68f0298 commit 55fbaf2

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/dtsx/astra/cli/commands/AbstractCmd.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ public final void run() {
112112
);
113113

114114
val level =
115-
(common.quiet())
116-
? Level.QUIET :
117115
(common.verbose())
118-
? Level.VERBOSE
116+
? Level.VERBOSE :
117+
(common.quiet())
118+
? Level.QUIET
119119
: ctx.logLevel();
120120

121121
run(new CliContext(

src/main/java/com/dtsx/astra/cli/commands/CommonOptions.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,32 @@ public enum ColorMode { auto, never, always }
3333
@Option(
3434
names = "--color",
3535
description = { "One of: ${COMPLETION-CANDIDATES}", SHOW_CUSTOM_DEFAULT + "auto" },
36+
arity = "0..1",
3637
fallbackValue = "always",
38+
defaultValue = "${ASTRA_DEFAULT_COLOR:-auto}",
3739
paramLabel = "WHEN"
3840
)
3941
private void setAnsi(ColorMode mode) {
4042
switch (mode) {
4143
case always -> this.ansi = Optional.of(Ansi.ON); // auto is handled by Optional.empty() here, not Ansi.AUTO
4244
case never -> this.ansi = Optional.of(Ansi.OFF);
45+
default -> this.ansi = Optional.empty();
4346
}
4447
}
4548

4649
@Option(
4750
names = "--no-color",
51+
defaultValue = "${ASTRA_NO_COLOR:-false}", // no DEFAULT in env var on purpose to better adhere to per-program NO_COLOR semantics
4852
hidden = true
4953
)
5054
private void setAnsi(boolean noColor) {
51-
if (noColor) {
52-
this.ansi = Optional.of(Ansi.OFF);
53-
} else {
54-
throw new OptionValidationException("--no-color", "--no-color must be called without a value (or with 'true'); use --color=never instead");
55-
}
55+
this.ansi = Optional.of((noColor) ? Ansi.OFF : Ansi.ON);
5656
}
5757

5858
@Option(
5959
names = { "--output", "-o" },
6060
completionCandidates = OutputTypeCompletion.class,
61-
defaultValue = "human",
61+
defaultValue = "${ASTRA_DEFAULT_OUTPUT_TYPE:-human}",
6262
description = "One of: ${COMPLETION-CANDIDATES}",
6363
paramLabel = "FORMAT"
6464
)
@@ -69,6 +69,7 @@ private void setAnsi(boolean noColor) {
6969
@Option(
7070
names = { "-V", "--verbose" },
7171
description = "Enable verbose logging output",
72+
defaultValue = "${ASTRA_DEFAULT_VERBOSE:-false}",
7273
showDefaultValue = Visibility.NEVER
7374
)
7475
private boolean verbose;
@@ -77,14 +78,16 @@ private void setAnsi(boolean noColor) {
7778
@Option(
7879
names = { "-q", "--quiet" },
7980
description = "Only output essential information",
81+
defaultValue = "${ASTRA_DEFAULT_QUIET:-false}",
8082
showDefaultValue = Visibility.NEVER
8183
)
8284
private boolean quiet;
8385

8486
@Getter
8587
@Option(
8688
names = { "--spinner" },
87-
description = { "Enable/disable loading spinners", SHOW_CUSTOM_DEFAULT + "enabled if tty" },
89+
description = { "Enable/disable loading spinners", SHOW_CUSTOM_DEFAULT + "enabled if tty and not quiet" },
90+
defaultValue = "${ASTRA_DEFAULT_SPINNER:-" + Option.NULL_VALUE + "}",
8891
negatable = true,
8992
fallbackValue = "true"
9093
)
@@ -100,6 +103,7 @@ private void setAnsi(boolean noColor) {
100103
names = "--dump-logs",
101104
description = { "Write all logs to an optionally specified file", SHOW_CUSTOM_DEFAULT + "${cli.home-folder.path}/logs/<file>.log" },
102105
fallbackValue = "__fallback__",
106+
defaultValue = "${ASTRA_DEFAULT_DUMP_LOGS:-" + Option.NULL_VALUE + "}",
103107
paramLabel = "FILE",
104108
arity = "0..1"
105109
)
@@ -134,6 +138,7 @@ private void setDumpLogs(boolean noDumpLogs) {
134138
@Option(
135139
names = "--no-input",
136140
description = "Don't ask for user input (e.g. confirmation prompts)",
141+
defaultValue = "${ASTRA_DEFAULT_NO_INPUT:-false}",
137142
showDefaultValue = Visibility.NEVER
138143
)
139144
private boolean noInput;

0 commit comments

Comments
 (0)