Skip to content

Commit 4591103

Browse files
committed
feat: removed newlines by default in secrets env command
1 parent 9ec49bf commit 4591103

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/secrets/CommandEnv.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class CommandEnv extends CommandPolykey {
2222
this.addOption(binOptions.envFormat);
2323
this.addOption(binOptions.envInvalid);
2424
this.addOption(binOptions.envDuplicate);
25+
this.addOption(binOptions.preserveNewline);
2526
this.argument(
2627
'<args...>',
2728
'command and arguments formatted as [envPaths...][-- cmd [cmdArgs...]]',
@@ -160,7 +161,12 @@ class CommandEnv extends CommandPolykey {
160161
utils.never();
161162
}
162163
}
163-
envp[newName] = secretContent;
164+
// Trim the single trailing newline if it exists
165+
if (secretContent.endsWith('\n')) {
166+
envp[newName] = secretContent.slice(0, -1);
167+
} else {
168+
envp[newName] = secretContent;
169+
}
164170
envpPath[newName] = {
165171
nameOrId,
166172
secretName,
@@ -175,7 +181,7 @@ class CommandEnv extends CommandPolykey {
175181
// Here we want to switch between the different usages
176182
const platform = os.platform();
177183
if (cmd != null) {
178-
// If a cmd is| provided then we default to exec it
184+
// If a cmd is provided then we default to exec it
179185
switch (platform) {
180186
case 'linux':
181187
// Fallthrough

src/utils/options.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,13 @@ const parents = new commander.Option(
318318
'If enabled, create all parent directories as well. If the directories exist, do nothing.',
319319
).default(false);
320320

321+
const preserveNewline = new commander.Option(
322+
'--preserve-newline <path>',
323+
'Preserve the last trailing newline for the secret content',
324+
)
325+
.argParser(binParsers.parseSecretPathEnv)
326+
.default(undefined);
327+
321328
export {
322329
nodePath,
323330
format,
@@ -361,4 +368,5 @@ export {
361368
order,
362369
recursive,
363370
parents,
371+
preserveNewline,
364372
};

0 commit comments

Comments
 (0)