Hog v10.58.0
help.tcl
Go to the documentation of this file.
2  aliases {H}
3  description "Display this help message."
4  passthrough true
5  script {
6  set _topic [Commands::Args]
7  if {[llength $_topic] == 0} {
8  Help::RenderTopLevel
9  } else {
10  Help::RenderPath $_topic
11  }
12  }
13 }
14 
15 Commands::RegisterCommand HELP.FLOWS {
16  aliases {F}
17  description "Flow help. Usage: HELP FLOWS \[<tool>\] \[<flow>\]"
18  script {
19  Help::_banner
20  set _tool_arg [Commands::Arg 0]
21  set _flow_arg [Commands::Arg 1]
22 
23  if {$_tool_arg eq ""} {
24  puts "TODO: dedicated flows overview page"
25  return
26  }
27 
28  # Resolve tool alias to namespace.
29  set _tool_ns ""
30  foreach ns [namespace children ::Tools] {
31  if {[string tolower [namespace tail $ns]] eq [string tolower $_tool_arg]} {
32  set _tool_ns $ns
33  break
34  }
35  }
36  if {$_tool_ns eq ""} {
37  set _avail_list {}
38  foreach ns [lsort [namespace children ::Tools]] { lappend _avail_list [string tolower [namespace tail $ns]] }
39  puts "Unknown tool '$_tool_arg'. Available tools: [join $_avail_list {, }]"
40  return
41  }
42 
43  # GetChildren is a raw prefix-scan over real canons, never alias-aware, so
44  # resolve the tool's real canon via GetCommand first, not a guessed
45  # string (same pattern as Help::_tool_group_rows).
46  set _tnode [Commands::GetCommand [string toupper [namespace tail $_tool_ns]]]
47  set _flow_root "[tdict getval $_tnode canon].FLOW"
48 
49  if {$_flow_arg eq ""} {
50  set _kids [Commands::GetChildren $_flow_root]
51  if {[llength $_kids] == 0} {
52  puts "\nTool [namespace tail $_tool_ns] declares no flows.\n"
53  return
54  }
55  puts "\nFlows for [namespace tail $_tool_ns]:"
56  foreach _c $_kids { puts [Help::_child_row [Commands::GetCommand $_c] 2] }
57  puts ""
58  return
59  }
60 
61  set _fnode [Commands::GetCommand "$_flow_root.$_flow_arg"]
62  if {$_fnode eq {}} {
63  puts "Tool [namespace tail $_tool_ns] has no flow '$_flow_arg'."
64  return
65  }
66  # A flow renders through the ordinary command page - it is an ordinary node.
67  Help::RenderCommand $_fnode [list [string tolower [namespace tail $_tool_ns]] \
68  FLOW [tdict getval $_fnode name]]
69  }
70 }
71 
72 Commands::RegisterCommand HELP.TOOLS {
73  aliases {TOOL T}
74  description "Overview of registered tools (built-in vs custom). Usage: HELP TOOLS \[<tool>\]"
75  script {
76  Help::_banner
77  set _which [Commands::Arg 0]
78  if {$_which eq ""} { Help::RenderToolList } else { Help::RenderTool $_which }
79  }
80 }
81 
82 
83 namespace eval Help {
84 
85 
86  # accepts either a plain list of alias strings (commands) or a tlist (flows).
87  proc _aliases {obj name} {
88  set als {}
89  if {[tobj isobj $obj] && [tobj type $obj] eq "List"} {
90  foreach a [tobj value $obj] {
91  set al [string tolower [tobj value $a]]
92  if {$al ne [string tolower $name]} { lappend als $al }
93  }
94  } else {
95  foreach a $obj {
96  set al [string tolower $a]
97  if {$al ne [string tolower $name]} { lappend als $al }
98  }
99  }
100  return [expr {[llength $als] > 0 ? "([join $als {, }])" : ""}]
101  }
102 
103  # expects a tlist of options; returns a plain string
104  proc _options_string {obj_list {indent 0}} {
105  set pad [string repeat " " $indent]
106  set out ""
107  foreach _option $obj_list {
108  set n [llength $_option]
109  if {$n == 2} {
110  lassign $_option opt help
111  append out [format "%s%-20s %s\n" $pad "-$opt" $help]
112  } elseif {$n == 3} {
113  lassign $_option opt def help
114  set suffix [expr {$def ne "" ? " (default: $def)" : ""}]
115  append out [format "%s%-20s %s%s\n" $pad "-$opt <arg>" $help $suffix]
116  } else {
117  Msg Warning "Custom option spec has invalid arity (expected 2 or 3): $_option"
118  }
119  }
120  return $out
121  }
122 
123  proc _banner {} {
124  puts "[string repeat "=" 80]\nHog Launcher - Help\n[string repeat "=" 80]"
125  }
126 
127  # Registered tool namespaces split as {builtin custom}
128  proc _tool_groups {} {
129  set _builtin {}
130  set _custom {}
131  foreach ns [lsort [namespace children ::Tools]] {
132  if {[catch {set m [${ns}::GetManifest]}]} continue
133  if {[dict exists $m custom] && [dict get $m custom]} {
134  lappend _custom $ns
135  } else {
136  lappend _builtin $ns
137  }
138  }
139  return [list $_builtin $_custom]
140  }
141 
142  # One indented line for a child node: "*NAME (aliases) description",
143  # where * marks a node that needs a project.
144  proc _child_row {node indent} {
145  if {$node eq {}} { return "" }
146  set name [tdict getval $node name]
147  # Marker and name share one padded field, so a long name doesn't shift the
148  # alias/description columns by the width of the "*".
149  if {[Commands::Node::RequiresProj $node]} { set name "*$name" }
150  return [format "%s%-17s %-12s %s" \
151  [string repeat " " $indent] \
152  $name \
153  [_aliases [tdict getobjor $node aliases [tlist create]] [tdict getval $node name]] \
154  [tdict getor $node description ""]]
155  }
156 
157  proc RenderPath {path} {
158  _banner
159  set _resolved [Commands::ResolvePath $path]
160 
161  if {[llength $_resolved] > 0 && [llength [dict get $_resolved remaining]] == 0} {
162  # Matched a registered command
163  set _node [dict get $_resolved node]
164  if {[Commands::Node::IsTool $_node]} {
165  RenderTool [string tolower [tdict getval $_node name]]
166  return
167  }
168  RenderCommand $_node [dict get $_resolved path]
169  return
170  }
171 
172  # Single-segment path naming a flow that several tools provide -> overview.
173  set _first [string toupper [lindex $path 0]]
174  if {[llength $path] == 1 && [llength [Commands::ToolsWithFlow $_first]] > 0} {
175  RenderFlows $_first
176  return
177  }
178 
179  puts "Unknown help topic: [join $path { }]"
180  }
181 
182 
183  # Top Level Help Page: ./Hog/Do HELP
184  proc RenderTopLevel {} {
185  _banner
186  puts ""
187  puts "usage: ./Hog/Do <directive> \[project\] \[OPTIONS\]"
188  puts ""
189 
190  set _fmt_tool_row {{ns} {
191  if {[catch {set m [${ns}::GetManifest]} err]} { return "" }
192  set vendor [expr {[dict exists $m vendor] ? " ([dict get $m vendor])" : ""}]
193  return [format " %-12s %s%s" [string tolower [namespace tail $ns]] [dict get $m name] $vendor]
194  }}
195  lassign [_tool_groups] _builtin_tools _custom_tools
196  puts "Built-in tools:"
197  foreach ns $_builtin_tools {
198  set _row [apply $_fmt_tool_row $ns]
199  if {$_row ne ""} { puts $_row }
200  }
201  if {[llength $_custom_tools] > 0} {
202  puts "\nCustom tools:"
203  foreach ns $_custom_tools {
204  set _row [apply $_fmt_tool_row $ns]
205  if {$_row ne ""} { puts $_row }
206  }
207  }
208  puts ""
209 
210  set _fmt_cmd_row {{cmd} {
211  return [format " %-10s %s" [tdict getval $cmd name] [tdict getor $cmd description ""]]
212  }}
213 
214  puts "General directives:"
215  dict for {cname cmd} [::Commands::GetCommands] {
216  if {[Commands::Node::IsTool $cmd]} { continue }
217  if {[tdict getor $cmd custom 0]} { continue }
218  puts [apply $_fmt_cmd_row $cmd]
219  }
220 
221  set _has_custom 0
222  dict for {cname cmd} [::Commands::GetCommands] {
223  if {[Commands::Node::IsTool $cmd]} { continue }
224  if {![tdict getor $cmd custom 0]} { continue }
225  if {!$_has_custom} { puts "\nCustom commands:"; set _has_custom 1 }
226  puts [apply $_fmt_cmd_row $cmd]
227  }
228 
229  puts ""
230 
231  set _common_flows {
232  CREATE "Create the project, replace it if already existing."
233  SYNTH "Run synthesis only, create the project if not existing."
234  IMPLEMENTATION "Run implementation only, project must already exist and be synthesised."
235  SIMULATION "Simulate the project, creating it if not existing."
236  WORKFLOW "Run the full workflow, creates the project if not existing."
237  CREATEWORKFLOW "Create the project (even if existing) and run the complete workflow."
238  }
239  puts "Common project flows (require a project):"
240  dict for {_fn _desc} $_common_flows {
241  puts [format " %-16s %s" $_fn $_desc]
242  }
243 
244  puts ""
245  puts "Additional information:"
246  puts " Help for a specific directive: ./Hog/Do HELP <directive> or ./Hog/Do <directive> --help"
247  puts " List every tool: ./Hog/Do HELP TOOLS"
248  puts " Help for a tool: ./Hog/Do HELP <tool> or ./Hog/Do HELP TOOLS <tool>"
249  puts " Help for a flow across tools: ./Hog/Do HELP <flow>"
250  puts " Help for a tool's flow: ./Hog/Do HELP FLOWS <tool> <flow>"
251  puts ""
252  }
253 
254  # Two lines per tool: identity, then what it offers.
255  proc _tool_group_rows {label tools} {
256  if {[llength $tools] == 0} { return }
257  puts "\n$label"
258  foreach ns $tools {
259  set _m [${ns}::GetManifest]
260  set _short [string tolower [namespace tail $ns]]
261  set _node [Commands::GetCommand [string toupper [namespace tail $ns]]]
262 
263  set _als ""
264  if {$_node ne {}} {
265  set _als [_aliases [tdict getobjor $_node aliases [tlist create]] \
266  [tdict getval $_node name]]
267  }
268 
269  # The node's own resolved canon (via GetCommand above)
270  set _real_canon [expr {$_node ne {} ? [tdict getval $_node canon] : ""}]
271 
272  # Direct commands are the leaf children; FLOW/STAGE are the group children.
273  set _ncmd 0
274  foreach _c [Commands::GetChildren $_real_canon] {
275  if {[llength [Commands::GetChildren $_c]] == 0} { incr _ncmd }
276  }
277  set _nflow [llength [Commands::GetChildren "$_real_canon.FLOW"]]
278  set _nstage [llength [Commands::GetChildren "$_real_canon.STAGE"]]
279 
280  set _offers {}
281  if {$_nflow > 0} { lappend _offers "$_nflow flow[expr {$_nflow == 1 ? {} : {s}}]" }
282  if {$_nstage > 0} { lappend _offers "$_nstage stage[expr {$_nstage == 1 ? {} : {s}}]" }
283  if {$_ncmd > 0} { lappend _offers "$_ncmd command[expr {$_ncmd == 1 ? {} : {s}}]" }
284  if {[llength $_offers] == 0} { set _offers [list "nothing registered"] }
285 
286  # Aliases go last on the second line
287  set _line2 [join $_offers {, }]
288  if {$_als ne ""} { append _line2 " aka [string trim $_als {()}]" }
289  puts [format " %-12s %s" $_short [dict get $_m name]]
290  puts [format " %-12s %s" "" $_line2]
291  }
292  }
293 
294  # Tools overview: ./Hog/Do HELP TOOLS
295  # One row per tool: aliases plus flow/stage/command counts
296  proc RenderToolList {} {
297  lassign [_tool_groups] _builtin _custom
298  _tool_group_rows "Built-in tools:" $_builtin
299  _tool_group_rows "Custom tools (hog-tools/):" $_custom
300 
301  puts ""
302  puts " A tool's own page: ./Hog/Do HELP TOOLS <tool> (or HELP <tool>)"
303  puts " Run a tool's command: ./Hog/Do <tool> <command> \[OPTIONS\]"
304  puts " Run a tool's flow: ./Hog/Do <tool> FLOW <flow> <project>"
305  puts ""
306  }
307 
308  # Tool-level Help Page: ./Hog/Do HELP TOOLS <tool>
309  proc RenderTool {alias} {
310  set _tns [Tools::ResolveAlias [string tolower $alias]]
311  if {$_tns eq "" || [catch {${_tns}::GetManifest} _m]} {
312  set _avail_list {}
313  foreach ns [lsort [namespace children ::Tools]] { lappend _avail_list [string tolower [namespace tail $ns]] }
314  puts "Unknown tool '$alias'. Available tools: [join $_avail_list {, }]"
315  return
316  }
317  set _canon [string tolower [namespace tail $_tns]]
318 
319  # Fetch the tool's own node via ResolvePath so alias walking is handled
320  # automatically (e.g. vivado_vitis_classic → VIVADO).
321  set _r [Commands::ResolvePath [list $_canon]]
322  set _tnode [expr {[llength $_r] > 0 ? [dict get $_r node] : {}}]
323 
324  set _tname [dict get $_m name]
325  set _alias_str ""
326  if {$_tnode ne ""} {
327  set _alias_str [_aliases [tdict getobjor $_tnode aliases [tlist create]] \
328  [tdict getval $_tnode name]]
329  }
330  puts "Tool: $_tname $_alias_str"
331  if {[dict get $_m vendor] ne ""} { puts " Vendor: [dict get $_m vendor]" }
332  if {[dict get $_m description] ne ""} { puts " Description: [dict get $_m description]" }
333  if {[dict get $_m version] ne ""} { puts " Version: [dict get $_m version]" }
334  if {[dict get $_m custom]} { puts " Origin: custom (user-defined)" }
335  if {[dict get $_m _source_path] ne ""} { puts " Source: [dict get $_m _source_path]" }
336  puts " Version Info:"
337  set _git [dict get $_m _git]
338  if {[dict size $_git] > 0} {
339  dict for {_gk _gv} $_git {
340  if {$_gv ne ""} { puts [format " %-10s %s" $_gk $_gv] }
341  }
342  }
343  if {[llength [dict get $_m features]] > 0} {
344  puts " Features: [join [dict get $_m features] {, }]"
345  }
346  puts ""
347  if {$_tnode ne ""} {
348  set _groups {}
349  set _cmd_hdr 0
350  foreach _child_canon [Commands::GetChildren [tdict getval $_tnode canon]] {
351  set _snode [Commands::GetCommand $_child_canon]
352  if {$_snode eq {}} { continue }
353  if {[llength [Commands::GetChildren $_child_canon]] > 0} {
354  lappend _groups $_child_canon
355  continue
356  }
357  if {!$_cmd_hdr} { puts "Usage: ./Hog/Do $_canon <command> \[OPTIONS\]\n\nCommands: (* - requires project)"; set _cmd_hdr 1 }
358  puts [_child_row $_snode 2]
359  }
360 
361  foreach _g $_groups {
362  set _gname [string tolower [tdict getval [Commands::GetCommand $_g] name]]
363  puts "\n[string totitle $_gname]s (run via 'tool $_canon $_gname <$_gname> <project>'):"
364  foreach _c [Commands::GetChildren $_g] { puts [_child_row [Commands::GetCommand $_c] 2] }
365  }
366  }
367  puts ""
368  }
369 
370 
371  # Flow-level Help Page: ./Hog/Do HELP <flow> - the same flow name across every
372  # tool that provides it. Summaries only; the per-tool page has the options.
373  proc RenderFlows {flow_name} {
374  puts "Flows matching '$flow_name':"
375  foreach _tool_key [Commands::ToolsWithFlow $flow_name] {
376  set _r [Commands::ResolvePath [list $_tool_key FLOW $flow_name]]
377  if {[llength $_r] == 0 || [llength [dict get $_r remaining]] > 0} { continue }
378  set _fnode [dict get $_r node]
379  if {$_fnode eq {}} { continue }
380  set _short [string tolower $_tool_key]
381  set _fname [tdict getval $_fnode name]
382  puts ""
383  puts " $_short: $_fname [_aliases [tdict getobjor $_fnode aliases [tlist create]] $_fname]"
384  if {[tdict getor $_fnode custom 0]} { puts " (custom flow — user-defined)" }
385  if {[tdict getor $_fnode description ""] ne ""} {
386  puts " [tdict getor $_fnode description ""]"
387  }
388  set _stages [Commands::Node::FlattenStages $_fnode]
389  if {[llength $_stages] > 0} { puts " Stages: [join $_stages { -> }]" }
390  puts " Run './Hog/Do HELP FLOWS $_short [string tolower $_fname]' for full options."
391  }
392  puts ""
393  }
394 
395  # Command-level Help Page: ./Hog/Do HELP <command>
396  proc RenderCommand {_node _path} {
397  # An author-supplied help body replaces the generated page entirely.
398  set _custom_help [tdict getor $_node help ""]
399  if {$_custom_help ne ""} { uplevel #0 $_custom_help; return }
400 
401  set _pretty [join $_path { }]
402  set _has_subs [expr {[llength [Commands::GetChildren [tdict getval $_node canon]]] > 0}]
403  set _run [Commands::Node::IsRunnable $_node]
404  set _req_proj [tdict getor $_node requires_proj 0]
405  set _proj_arg [expr {$_req_proj ? {<project> } : {}}]
406 
407  if {$_has_subs && $_run} {
408  puts "Usage: ./Hog/Do $_pretty ${_proj_arg}\[<subcommand>\] \[OPTIONS\]"
409  } elseif {$_has_subs} {
410  puts "Usage: ./Hog/Do $_pretty ${_proj_arg}<subcommand> \[OPTIONS\]"
411  } else {
412  puts "Usage: ./Hog/Do $_pretty ${_proj_arg}\[OPTIONS\]"
413  }
414  if {$_req_proj} { puts " Requires: project" }
415  puts ""
416  puts "$_pretty [_aliases [tdict getobjor $_node aliases [tlist create]] [tdict getval $_node name]]:"
417  puts " [tdict getor $_node description ""]"
418  if {[tdict getor $_node custom 0]} { puts " (custom — user-defined)" }
419 
420  # Flattened, so @referenced flows show their spliced-in stages rather than
421  # the raw "@CREATE" the author wrote.
422  set _stages [Commands::Node::FlattenStages $_node]
423  if {[llength $_stages] > 0} {
424  puts "\n Stages:"
425  puts " [join $_stages { -> }]"
426  }
427 
428  set _opts [Commands::GetCommandOptions $_node]
429  if {$_run && [llength $_opts] > 0} {
430  puts "\n Options:"
431  puts "[_options_string $_opts 3]"
432  }
433 
434  if {$_has_subs} {
435  puts "\n Subcommands: (* - requires project)"
436  foreach _child_canon [Commands::GetChildren [tdict getval $_node canon]] {
437  puts [_child_row [Commands::GetCommand $_child_canon] 3]
438  }
439  puts ""
440  }
441  }
442 }