Skip to content

Conversation

aluttik
Copy link
Contributor

@aluttik aluttik commented Jan 23, 2018

The readme will still need more work and it wouldn't hurt to add a few more tests for this, but the basics are all there.

usage: crossplane build [-h] [-v] [-d PATH] [-f] [-i NUM | -t] [--no-headers]
                        [--stdout]
                        filename

builds an nginx config from a json payload

positional arguments:
  filename              the file with the config payload

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         verbose output
  -d PATH, --dir PATH   the base directory to build in
  -f, --force           overwrite existing files
  -i NUM, --indent NUM  number of spaces to indent output
  -t, --tabs            indent with tabs instead of spaces
  --no-headers          do not write header to configs
  --stdout              write configs to stdout instead

Copy link
Contributor

@dedm dedm left a comment

Choose a reason for hiding this comment

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

I would also like to see a test when we

  1. parse existing config (A) to a JSON
  2. create a config (B) from JSON
  3. compare (A) and (B)


if header:
output = (
'# This config was built from JSON using crossplane.\n'
Copy link
Contributor

Choose a reason for hiding this comment

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

NGINX crossplane (branding!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha okay

def build(payload, indent=4, tabs=False):
padding = '\t' if tabs else ' ' * indent

def _build_lines(objs, depth):
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a really clever use of a generator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks :)

@aluttik aluttik merged commit 56db904 into master Jan 23, 2018
@aluttik aluttik deleted the add-config-builder branch January 23, 2018 23:12
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.

3 participants