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

Add \ to escape newlines for multi-line bash commands #561

Merged
merged 2 commits into from
May 30, 2024
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
18 changes: 9 additions & 9 deletions _articles/devops-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ aws-vault exec prod-power -- \
Lists servers in an environment as a table

```bash
aws-vault exec sandbox-power --
aws-vault exec sandbox-power -- \
./bin/ls-servers -e dev
```

Expand Down Expand Up @@ -398,7 +398,7 @@ split up slices that have 10k responses (the limit) to ensure a complete
listing of results.

```bash
aws-vault exec sandbox-power --
aws-vault exec sandbox-power -- \
./bin/query-cloudwatch \
--app idp --env dev --log events.log \
--from 10d --slice 1d --query "$QUERY"
Expand Down Expand Up @@ -450,7 +450,7 @@ Imitates `scp` by copying a file in and out of S3. Use the instance ID to refer
(see [`ls-servers`](#ls-servers) to find them).

```bash
aws-vault exec sandbox-power --
aws-vault exec sandbox-power -- \
./bin/scp-s3 i-abcdef1234:/tmp/file.txt ./file.txt
```

Expand Down Expand Up @@ -481,7 +481,7 @@ Shows usage plus a list of the available SSM session documents for the
application environment.

```bash
aws-vault exec sandbox-power --
aws-vault exec sandbox-power -- \
./bin/ssm-instance -h
```

Expand All @@ -490,7 +490,7 @@ aws-vault exec sandbox-power --
Opens a Rails console (in read-only mode)

```bash
aws-vault exec sandbox-power --
aws-vault exec sandbox-power -- \
./bin/ssm-instance --document rails-c --any asg-dev-idp
```

Expand All @@ -499,7 +499,7 @@ aws-vault exec sandbox-power --
Opens a Rails console (in read-write mode). **Be careful please**.

```bash
aws-vault exec sandbox-power --
aws-vault exec sandbox-power -- \
./bin/ssm-instance --document rails-w --any asg-dev-idp
```

Expand All @@ -508,7 +508,7 @@ aws-vault exec sandbox-power --
Tails and streams cloudwatch logs, specifically `/var/log/cloud-init-output.log`. Useful for checking that a box spins up correctly, such as [during a deploy]({% link _articles/appdev-deploy.md %}#follow-the-process).

```bash
aws-vault exec sandbox-power --
aws-vault exec sandbox-power -- \
./bin/ssm-instance --document tail-cw --any asg-dev-idp
```

Expand All @@ -532,14 +532,14 @@ Shows usage plus a list of the available SSM command documents for the
application environment.

```bash
aws-vault exec sandbox-power --
aws-vault exec sandbox-power -- \
./bin/ssm-command -h
```

Safely restart GoodJob (idp-workers) service.

```bash
aws-vault exec sandbox-power --
aws-vault exec sandbox-power -- \
./bin/ssm-command -d worker-restart -r worker -e dev
```

1 change: 1 addition & 0 deletions spec/html_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
aggregate_failures do
expect(doc).to have_unique_ids
expect(doc).to link_internally_for_handbook_articles
expect(doc).to escape_newlines_in_bash_code_snippets
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/support/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,17 @@
"expected that #{actual.url} would not link to external version of articles in this handbook, but found:\n#{articles.to_a.join("\n")}"
end
end

RSpec::Matchers.define :escape_newlines_in_bash_code_snippets do
match do |actual|
doc = actual

doc.css('.language-bash code').each do |code_elem|
expect(code_elem.inner_text).to_not match(/ --\s*$/)
end
end

failure_message do |actual|
"expected that #{actual.url} would escape newlines with \\ in bash scripts"
end
end
Loading