Within Charm Tools,
charm create command makes it easy to create a charm that follows
the recommended structure and includes all the right pieces. While the
option is discussed in the documentation, I wanted to take a moment to call
it out specifically, as well as briefly talk about the new default template.
The purpose of the
-t option is to create a new charm using a language-specific
template. This makes it very easy to start a new charm in your favorite language.
For example, to create a new Bash charm, simply run the following:
$ charm create -t bash my_charm
If you prefer to write your charms in Python (which is recommended, and has been the default for some time now):
$ charm create -t python my_charm
New templates will continue to be added for more languages and style, such as the recently added Ansible charm template, and of course submissions for your favorite language are much appreciated.
The New Default Charm Template
With the newest version of Charm Tools, the default template is not only Python-based and includes the Charm Helpers library, but it also leverages some new features from Charm Helpers to make managing the charm lifecycle much easier.
For example, the following block from the refactored Chamilo charm encapsulates all of the decision-making logic that was previously spread between several different hooks, in a single, relatively easy to understand block:
This is a new way of thinking about the decisions that your charm has to make to know if and when it is ready to configure and start its software, but the template sets your new charm up with all of the bits in place to use this new pattern, and commented placeholders and examples to make it easy to see what to add where. The new template also includes boilerplate test cases to encourage proper testing of your charm.
And, if you want a more bare-bones Python charm that still includes Charm Helpers and all the proper files in the right places, it's as easy as:
$ charm create -t python-basic