Skip to content

Commit cc083dd

Browse files
authored
View dependencies (#60)
# Changes ## Primary change ## Supporting changes - Add `dependency-graph` target to `src/go` - Add related graphviz tool and documentation ## Future work Break up the overly-modular CLI and use the idomatic `cobra-cli` structure instead.
1 parent 48561ec commit cc083dd

File tree

5 files changed

+65
-48
lines changed

5 files changed

+65
-48
lines changed

doc/task-automation.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ Manuals are written in Markdown. This project uses Pandoc to generate `groff` m
2222
Markdown manuals in `man/groff/` and `man/markdown/`, respectively. The Markdown manuals are
2323
included in the repository, for ease of reading on GitHub.
2424

25+
### Targets in `src/go/`
26+
27+
There are a number of tasks to build the Golang code and to assist with development. Try `make
28+
help` to see what is available.
29+
2530
### Targets in `src/zsh`
2631

2732
There isn't anything to build, since the programs are all scripts. However, there are conventional

etc/macos/Brewfile.developer

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
tap "homebrew/bundle"
2+
brew "graphviz"
23
brew "fswatch"
34
brew "pandoc"
45
brew "pre-commit"

src/go/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ _marmot
33
marmot
44
marmot.exe
55

6+
# Dependencies
7+
dependencies.png
8+
69
# Testing
710
coverage.html
811
coverage.out

src/go/Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ all: $(executable) $(autocomplete) #> Build all sources
103103

104104
.PHONY: clean
105105
clean: #> Remove local build files
106-
$(RM) $(autocomplete) coverage.html coverage.out coverage-gaps.out $(executable)
106+
$(RM) $(autocomplete) coverage.html coverage.out coverage-gaps.out dependencies.png $(executable)
107107

108108
.PHONY: install
109109
install: $(executable) | $(bindir) $(datadirpkg) $(libexecdirpkg) #> Install program
@@ -145,6 +145,7 @@ install-autocomplete-zsh: $(autocomplete) | $(datadirzshfn) #> Install autocompl
145145

146146
.PHONY: install-tools
147147
install-tools: #> Install Go development tools
148+
go install github.com/kisielk/godepgraph@latest
148149
go install github.com/go-delve/delve/cmd/dlv@latest
149150
go install github.com/gregoryv/uncover/cmd/uncover@latest
150151
go install github.com/onsi/ginkgo/v2/ginkgo
@@ -162,6 +163,10 @@ test-watch: #> Run tests in watch mode
162163

163164
#. GO TARGETS
164165

166+
.PHONY: dependency-graph
167+
dependency-graph: dependencies.png #> Make a dependency graph of packages in this module
168+
@:
169+
165170
.PHONY: format
166171
format: #> Format sources
167172
gofumpt -l -w .
@@ -191,5 +196,9 @@ coverage.out: $(sources)
191196
coverage-gaps.out: coverage.out
192197
uncover $< > $@
193198

199+
dependencies.png: $(sources)
200+
godepgraph -s github.com/kkrull/marmot | dot -Tpng -o $@
201+
@echo "Wrote $@"
202+
194203
$(executable): $(sources)
195204
go build -o $(executable) $(source_main)

src/go/cmd/root/cli_config_parser.go

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,7 @@ func (parser rootConfigParser) Parse(
3939
} else if metaRepoPath, pathErr := metaRepoFlag.GetString(flags); pathErr != nil {
4040
return nil, pathErr
4141
} else {
42-
metaRepoAdmin := svcfs.NewJsonMetaRepoAdmin(parser.version)
43-
jsonMetaRepo := svcfs.NewJsonMetaRepo(metaRepoPath)
44-
config := &rootCliConfig{
45-
args: args,
46-
cmdFactory: use.NewCommandFactory().
47-
WithLocalRepositorySource(jsonMetaRepo).
48-
WithMetaDataAdmin(metaRepoAdmin).
49-
WithRemoteRepositorySource(jsonMetaRepo),
50-
debug: debug,
51-
flagSet: flags,
52-
inputLines: make([]string, 0),
53-
metaRepoPath: metaRepoPath,
54-
queryFactory: use.NewQueryFactory().
55-
WithLocalRepositorySource(jsonMetaRepo).
56-
WithMetaDataAdmin(metaRepoAdmin).
57-
WithRemoteRepositorySource(jsonMetaRepo),
58-
}
59-
60-
return config, nil
42+
return parser.assemble(args, debug, flags, make([]string, 0), metaRepoPath), nil
6143
}
6244
}
6345

@@ -80,36 +62,53 @@ func (parser rootConfigParser) ParseR(
8062
}
8163
}
8264

83-
inputLines := make([]string, 0)
84-
if readFromStdin {
85-
scanner := bufio.NewScanner(stdin)
86-
for scanner.Scan() {
87-
line := scanner.Text()
88-
inputLines = append(inputLines, line)
89-
}
90-
if scanErr := scanner.Err(); scanErr != nil {
91-
return nil, scanErr
92-
}
65+
if !readFromStdin {
66+
return parser.assemble(argsBeforeDash, debug, flags, make([]string, 0), metaRepoPath), nil
67+
} else if inputLines, scanErr := readLines(stdin); scanErr != nil {
68+
return nil, scanErr
69+
} else {
70+
return parser.assemble(argsBeforeDash, debug, flags, inputLines, metaRepoPath), nil
9371
}
72+
}
73+
}
9474

95-
metaRepoAdmin := svcfs.NewJsonMetaRepoAdmin(parser.version)
96-
jsonMetaRepo := svcfs.NewJsonMetaRepo(metaRepoPath)
97-
config := &rootCliConfig{
98-
args: argsBeforeDash,
99-
cmdFactory: use.NewCommandFactory().
100-
WithLocalRepositorySource(jsonMetaRepo).
101-
WithMetaDataAdmin(metaRepoAdmin).
102-
WithRemoteRepositorySource(jsonMetaRepo),
103-
debug: debug,
104-
flagSet: flags,
105-
inputLines: inputLines,
106-
metaRepoPath: metaRepoPath,
107-
queryFactory: use.NewQueryFactory().
108-
WithLocalRepositorySource(jsonMetaRepo).
109-
WithMetaDataAdmin(metaRepoAdmin).
110-
WithRemoteRepositorySource(jsonMetaRepo),
111-
}
75+
func (parser rootConfigParser) assemble(
76+
args []string,
77+
debug bool,
78+
flags *pflag.FlagSet,
79+
inputLines []string,
80+
metaRepoPath string,
81+
) CliConfig {
82+
metaRepoAdmin := svcfs.NewJsonMetaRepoAdmin(parser.version)
83+
jsonMetaRepo := svcfs.NewJsonMetaRepo(metaRepoPath)
84+
return &rootCliConfig{
85+
args: args,
86+
cmdFactory: use.NewCommandFactory().
87+
WithLocalRepositorySource(jsonMetaRepo).
88+
WithMetaDataAdmin(metaRepoAdmin).
89+
WithRemoteRepositorySource(jsonMetaRepo),
90+
debug: debug,
91+
flagSet: flags,
92+
inputLines: inputLines,
93+
metaRepoPath: metaRepoPath,
94+
queryFactory: use.NewQueryFactory().
95+
WithLocalRepositorySource(jsonMetaRepo).
96+
WithMetaDataAdmin(metaRepoAdmin).
97+
WithRemoteRepositorySource(jsonMetaRepo),
98+
}
99+
}
112100

113-
return config, nil
101+
func readLines(stdin io.Reader) ([]string, error) {
102+
inputLines := make([]string, 0)
103+
scanner := bufio.NewScanner(stdin)
104+
for scanner.Scan() {
105+
line := scanner.Text()
106+
inputLines = append(inputLines, line)
107+
}
108+
109+
if scanErr := scanner.Err(); scanErr != nil {
110+
return nil, scanErr
111+
} else {
112+
return inputLines, nil
114113
}
115114
}

0 commit comments

Comments
 (0)