Skip to content

Commit

Permalink
Merge pull request #555 from msqd/create_cli
Browse files Browse the repository at this point in the history
[FEATURE] CLI: harp create project
  • Loading branch information
hartym authored Oct 28, 2024
2 parents b9c0575 + 131adda commit 7677598
Show file tree
Hide file tree
Showing 26 changed files with 3,278 additions and 573 deletions.
8 changes: 4 additions & 4 deletions docs/_quicktoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
| | |
| Enhance and extend. | Dive in the internals. |
| | |
| - :doc:`/develop/run` | - :doc:`/contribute/introduction` |
| - :doc:`/develop/customize` | - :doc:`/contribute/overview` |
| - :doc:`/develop/extend` | - :doc:`/contribute/dependency-injection` |
| | - :doc:`/contribute/events` |
| - :doc:`/develop/quick-start` | - :doc:`/contribute/introduction` |
| - :doc:`/develop/run` | - :doc:`/contribute/overview` |
| - :doc:`/develop/customize` | - :doc:`/contribute/dependency-injection` |
| - :doc:`/develop/extend` | - :doc:`/contribute/events` |
| | - :doc:`/contribute/applications` |
+--------------------------------------------------------+--------------------------------------------------------+
| :doc:`Reference </reference/index>` |
Expand Down
1 change: 1 addition & 0 deletions docs/changelogs/unreleased.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased
==========

* CLI: adds a cookiecutter based «harp create project» command to bootstrap an empty proxy project.
* Config: «!include» constructor can now be used in all configuration files, not only service definitions.
* Proxy: It is now possible to override the default HttpProxyController with your own on a per-endpoint basis.
* Rules/DX: Better errors on rules failure.
Expand Down
1 change: 1 addition & 0 deletions docs/develop/_toc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.. toctree::
:maxdepth: 2

quick-start
run
customize
extend
44 changes: 44 additions & 0 deletions docs/develop/quick-start.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Quick Start
===========

Install & Bootstrap
:::::::::::::::::::

To start developing with HARP (create your own proxies with custom code), you need a few
things:

**Install HARP to be used as a CLI/dev tool**

.. code:: shell
pipx install 'harp-proxy[dev]'
.. note::

This will install an isolated instance of HARP that we'll mostly use to create new
projects. It is possible to do it without, but this is the easiest.

**Bootstrap a new project**

.. code:: shell
harp create project
Answer a few questions, and you're ready to go!


**Start your project**

.. code:: shell
cd <your-project>
make
This will install the dependencies (in a poetry-managed virtualenv) and start your proxy.

Next Steps
::::::::::

Congratulations, you created your first HARP project! Now you can start tuning it.

.. todo:: pointers
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
harp.commandline.cookiecutters.project
======================================

.. automodule:: harp.commandline.cookiecutters.project
:members:
:undoc-members:
:show-inheritance:

.. inheritance-diagram:: harp.commandline.cookiecutters.project
17 changes: 17 additions & 0 deletions docs/reference/core/harp.commandline.cookiecutters.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
harp.commandline.cookiecutters
==============================

.. automodule:: harp.commandline.cookiecutters
:members:
:undoc-members:
:show-inheritance:

.. inheritance-diagram:: harp.commandline.cookiecutters

Submodules
----------

.. toctree::
:maxdepth: 1

harp.commandline.cookiecutters.project
1 change: 1 addition & 0 deletions docs/reference/core/harp.commandline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Submodules
.. toctree::
:maxdepth: 1

harp.commandline.cookiecutters
harp.commandline.install
harp.commandline.migrations
harp.commandline.options
Expand Down
2 changes: 2 additions & 0 deletions harp/commandline/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from click import Command

from harp.commandline.config import config
from harp.commandline.create import create
from harp.commandline.examples import entrypoint as examples
from harp.commandline.server import server
from harp.settings import HARP_ENV
Expand Down Expand Up @@ -112,6 +113,7 @@ def start(*args, **kwargs):
entrypoint.add_command(server)
entrypoint.add_command(config)
entrypoint.add_command(examples)
entrypoint.add_command(create)

__all__ = [
"entrypoint",
Expand Down
Empty file.
21 changes: 21 additions & 0 deletions harp/commandline/cookiecutters/project/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 {{cookiecutter.author}}

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7 changes: 7 additions & 0 deletions harp/commandline/cookiecutters/project/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# HARP Cookiecutter Template

.. code:: shell
cookiecutter gh:msqd/harp-template
Enjoy :)
Empty file.
8 changes: 8 additions & 0 deletions harp/commandline/cookiecutters/project/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "HARP Project",
"__dir_name": "{{cookiecutter.name | slugify}}",
"__pkg_name": "{{cookiecutter.name | slugify(separator='_')}}",
"author": "Smart Anonymous Harpist",
"create_application": false,
"create_config": true
}
12 changes: 12 additions & 0 deletions harp/commandline/cookiecutters/project/hooks/post_gen_project.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#! /bin/bash

if [ "{{cookiecutter.create_application}}" == "False" ]; then
echo "Removing application folder (create_application == False)."
rm -rf ./{{cookiecutter.__pkg_name}}
fi


if [ "{{cookiecutter.create_config}}" == "False" ]; then
echo "Removing config file (create_config == False)."
rm -f ./config.yml
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
POETRY ?= $(shell which poetry || echo poetry)

.PHONY: start install


start: install
$(POETRY) run harp server{% if cookiecutter.create_application %} --enable {{cookiecutter.__pkg_name}}{% endif %}{% if cookiecutter.create_config %} --file config.yml{% endif %}

install:
$(POETRY) install
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Example: {{cookiecutter.name}}
========={{'=' * cookiecutter.name|length}}

.. code::
# install dependencies and start your proxy
make
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading

0 comments on commit 7677598

Please sign in to comment.