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 cli options to output lookml #89

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

remisalmon
Copy link

@remisalmon remisalmon commented Feb 16, 2024

This should close #88.

> lkml --help
usage: lkml [-h] [-v] [--json | --lookml | -w] file

A blazing fast LookML parser, implemented in pure Python. When invoked from the command line, returns the parsed
output as a JSON string.

positional arguments:
  file           path to the LookML file to parse

options:
  -h, --help     show this help message and exit
  -v, --verbose  increase logging verbosity to debug
  --json         return a JSON string (default)
  --lookml       return a LookML string
  -w, --write    parse and write back to file

@remisalmon remisalmon marked this pull request as ready for review February 16, 2024 22:52
json_string = json.dumps(result, indent=2)
print(json_string)

finally:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileType objects dont work with context managers, this makes sure the file is closed even if they cannot be parsed.

Copy link
Owner

@joshtemple joshtemple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @remisalmon thank you for this PR and I'm sorry it's taken so long for me to review it. My only question is with the --write arg. Can you explain to me what you would use this for?

lkml/__init__.py Outdated
Comment on lines 112 to 118
group.add_argument(
"-w",
"--write",
action="store_true",
default=False,
help="parse and write back to file",
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use case for parsing from a file and writing back to the same file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lkml parser/dumper does a great job at cleaning up lkml files (separating measures from dimensions, correcting the indentation, etc.), the option to write it back to file would allow to use lkml as a auto-formatter in text editors, pre-commits, CI checks, etc. (like running black on .py files).

@remisalmon
Copy link
Author

Hey @remisalmon thank you for this PR and I'm sorry it's taken so long for me to review it. My only question is with the --write arg. Can you explain to me what you would use this for?

Hi @joshtemple I have removed that option, happy to add it back if you feel it belongs here. I replied just above in #89 (comment).

I also added some cli tests to make sure the output (json or lookml) can be parsed back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add cli options to output lookml
2 participants