cknv/beetle — pull request #18 by cknv (2014-09-11 19:21:55+00:00)
Title: Better (click based) cli

I changed some things to allow a click based cli.

There is some weird things going on, or at least untraditional. The cli is not the function defined as the entry point, but rather there is a wrapper around it, that loads plugins before starting the main cli.

As the plugin importing takes place before loading the actual config, plugins are discovered from the path. I am not convinced that it's a good idea, as it removes the option to configure the plugins that does not expose a cli. I'll see if there is something I can do to remedy this.

As it stands the plugins can do two things, expose a cli, and extend a part of beetle.
The cli parts must implement a function and a few decorators, and the extenders will need to provide a `register` function.

The ones with a cli works like this:
```python
from beetle.cli import cli

@cli.command()
def bleh(): # This becomes the name of the sub command.
print('aaaand done!')
```
It is then invoked like so:
```bash
$ beetle test
aaaand done!
```
Admittedly, this does almost nothing in it's own right, so by adding a decorator, the function can get access to the beetle context, which contains the various instances. Which can be used for stuff.
```python
from beetle.cli import cli, context

@cli.command()
@context
def bleh(ctx): # This becomes the name of the sub command.
print(ctx)
print('aaaand done!')
```
Which looks like so:
```bash
$ beetle test

aaaand done!
```
That was one usecase. The other is the ones that extend the beetle parts. That looks like so:
```python
import markdown

def render_markdown(raw_content):
return markdown.markdown(raw_content)

def register(ctx):
markdown_extentions = ['md', 'mkd', 'markdown']
ctx.content_renderer.add_renderer(markdown_extentions, render_markdown)
```
As you can see the register function also takes the context, which should provide everything the plugin could wish for.

The context has the following names: `writer`, `content_renderer`, `config`, `includer`.

So before merging I there is two issues I want to work on.
* Not loading plugins from the path.
* Passing plugin config to the plugins.

Both of these can actually be solved by loading the config before starting the cli, but I think that may be weird idea - time will tell :)