Skip to content

bendhouseart/nuki-tmp

nukikata

Japanese for cookiecutter: クッキーの抜き型 - Kukkī no nukikata | Direct translation: To shape or mold

pypi python Build Status codecov

Fork of

Cookiecutter

Cookiecutter is the worlds most popular code scaffolding tool with over 4 thousand open source cookiecutters available today. This fork includes many additional features including:

  • Loops
  • Conditionals
  • Plugins

Inspired by Ansible's syntax, this project aims to be a flexible declarative CLI that is easy to write operators for to extend functionality. It was originally built to extend cookiecutter to include conditionals and loops in the configuration file format. We are now looking at it as an upstream declarative CLI sandbox to prove out patterns that can either be integrated back into cookiecutter or fit a variety of other use cases.

Quick Demo

pip3 install nukikata
nukikata https://github.com/insight-infrastructure/nukikata-demos

Note: If you experience installation errors try pip3 install nukikata --no-binary :all:.

Features

All cookiecutter features are supported in addition to loops, conditionals, and plugins. These features are only available to supplied dictionary objects with a type key to trigger the associated operator. Loops and conditionals are triggered by rendering jinja expressions per the example below. Other cookiecutters can be called from a single nukikata to knit together modularized components.

nuki.yaml

---
name:
  type: input # Input box
  message: What is your name?

colors:
  type: checkbox # Multi selector - returns a list
  message: What are your favorite colors?
  choices:
    - blue
    - green
    - grey

outcome:
  type: select # Single selector - returns a string
  message: What is the airspeed velocity of an unladen swallow??
  choices:
    - flung-off-bridge: I donno
    - walk-across-bridge: What do you mean? African or European swallow?

bad_outcome:
  type: print
  statement: Wrong answer {{ nuki.name }}...
  when: "{{ nuki.outcome == 'flung-off-bridge' }}"

color_essays:
  type: input
  message: Please tell me how much you like the color {{nuki.item}}?
  default: Oh color {{nuki.item}}, you are so frickin cool... # loops over nuki.colors
  loop: "{{ nuki.colors }}"
  when: "{{ nuki.colors|length > 1 }}"

democmd:
  type: command
  command: pwd

dump_yaml:
  type: yaml
  contents: "{{ nuki }}"
  path: "{{ calling_directory }}/output.yaml"

Here the jinja default context key goes to the name of file - ie {{ nuki.<> }} but can be customized if needed. We can also see the use of a special variable

Prompts are enhanced by extending the functionality from PyInquirer as a set of operators as noted by the types input, list, and checkbox. Writing new operators is super simple as seen in the print operator:

cookiecuttuer/operators/print.py

class PrintOperator(BaseOperator):
    type = 'print'
    def __init__(self, *args, **kwargs):
        super(PrintOperator, self).__init__(*args, **kwargs)

    def _execute(self):
        print(self.operator_dict['statement'])
        return self.operator_dict['statement']

New operator PRs welcome. We're aiming to interface with various APIs and popular libraries to create simple ways to conditionally call and loop through popular methods.

Operators

Over 35 different operators are currently available with more coming down the line. To understand how to use them, please refer to the API Docs.

The main type of operators are derivations of PyInquirer which greatly enhanced the capabilities of the original cookiecutter due to the ability to use multi-select inputs that return lists. Please inspect the PyInquirer API docs to understand the interface. All features are supported except for validation and filter which is not supported and when which is implemented in jinja.

To see a number of good examples of the types of interfaces available for each operator, consider downloading the demo above and walking through the syntax.

Note to Users and Developers

This is a very early WIP but has long term ambitions of being a sort of swiss army knife for management of configuration files and boilerplate. Please consider contributing or leaving your comments in the issues section on where you see this project going and what features you would like added.

This project intends on being an edge release of cookiecutter and would not have been possible were it not for the orginal maintainers of that repository. Development in this repository is meant to be a proving ground for features that could be implemented and merged into the original cookiecutter repository. Please consider supporting both projects.

Windows will not have first class support. Several operators are built for POSIX systems. PRs welcome to build in full support. Basic features like PyInquirer style prompts are supported.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages