Skip to content

Commit da76006

Browse files
committed
Feature flag structure results using --structured_results.
Also controlled through STRUCTURED_RESULTS env var. To maintain current behavior, this is false by default.
1 parent b048a25 commit da76006

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ts/kpt-functions/src/run.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ Use this ONLY if the function accepts a ConfigMap.`,
115115
action: 'storeTrue',
116116
help: 'Input and output files are in JSON instead of YAML',
117117
});
118-
parser.addArgument('--log-to-stderr', {
118+
parser.addArgument('--structured_results', {
119119
action: 'storeTrue',
120120
help:
121-
'Confguration issues should be logged to stderr in addition to the ".results" field in the output',
121+
'Emit structured results using ".results" field in stdout. Otherwise, emit unstructured logs to stderr',
122122
});
123123

124124
// Parse args.
@@ -140,8 +140,8 @@ Use this ONLY if the function accepts a ConfigMap.`,
140140
}
141141
functionConfig = parseToConfigMap(parser, functionConfigLiterals);
142142
}
143-
const logToStderr =
144-
process.env.LOG_TO_STDERR || Boolean(args.get('log_to_stderr'));
143+
const structuredResults =
144+
process.env.STRUCTURED_RESULTS || Boolean(args.get('structured_results'));
145145

146146
// Read the input and construct Configs.
147147
const configs = await readConfigs(inputFile, fileFormat, functionConfig);
@@ -151,11 +151,12 @@ Use this ONLY if the function accepts a ConfigMap.`,
151151
await fn(configs);
152152
} catch (err) {
153153
if (err instanceof ConfigError) {
154-
if (logToStderr) {
154+
if (structuredResults) {
155+
// Include Issues as part of function's output.
156+
await writeConfigs(outputFile, configs, fileFormat, err.toResults());
157+
} else {
155158
err.log();
156159
}
157-
// Include Issues as part of function's output.
158-
await writeConfigs(outputFile, configs, fileFormat, err.toResults());
159160
}
160161
throw err;
161162
}

0 commit comments

Comments
 (0)