Skip to content

Commit

Permalink
Merge pull request #41 from moul/dev/moul/graph-human
Browse files Browse the repository at this point in the history
feat: add Graph.Human() helper
  • Loading branch information
moul authored Sep 25, 2019
2 parents 20ea6b2 + 19b94c4 commit 97b8bda
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 20 deletions.
8 changes: 5 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
version: 2.1

orbs:
moul: moul/build@1.8.3
moul: moul/build@1.12.1 # https://github.com/moul/build

workflows:
main:
jobs:
- moul/golang-build:
gopkg: moul.io/graphman
- moul/golang-build:
gopkg: moul.io/graphman
tag: '1.12'
- moul/golang-build:
gopkg: moul.io/graphman
tag: '1.11'
- moul/docker-build:
image: moul/graphman
- moul/docker-build
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# build
FROM golang:1.12-alpine as builder
FROM golang:1.13-alpine as builder
RUN apk add --no-cache git gcc musl-dev make
ENV GO111MODULE=on
WORKDIR /go/src/moul.io/graphman
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GOBINS ?= ./cmd/pertify

all: test install

-include rules.mk
include rules.mk

web/pertify/examples.js: $(wildcard ./examples/pertify/*.yml)
cd examples/pertify; fs-bundler --format=js --callback=examples *.yml > ../../$@
Expand Down Expand Up @@ -47,3 +47,4 @@ netlify: _netlify-deps lambda-build
_netlify_deps:
cd; go get moul.io/fs-bundler
cd cmd/pertify; $(GO) get -v .
cd lambda; $(GO) get -v .
2 changes: 1 addition & 1 deletion cmd/pertify/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module moul.io/cmd/pertify

go 1.12
go 1.13

require (
github.com/pkg/errors v0.8.1
Expand Down
2 changes: 1 addition & 1 deletion examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module moul.io/graphman/examples

go 1.12
go 1.13

require (
moul.io/graphman v1.5.0
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module moul.io/graphman

go 1.12
go 1.13

require (
github.com/kr/pretty v0.1.0 // indirect
Expand Down
12 changes: 12 additions & 0 deletions graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,18 @@ func (g *Graph) String() string {
return fmt.Sprintf("{%s}", strings.Join(elems, ","))
}

// Human returns a diff-friendly and human-readable representation of the vertices and edges
func (g *Graph) Human() string {
out := ""
for _, vertex := range g.Vertices() {
out += fmt.Sprintf("* %s\n", vertex.ID())
for _, edge := range vertex.Edges() {
out += fmt.Sprintf(" * %s\n", edge.String())
}
}
return out
}

//
// Graphs
//
Expand Down
59 changes: 59 additions & 0 deletions graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,62 @@ func ExampleGraph_big() {
// {(0,1),(1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,8),(8,9),(9,10),(10,11),(11,12),(12,13),(13,14),(14,15),(15,16),(16,17),(17,18),(18,19),(19,20),(20,21),(21,22),(22,23),(23,24),(24,25),(25,26),(26,27),(27,28),(28,29),(29,30),(30,31),(31,32),(32,33),(33,34),(34,35),(35,36),(36,37),(37,38),(38,39),(39,40),(40,41),(41,42),(42,43),(43,44),(44,45),(45,46),(46,47),(47,48),(48,49),(49,50),(50,51),(51,52),(52,53),(53,54),(54,55),(55,56),(56,57),(57,58),(58,59),(59,60),(60,61),(61,62),(62,63),(63,64),(64,65),(65,66),(66,67),(67,68),(68,69),(69,70),(70,71),(71,72),(72,73),(73,74),(74,75),(75,76),(76,77),(77,78),(78,79),(79,80),(80,81),(81,82),(82,83),(83,84),(84,85),(85,86),(86,87),(87,88),(88,89),(89,90),(90,91),(91,92),(92,93),(93,94),(94,95),(95,96),(96,97),(97,98),(98,99),(99,100)}
// 0-100: (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100) 100
}

func ExampleGraph_Human() {
graph := New()
graph.AddEdge("G", "H")
graph.AddEdge("A", "B")
graph.AddEdge("A", "B")
graph.AddEdge("F", "H")
graph.AddEdge("A", "C")
graph.AddEdge("B", "E")
graph.AddEdge("B", "G")
graph.AddEdge("C", "F")
graph.AddEdge("D", "H")
graph.AddEdge("A", "D")
graph.AddEdge("E", "G")
graph.AddEdge("E", "H")
graph.AddEdge("F", "G")
graph.AddVertex("I")
graph.AddVertex("J")
graph.AddVertex("K")
fmt.Println(graph.Human())
// Output:
// * A
// * (A,B)
// * (A,B)
// * (A,C)
// * (A,D)
// * B
// * (A,B)
// * (A,B)
// * (B,E)
// * (B,G)
// * C
// * (A,C)
// * (C,F)
// * D
// * (A,D)
// * (D,H)
// * E
// * (B,E)
// * (E,G)
// * (E,H)
// * F
// * (C,F)
// * (F,H)
// * (F,G)
// * G
// * (B,G)
// * (E,G)
// * (F,G)
// * (G,H)
// * H
// * (G,H)
// * (F,H)
// * (D,H)
// * (E,H)
// * I
// * J
// * K
}
6 changes: 3 additions & 3 deletions lambda/go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module moul.io/graphman/lambda

go 1.12
go 1.13

require (
github.com/aws/aws-lambda-go v1.11.1
github.com/aws/aws-lambda-go v1.13.2
github.com/pkg/errors v0.8.1
gopkg.in/yaml.v3 v3.0.0-20190709130402-674ba3eaed22
gopkg.in/yaml.v3 v3.0.0-20190924164351-c8b7dadae555
moul.io/graphman v1.5.0
moul.io/graphman/viz v1.5.0
)
Expand Down
19 changes: 12 additions & 7 deletions lambda/go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/awalterschulze/gographviz v0.0.0-20190522210029-fa59802746ab h1:+cdNqtOJWjvepyhxy23G7z7vmpYCoC65AP0nqi1f53s=
github.com/awalterschulze/gographviz v0.0.0-20190522210029-fa59802746ab/go.mod h1:GEV5wmg4YquNw7v1kkyoX9etIk8yVmXj+AkDHuuETHs=
github.com/aws/aws-lambda-go v1.11.1 h1:wuOnhS5aqzPOWns71FO35PtbtBKHr4MYsPVt5qXLSfI=
github.com/aws/aws-lambda-go v1.11.1/go.mod h1:Rr2SMTLeSMKgD45uep9V/NP8tnbCcySgu04cx0k/6cw=
github.com/aws/aws-lambda-go v1.13.2 h1:8lYuRVn6rESoUNZXdbCmtGB4bBk4vcVYojiHjE4mMrM=
github.com/aws/aws-lambda-go v1.13.2/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
Expand All @@ -13,14 +15,17 @@ github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.2.1 h1:52QO5WkIUcHGIR7EnGagH88x1bUzqGXTC5/1bDTUQ7U=
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/urfave/cli.v1 v1.20.0/go.mod h1:vuBzUtMdQeixQj8LVd+/98pzhxNGQoyuPBlsXHOQNO0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20190709130402-674ba3eaed22 h1:0efs3hwEZhFKsCoP8l6dDB1AZWMgnEl3yWXWRZTOaEA=
gopkg.in/yaml.v3 v3.0.0-20190709130402-674ba3eaed22/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20190924164351-c8b7dadae555 h1:4Yrwvx9yMvZx+vK3wdX7aX2UCNZJJn0TDc+BNOJTE00=
gopkg.in/yaml.v3 v3.0.0-20190924164351-c8b7dadae555/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
20 changes: 19 additions & 1 deletion rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ endif
endif
ifdef GOPKG
GO ?= go
GOPATH ?= $(HOME)/go

ifdef GOBINS
.PHONY: go.install
Expand Down Expand Up @@ -114,11 +115,20 @@ go.bumpdeps:
$(GO) get -u ./...; \
); done

.PHONY: go.bump-deps
go.fmt:
if ! command -v goimports &>/dev/null; then GO111MODULE=off go get golang.org/x/tools/cmd/goimports; fi
@set -e; for dir in `find . -type f -name "go.mod" | sed 's@/[^/]*$$@@' | sort | uniq`; do ( set -xe; \
cd $$dir; \
goimports -w . \
); done

BUILD_STEPS += go.build
BUMPDEPS_STEPS += go.bumpdeps
TIDY_STEPS += go.tidy
LINT_STEPS += go.lint
UNITTEST_STEPS += go.unittest
FMT_STEPS += go.fmt
endif

##
Expand Down Expand Up @@ -153,6 +163,7 @@ DOCKER_IMAGE = $(notdir $(PWD))
endif
endif
ifdef DOCKER_IMAGE
ifneq ($(DOCKER_IMAGE),none)
.PHONY: docker.build
docker.build:
docker build \
Expand All @@ -163,6 +174,7 @@ docker.build:

BUILD_STEPS += docker.build
endif
endif

##
## Common
Expand Down Expand Up @@ -190,7 +202,7 @@ endif

ifdef LINT_STEPS
.PHONY: lint
lint: $(LINT_STEPS)
lint: $(FMT_STEPS) $(LINT_STEPS)
endif

ifdef TIDY_STEPS
Expand All @@ -213,6 +225,11 @@ ifdef BUMPDEPS_STEPS
bumpdeps: $(BUMPDEPS_STEPS)
endif

ifdef FMT_STEPS
.PHONY: fmt
fmt: $(FMT_STEPS)
endif

ifdef GENERATE_STEPS
.PHONY: generate
generate: $(GENERATE_STEPS)
Expand All @@ -223,6 +240,7 @@ help:
@echo "General commands:"
@[ "$(BUILD_STEPS)" != "" ] && echo " build" || true
@[ "$(BUMPDEPS_STEPS)" != "" ] && echo " bumpdeps" || true
@[ "$(FMT_STEPS)" != "" ] && echo " fmt" || true
@[ "$(GENERATE_STEPS)" != "" ] && echo " generate" || true
@[ "$(INSTALL_STEPS)" != "" ] && echo " install" || true
@[ "$(LINT_STEPS)" != "" ] && echo " lint" || true
Expand Down
2 changes: 1 addition & 1 deletion viz/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module moul.io/graphman/viz

go 1.12
go 1.13

require (
github.com/awalterschulze/gographviz v0.0.0-20190522210029-fa59802746ab
Expand Down

0 comments on commit 97b8bda

Please sign in to comment.