Browse Source

cli yamily-dot: added --comment arg

Fabian Peter Hammerle 4 years ago
parent
commit
9b749b0f98
3 changed files with 26 additions and 1 deletions
  1. 2 1
      CHANGELOG.md
  2. 19 0
      tests/cli/_dot_test.py
  3. 5 0
      yamily/_cli.py

+ 2 - 1
CHANGELOG.md

@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ## Unreleased
 ### Added
-- `Person.death_date`
+- api/yaml: `Person.death_date`
+- cli: `yamily-dot --comment 'some comment'`
 
 ## 0.1.0 - 2020-01-02

+ 19 - 0
tests/cli/_dot_test.py

@@ -27,3 +27,22 @@ def test__dot_recurse_dir(capsys):
     out, err = capsys.readouterr()
     assert not err
     assert out == pathlib.Path("persons").joinpath("digraph.dot").read_text()
+
+
+@patch("sys.argv", ["", "--comment", "some text", "persons/erika-mustermann.yml"])
+def test__dot_comment(capsys):
+    _dot()
+    out, err = capsys.readouterr()
+    assert not err
+    expected_out = r"""digraph yamily {
+	subgraph "cluster_erika-mustermann" {
+		rank=same style=invisible
+		"erika-mustermann" [label="Erika Mustermann\n*1957-08-12" shape=box]
+	}
+	subgraph cluster_comment {
+		style=invisible
+		comment [label="some text" shape=none]
+	}
+}
+"""
+    assert out == expected_out

+ 5 - 0
yamily/_cli.py

@@ -66,10 +66,15 @@ def _dot() -> None:
     argparser.add_argument(
         "paths", nargs="+", metavar="path", help="path to yamily .yml file or folder"
     )
+    argparser.add_argument("--comment", dest="comment_text")
     args = argparser.parse_args()
     collection = yamily.PersonCollection()
     for path in args.paths:
         for person in _read(pathlib.Path(path)):
             collection.add_person(person)
     graph = yamily._graphviz.digraph(collection)  # pylint: disable=protected-access
+    if args.comment_text is not None:
+        with graph.subgraph(name="cluster_comment") as comment:
+            comment.attr(style="invisible")
+            comment.node("comment", label=args.comment_text, shape="none")
     print(graph.source)