Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

append LF #151

Merged
merged 3 commits into from
Aug 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed

* Append LF to `known_hosts` / `config`.

### Fixed

* Typo (thanks [@psbss](https://github.com/psbss))
Expand Down
17 changes: 12 additions & 5 deletions lib/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/main.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function main(): void
},
{
name: "known_hosts",
contents: prependLf(core.getInput("known_hosts", {
contents: insertLf(core.getInput("known_hosts", {
required: true,
})),
options: {
Expand All @@ -40,7 +40,7 @@ function main(): void
},
{
name: "config",
contents: prependLf(core.getInput("config")),
contents: insertLf(core.getInput("config")),
options: {
mode: 0o644,
flag: "a",
Expand Down Expand Up @@ -104,19 +104,29 @@ function getHomeEnv(): string
}

/**
* prepend LF to value if not empty
* prepend/append LF to value if not empty
* @param value the value to prepend LF
* @returns prepended value
*/
function prependLf(value: string): string
function insertLf(value: string): string
{
let affectedValue = value;

if(value.length === 0)
{
// do nothing if empty
return "";
}
if(!affectedValue.startsWith("\n"))
{
affectedValue = `\n${affectedValue}`;
}
if(!affectedValue.endsWith("\n"))
{
affectedValue = `${affectedValue}\n`;
}

return `\n${value}`;
return affectedValue;
}

main();