Skip to content

Commit 3e5c03d

Browse files
authored
Allow setting of custom title (#52)
* Make OptionParser enforce required parameter options * Allow setting of custom title * Bump gem version
1 parent 6242d3c commit 3e5c03d

10 files changed

Lines changed: 69 additions & 11 deletions

File tree

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
visualize_packs (0.5.17)
4+
visualize_packs (0.5.18)
55
packs-specification
66
parse_packwerk (>= 0.20.0)
77
sorbet-runtime

bin/visualize_packs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ OptionParser.new do |opt|
1818
opt.on('--no-visibility-arrows', "Don't show visibility arrows") { |o| options.show_visibility = false }
1919

2020
opt.on('--no-todo-arrows', "Don't show pack todos") { |o| options.show_todos = false }
21-
opt.on("--only-todo-types=", "Show only the selected types of todos. Comma-separated list of #{EdgeTodoTypes.values.map &:serialize}") { |o| options.only_todo_types = o.to_s.split(",").uniq.map { EdgeTodoTypes.deserialize(_1) } }
21+
opt.on("--only-todo-types=STRING", "Show only the selected types of todos. Comma-separated list of #{EdgeTodoTypes.values.map &:serialize}") { |o| options.only_todo_types = o.to_s.split(",").uniq.map { EdgeTodoTypes.deserialize(_1) } }
2222
opt.on("--use-todos-for-layout", "Show only the selected types of todos. Comma-separated list of #{EdgeTodoTypes.values.map &:serialize}") { |o| options.use_todos_for_layout = true }
2323

2424
opt.on('--no-teams', "Don't show team colors") { |o| options.show_teams = false }
2525

26-
opt.on('--focus-pack=', "Focus on a specific pack(s). Comma-separated list of packs. Wildcards supported: 'packs/*'") { |o| options.focus_pack = o.to_s.split(",") }
27-
opt.on('--focus-pack-edge-mode=', "If focus-pack is set, this shows only between focussed packs (when set to none) or the edges into / out of / in and out of the focus packs to non-focus packs (which will be re-added to the graph). One of #{FocusPackEdgeDirection.values.map &:serialize}") { |o| options.show_only_edges_to_focus_pack = FocusPackEdgeDirection.deserialize(o) }
26+
opt.on('--focus-pack=STRING', "Focus on a specific pack(s). Comma-separated list of packs. Wildcards supported: 'packs/*'") { |o| options.focus_pack = o.to_s.split(",") }
27+
opt.on('--focus-pack-edge-mode=STRING', "If focus-pack is set, this shows only between focussed packs (when set to none) or the edges into / out of / in and out of the focus packs to non-focus packs (which will be re-added to the graph). One of #{FocusPackEdgeDirection.values.map &:serialize}") { |o| options.show_only_edges_to_focus_pack = FocusPackEdgeDirection.deserialize(o) }
2828
opt.on('--exclude-packs=', "Exclude listed packs from diagram. If used with include you will get all included that are not excluded. Wildcards support: 'packs/ignores/*'") { |o| options.exclude_packs = o.to_s.split(",") }
2929

3030
opt.on('--roll-nested-into-parent-packs', "Don't show nested packs (not counting root). Connect edges to top-level pack instead") { |o| options.roll_nested_into_parent_packs = true }
3131
opt.on('--no-nesting-arrows', "Don't draw relationships between parents and nested packs") { |o| options.show_nested_relationships = false }
3232

33-
opt.on('--remote-base-url=', "Link pack packs to a URL (affects graphviz SVG generation)") { |o| options.remote_base_url = o }
33+
opt.on('--remote-base-url=STRING', "Link pack packs to a URL (affects graphviz SVG generation)") { |o| options.remote_base_url = o }
34+
35+
opt.on('--title=STRING', "Set a custom diagram title") { |o| options.title = o }
3436

3537
opt.on_tail("-h", "--help", "Show this message") do
3638
puts opt

diagram_examples.png

-4.81 KB
Loading

lib/visualize_packs.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def self.code_owner(package)
5656

5757
sig { params(options: Options, max_todo_count: T.nilable(Integer)).returns(String) }
5858
def self.diagram_title(options, max_todo_count)
59+
return "<<b>#{options.title}</b>>" if options.title
60+
5961
app_name = File.basename(Dir.pwd)
6062
focus_edge_info = options.focus_pack && options.show_only_edges_to_focus_pack != FocusPackEdgeDirection::All ? "showing only edges to/from focus pack" : "showing all edges between visible packs"
6163
focus_info = options.focus_pack ? "Focus on #{limited_sentence(options.focus_pack)} (#{focus_edge_info})" : "All packs"

lib/visualize_packs/options.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ class Options < T::Struct
4444
prop :show_nested_relationships, T::Boolean, default: true
4545

4646
prop :remote_base_url, T.nilable(String)
47+
48+
prop :title, T.nilable(String), default: nil
4749
end

spec/diagram_generation_helper.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test_names+=("no_visibility"); test_params[${test_names[-1]}]="--no-visibility-a
2828
test_names+=("only_todo_types"); test_params[${test_names[-1]}]="--only-todo-types=architecture,visibility"
2929
test_names+=("roll_nested_into_parent_packs"); test_params[${test_names[-1]}]="--roll-nested-into-parent-packs"
3030
test_names+=("only_layers"); test_params[${test_names[-1]}]="--no-dependency-arrows --no-todo-arrows --no-privacy --no-teams --no-nesting-arrows"
31-
test_names+=("no_to_all"); test_params[${test_names[-1]}]="--no-layers --no-dependency-arrows --no-todo-arrows --no-privacy --no-teams --no-nesting-arrows"
31+
test_names+=("no_to_all"); test_params[${test_names[-1]}]="--title='Hide everything' --no-layers --no-visibility --no-dependency-arrows --no-todo-arrows --no-privacy --no-teams --no-nesting-arrows"
3232
test_names+=("focussed_on_packs_ui"); test_params[${test_names[-1]}]="--focus-pack=packs/ui"
3333
test_names+=("focussed_on_packs_ui_focus_edges"); test_params[${test_names[-1]}]="--focus-pack=packs/ui --focus-pack-edge-mode=inout"
3434

@@ -40,7 +40,7 @@ test_names+=("focussed_on_packs_ui_focus_edges"); test_params[${test_names[-1]}]
4040
for test in "${test_names[@]}"; do
4141
params=${test_params[$test]}
4242
echo "Testing $test: $params"
43-
bundle exec visualize_packs $params $URL > test_output/$test$NEW.dot
43+
bundle exec "visualize_packs ${params} $URL" > test_output/$test$NEW.dot
4444
done
4545

4646
if [ "$GENERATE_PNGS" = "GENERATE_PNGS" ]; then

spec/sample_app1/Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ../..
33
specs:
4-
visualize_packs (0.5.17)
4+
visualize_packs (0.5.18)
55
packs-specification
66
parse_packwerk (>= 0.20.0)
77
sorbet-runtime

spec/sample_app1/test_output/no_to_all.dot

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ digraph package_diagram {
55
fontname="Helvetica,Arial,sans-serif"
66
dpi=100
77
layout=dot
8-
label=<<b>sample_app1: All packs - hiding layers, hiding dependencies, hiding todos, hiding privacy, hiding teams, hiding nested relationships</b>>
8+
label=<<b>Hide everything</b>>
99
fontsize=18
1010
]
1111
node [
@@ -105,7 +105,6 @@ digraph package_diagram {
105105
]
106106

107107
}
108-
"packs/models/packs/model_a" -> "packs/models" [ color=blue constraint=false ]
109108
subgraph cluster_legend {
110109
fontsize=16
111110
label="Edges Styles and Arrow Heads"

spec/visualize_packs_spec.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,4 +594,57 @@
594594
end
595595
end
596596
end
597+
598+
describe '.diagram_title' do
599+
context 'with a custom title from options' do
600+
it "returns whatever is set" do
601+
options = Options.new
602+
options.title = "Some title"
603+
604+
expect(VisualizePacks.diagram_title(options, 42)).to eq("<<b>Some title</b>>")
605+
end
606+
end
607+
608+
context 'without a custom title from options' do
609+
describe 'with basic options and nil max edge count' do
610+
it "with " do
611+
options = Options.new
612+
613+
expect(VisualizePacks.diagram_title(options, 0)).to eq(
614+
"<<b>visualize_packs: All packs</b><br/><font point-size='12'>Widest todo edge is 0 todo</font>>"
615+
)
616+
end
617+
end
618+
619+
describe 'with basic options and 0 max edge count' do
620+
it "with " do
621+
options = Options.new
622+
623+
expect(VisualizePacks.diagram_title(options, 0)).to eq(
624+
"<<b>visualize_packs: All packs</b><br/><font point-size='12'>Widest todo edge is 0 todo</font>>"
625+
)
626+
end
627+
end
628+
629+
describe 'with basic options and 1 max edge count' do
630+
it "with " do
631+
options = Options.new
632+
633+
expect(VisualizePacks.diagram_title(options, 1)).to eq(
634+
"<<b>visualize_packs: All packs</b><br/><font point-size='12'>Widest todo edge is 1 todo</font>>"
635+
)
636+
end
637+
end
638+
639+
describe 'with basic options and non-zero max edge count' do
640+
it "with " do
641+
options = Options.new
642+
643+
expect(VisualizePacks.diagram_title(options, 19)).to eq(
644+
"<<b>visualize_packs: All packs</b><br/><font point-size='12'>Widest todo edge is 19 todos</font>>"
645+
)
646+
end
647+
end
648+
end
649+
end
597650
end

visualize_packs.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = "visualize_packs"
3-
spec.version = '0.5.17'
3+
spec.version = '0.5.18'
44
spec.authors = ['Gusto Engineers']
55
spec.email = ['dev@gusto.com']
66
spec.summary = 'A gem to visualize connections in a Ruby app that uses packs'

0 commit comments

Comments
 (0)