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

Render to stdout by default #5

Merged
merged 1 commit into from
Oct 31, 2021
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
2 changes: 1 addition & 1 deletion docs/searchindex.js

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

8 changes: 4 additions & 4 deletions docs/stack_diff.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,23 +208,23 @@ <h1>Python usage<a class="headerlink" href="#python-usage" title="Permalink to t
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="stackdiff.StackDiff.render_changes">
<span class="sig-name descname"><span class="pre">render_changes</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">writer</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">IO</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#stackdiff.StackDiff.render_changes" title="Permalink to this definition">¶</a></dt>
<span class="sig-name descname"><span class="pre">render_changes</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">writer</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">IO</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#stackdiff.StackDiff.render_changes" title="Permalink to this definition">¶</a></dt>
<dd><p>Renders a visualisation of the changes that CloudFormation would apply
if the change set was executed.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>writer</strong> – Writer</p>
<dd class="field-odd"><p><strong>writer</strong> – Writer (defaults to <code class="docutils literal notranslate"><span class="pre">stdout</span></code>)</p>
</dd>
</dl>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="stackdiff.StackDiff.render_differences">
<span class="sig-name descname"><span class="pre">render_differences</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">writer</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">IO</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#stackdiff.StackDiff.render_differences" title="Permalink to this definition">¶</a></dt>
<span class="sig-name descname"><span class="pre">render_differences</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">writer</span></span><span class="p"><span class="pre">:</span></span> <span class="n"><span class="pre">Optional</span><span class="p"><span class="pre">[</span></span><span class="pre">IO</span><span class="p"><span class="pre">[</span></span><span class="pre">str</span><span class="p"><span class="pre">]</span></span><span class="p"><span class="pre">]</span></span></span> <span class="o"><span class="pre">=</span></span> <span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#stackdiff.StackDiff.render_differences" title="Permalink to this definition">¶</a></dt>
<dd><p>Renders a visualisation of the differences between the stack’s current
template and the change set’s proposed template.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>writer</strong> – Writer</p>
<dd class="field-odd"><p><strong>writer</strong> – Writer (defaults to <code class="docutils literal notranslate"><span class="pre">stdout</span></code>)</p>
</dd>
</dl>
</dd></dl>
Expand Down
13 changes: 7 additions & 6 deletions stackdiff/stack_diff.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from functools import cached_property
from sys import stdout
from typing import IO, Optional

from ansiscape import green, heavy, yellow
Expand Down Expand Up @@ -57,13 +58,13 @@ def change_template(self) -> str:
)
return response.get("TemplateBody", "")

def render_changes(self, writer: IO[str]) -> None:
def render_changes(self, writer: Optional[IO[str]] = None) -> None:
"""
Renders a visualisation of the changes that CloudFormation would apply
if the change set was executed.

Arguments:
writer: Writer
writer: Writer (defaults to ``stdout``)
"""

response = self.client.describe_change_set(
Expand Down Expand Up @@ -109,18 +110,18 @@ def render_changes(self, writer: IO[str]) -> None:
)

t = tabulate(rows, headers="firstrow", tablefmt="plain")
writer.write(t + "\n")
(writer or stdout).write(t + "\n")

def render_differences(self, writer: IO[str]) -> None:
def render_differences(self, writer: Optional[IO[str]] = None) -> None:
"""
Renders a visualisation of the differences between the stack's current
template and the change set's proposed template.

Arguments:
writer: Writer
writer: Writer (defaults to ``stdout``)
"""

render(self.stack_template, self.change_template, writer)
render(self.stack_template, self.change_template, writer or stdout)

@cached_property
def stack_template(self) -> str:
Expand Down