Parcourir la source

feat(scripts): provide `diagrams` CLI

This change addresses https://github.com/mingrammer/diagrams/issues/369
while providing a simple CLI entry point which can be used outside the
virtual environment of the installed package.

This works well with for example with [pipx](https://pipxproject.github.io/pipx/).
pull/524/head
Cedrik Neumann il y a 3 ans
Parent
révision
dbab810dee
Aucune clé connue n'a été trouvée dans la base pour cette signature ID de la clé GPG: 9D5C383EB946A92B
3 fichiers modifiés avec 52 ajouts et 0 suppressions
  1. +31
    -0
      diagrams/cli.py
  2. +18
    -0
      docs/getting-started/installation.md
  3. +3
    -0
      pyproject.toml

+ 31
- 0
diagrams/cli.py Voir le fichier

@@ -0,0 +1,31 @@
import argparse
import sys


def run() -> int:
parser = argparse.ArgumentParser(
description="Run diagrams code files in a diagrams environment.",
)
parser.add_argument(
"paths",
metavar="path",
type=str,
nargs="+",
help="a Python file containing diagrams code",
)
args = parser.parse_args()

for path in args.paths:
print(path)
with open(path) as f:
exec(f.read())

return 0


def main():
sys.exit(run())


if __name__ == "__main__":
main()

+ 18
- 0
docs/getting-started/installation.md Voir le fichier

@@ -18,6 +18,9 @@ $ pipenv install diagrams

# using poetry
$ poetry add diagrams

# using pipx
$ pipx install diagrams
```

## Quick Start
@@ -43,6 +46,21 @@ $ python diagram.py

It will be saved as `web_service.png` on your working directory.

### CLI

If the `diagrams` CLI has been installed system wide (i.e. with [pipx](https://pipxproject.github.io/pipx/)),
then the preceding command is equivalent to this.

```shell
$ diagrams diagram.py
```

Furthermore you can execute multiple files at once

```shell
$ diagrams diagram1.py diagram2.py
```

## Next

See more [Examples](/docs/getting-started/examples) or see [Guides](/docs/guides/diagram) page for more details.

+ 3
- 0
pyproject.toml Voir le fichier

@@ -9,6 +9,9 @@ homepage = "https://diagrams.mingrammer.com"
repository = "https://github.com/mingrammer/diagrams"
include = ["resources/**/*"]

[tool.poetry.scripts]
diagrams="diagrams.cli:main"

[tool.poetry.dependencies]
python = "^3.6"
graphviz = ">=0.13.2,<0.17.0"


Chargement…
Annuler
Enregistrer