Skip to content

Commit

Permalink
Support setting config options via environment variables
Browse files Browse the repository at this point in the history
Fix path handling for windows in config tests

Add JSON tags and make field naming more consistent

Generate CLI flags from struct

Flat map is generated on the fly (fewer allocations)

Renames and minor tweaks

Add CLI flag descriptions

Rename file

Minor restructuring

Minor tweaks

First draft of a documentation generation tool

Adding templ code and some styling info

Style tweaks

Add option to disable file embedding

Promote documentation code

Add a warning for using tabs in struct tags
  • Loading branch information
Maelkum committed Apr 12, 2024
1 parent 60a343d commit 8929f40
Show file tree
Hide file tree
Showing 24 changed files with 1,339 additions and 418 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmd/node/node
cmd/node/.b7s_*
cmd/node/*.yaml
cmd/b7s-node-docs/b7s-node-docs

cmd/keygen/keygen
cmd/keyforge/keyforge
Expand Down
91 changes: 91 additions & 0 deletions cmd/b7s-node-docs/assets/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
body {
font-family: Arial, sans-serif;
background-color: #dce4e8;
color: #333;
margin: 20px;
padding: 20px;
}

h1 {
color: #333;
border-bottom: 1px solid #ccc;
padding-bottom: 10px;
margin-bottom: 20px;
}

h3 {
color: #666;
margin-top: 20px;
}

ul {
list-style-type: none;
padding: 0;
}

li {
margin-bottom: 20px;
padding: 20px;
}

li.cfg {
background-color: #fff;
border-radius: 15px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
padding: 20px;
}

li.child-cfg {
background-color: #fefefe;
border-radius: 15px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
padding: 20px;
}

li.cli {
background-color: #edf2f5;
margin-bottom: 10px;
margin-right: 30px;
margin-left: 30px;
padding: 10px;
}

.cli-details {
margin-left: 20px;
}

h3 {
color: #333;
margin-top: 0;
}

p {
margin: 5px 0;
}

dl {
margin: 0;
}

dt {
margin-bottom: 15px;
}

dd {
margin-left: 0;
}

code {
background-color: #f5f5f5;
padding: 2px 5px;
border-radius: 3px;
}

.link-icon {
margin-left: 5px;
font-size: 80%;
color: #888;
text-decoration: none;
}
Binary file added cmd/b7s-node-docs/assets/favicon/favicon.ico
Binary file not shown.
86 changes: 86 additions & 0 deletions cmd/b7s-node-docs/b7sdocs.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package main

import "fmt"
import "github.com/blocklessnetwork/b7s/internal/config"

templ page(configs []config.ConfigOption) {
<html>
<head>
<title>Blockless B7S Node Configuration</title>
<link rel="icon" href="/assets/favicon/favicon.ico" type="image/x-icon" sizes="16x16"/>
<link rel="stylesheet" href="/assets/css/style.css" />
</head>
<body>
<h1>Blockless B7S Node Configuration</h1>
<p>
This page lists all of the configuration options supported by the b7s daemon.
It showcases the configuration structure, as accepted in a YAML config file, environment variables that can be used to set those options and, where applicable, the CLI flags and their default values.
</p>

@b7sdocs(configs)
</body>
</html>
}


templ b7sdocs(configs []config.ConfigOption) {

<ul>
for _, cfg := range configs {
<li class="cfg">
@configOption(cfg)
</li>
}
</ul>
}

func formatCLIDefault(def any) string {
str := fmt.Sprint(def)
if str != "" {
return str
}

return "N/A"
}

templ configOption(cfg config.ConfigOption) {

<h3 id={cfg.FullPath}>{cfg.Name} <a class="link-icon" href={ templ.URL(fmt.Sprintf("#%s", cfg.FullPath)) }><span >&#128279;</span></a></h3>

if cfg.Type() != "" {
<p>Type: {cfg.Type()}</p>
}

<p>Path: {cfg.FullPath}</p>
if cfg.Env != "" {
<p>Environment variable: {cfg.Env}</p>
}

if cfg.CLI.Flag != "" {

<dl>
<dt>CLI flag:</dt>
<dd>
<ul class="cli-details">
<li class="cli">Flag: <code>--{cfg.CLI.Flag}</code></li>
if cfg.CLI.Shorthand != "" {
<li class="cli">Shorthand: <code>-{cfg.CLI.Shorthand}</code></li>
}

<li class="cli">Default: {formatCLIDefault(cfg.CLI.Default)}</li>
<li class="cli">Description: {cfg.CLI.Description}</li>
</ul>
</dd>
</dl>
}

if len(cfg.Children) > 0 {
<ul>
for _, child := range cfg.Children {
<li class="child-cfg">
@configOption(child)
</li>
}
</ul>
}
}
Loading

0 comments on commit 8929f40

Please sign in to comment.