Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create new cli #93

Merged
merged 3 commits into from
Oct 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.5.0-dev

* Create `new` cli command for creating new `blogs`, `posts`, and `plugins` #93 0.5.0.dev16
* Remove unused function clif that was the original entrypoint #81 0.5.0.dev8
* Allow template variables to be used in head config #88 0.5.0.dev12
* Expose `markata.__version__` to templates as `__version__` #89 0.5.0.dev13
Expand All @@ -18,6 +19,34 @@
* DeepMerge `config_overrides` with config in post render methods #91 0.5.0.dev13
* Create ipython extension to automatically load markata #79 0.5.0.dev15

### `new` cli command

``` bash
# create a new blog template
markata new blog

# create a new blog post
markata new post

# create a new plugin
markata new plugin

markata new --help

Usage: markata new [OPTIONS] COMMAND [ARGS]...

create new things from templates

╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ blog Create a new blog from using the template from https://github.com/WaylonWalker/markata-blog-starter. │
│ plugin Create a new plugin using the template at https://github.com/WaylonWalker/markata-plugin-template. │
│ post Create new blog post in the pages directory from the template at https://github.com/WaylonWalker/markata-post-template. │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```

### sluggify paths

`python-sluggify` was implemented to ensure good urls are in place despite the
Expand Down
52 changes: 51 additions & 1 deletion markata/plugins/base_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import sys
import traceback
import warnings
from pathlib import Path
from typing import TYPE_CHECKING, Callable, Optional

import typer
Expand Down Expand Up @@ -81,6 +82,56 @@ def cli(app: typer.Typer, markata: "Markata") -> None:
Markata hook to implement base cli commands.
"""

new_app = typer.Typer()
app.add_typer(new_app)

@new_app.callback()
def new():
"create new things from templates"

@new_app.command()
def blog(
directory: Path = typer.Argument(
..., help="The directory to create the blog in."
)
) -> None:
"""
Create a new blog from using the template from
https://github.com/WaylonWalker/markata-blog-starter.
"""

from copier import run_auto

typer.echo(f"creating a new project in {directory.absolute()}")
url = markata.config.get("starters", {}).get('blog', "git+https://github.com/WaylonWalker/markata-blog-starter")
run_auto(url, directory)

@new_app.command()
def post() -> None:
"""
Create new blog post in the pages directory from the template at
https://github.com/WaylonWalker/markata-post-template.
"""

print("create a new post")
from copier import run_auto

typer.echo(f"creating a new post in {Path().absolute()}/posts")
url = markata.config.get('starters', {}).get('post', "git+https://github.com/WaylonWalker/markata-post-template")
run_auto(url, Path("."))

@new_app.command()
def plugin() -> None:
"""
Create a new plugin using the template at
https://github.com/WaylonWalker/markata-plugin-template.
"""
from copier import run_auto

typer.echo(f"creating a new plugin in {Path().absolute()}/<python-package-name>/plugins")
url = markata.config.get('starters', {}).get('post', "git+https://github.com/WaylonWalker/markata-plugin-template")
run_auto(url, Path("."))

@app.command()
def build(
pretty: bool = True,
Expand All @@ -89,7 +140,6 @@ def build(
"--quiet",
"-q",
),
# to_dict: bool = False,
verbose: bool = typer.Option(
False,
"--verbose",
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies = [
"beautifulsoup4",
"anyconfig",
"checksumdir",
"cookiecutter",
"copier",
"deepmerge",
"diskcache",
"feedgen",
Expand Down