-
Notifications
You must be signed in to change notification settings - Fork 5
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
[Feature] Improve logging and display of information #34
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
80f1694
Add plan command to the CLI
b-per b8c6570
Merge branch 'main' of github.com:dbt-labs/dbt-jobs-as-code into feat…
b-per 737ac78
Move the check of matching env vars outside client
b-per e6b9350
New function to check if a local config of env var exists in Cloud
b-per 63f8663
Create a ChangeSet Class
b-per 5db033b
Build the ChangeSet first and then act on it
b-per b9b0a89
Looks better with capwords
b-per 8c7bb9e
Leverage `rich` for showing tables in CLI
b-per File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from typing import Optional | ||
from pydantic import BaseModel | ||
import string | ||
from rich.table import Table | ||
|
||
|
||
class Change(BaseModel): | ||
"""Describes what a given change is and hot to apply it.""" | ||
|
||
identifier: str | ||
type: str | ||
action: str | ||
sync_function: object | ||
parameters: dict | ||
|
||
def __str__(self): | ||
return f"{self.action.upper()} {string.capwords(self.type)} {self.identifier}" | ||
|
||
def apply(self): | ||
self.sync_function(**self.parameters) | ||
|
||
|
||
class ChangeSet(BaseModel): | ||
"""Store the set of changes to be displayed or applied.""" | ||
|
||
__root__: Optional[list[Change]] = [] | ||
|
||
def __iter__(self): | ||
return iter(self.__root__) | ||
|
||
def append(self, change: Change): | ||
self.__root__.append(change) | ||
|
||
def __str__(self): | ||
list_str = [str(change) for change in self.__root__] | ||
return "\n".join(list_str) | ||
|
||
def to_table(self) -> Table: | ||
"""Return a table representation of the changeset.""" | ||
|
||
table = Table(title="Changes detected") | ||
|
||
table.add_column("Action", style="cyan", no_wrap=True) | ||
table.add_column("Type", style="magenta") | ||
table.add_column("ID", style="green") | ||
|
||
for change in self.__root__: | ||
table.add_row( | ||
change.action.upper(), string.capwords(change.type), change.identifier | ||
) | ||
|
||
return table | ||
|
||
def __len__(self): | ||
return len(self.__root__) | ||
|
||
def apply(self): | ||
for change in self.__root__: | ||
change.apply() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is beautiful! Excellent use of
rich
.