Skip to content

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.

@remisalmon remisalmon requested a review from joshtemple July 24, 2024 22:53
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