Skip to content

Fix --help flag and TOML config generation#8

Merged
bdk38 merged 2 commits intomainfrom
copilot/fix-help-flag-toml-config
Mar 6, 2026
Merged

Fix --help flag and TOML config generation#8
bdk38 merged 2 commits intomainfrom
copilot/fix-help-flag-toml-config

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 6, 2026

Two independent CLI bugs: --help silently starts the server instead of printing usage, and ./HellPot -g produces flat quoted dotted keys instead of proper TOML sections.

Changes

  • internal/config/arguments.go: Add --help to the -h switch case — consistent with the help text that already advertises --help.

  • internal/config/defaults.go: Replace snek.Marshal(toml.Parser()) with a direct marshal of defOpts via toml.Parser().Marshal(...). The previous call serialized koanf's flattened internal state (dotted keys), not the original nested structure.

Before:

'http.bind_addr' = '127.0.0.1'
'http.bind_port' = '8080'

After:

[http]
bind_addr = '127.0.0.1'
bind_port = '8080'

A shallow type conversion (map[string]map[string]interface{}map[string]interface{}) is required to satisfy Marshal's signature; the inner maps are preserved and the TOML parser correctly renders them as sections.

Original prompt

Fix --help Flag and TOML Config Generation

Problems

Problem 1: --help Flag Doesn't Work

Running ./HellPot --help doesn't display help text - it just starts the server instead. Only -h works.

Root Cause:
In internal/config/arguments.go line 27:

case "-h":
    CLI.printUsage()

Only -h is handled, not --help.

Problem 2: Generated TOML Uses Quoted Dotted Keys

Running ./HellPot -g generates a config file with flat, quoted keys:

'deception.server_name' = 'nginx'
'http.bind_addr' = '127.0.0.1'
'http.bind_port' = '8080'
'logger.debug' = true

Expected: Proper TOML sections:

[deception]
server_name = 'nginx'

[http]
bind_addr = '127.0.0.1'
bind_port = '8080'

[logger]
debug = true

Root Cause:
In internal/config/defaults.go line 64, the gen() function uses:

if dat, err = snek.Marshal(toml.Parser()); err != nil {

This marshals koanf's flattened internal structure (with dotted keys) instead of the original nested structure.


Solutions

Fix 1: Add --help Support

File: internal/config/arguments.go

Update line 27-28 to handle both -h and --help:

case "-h", "--help":
    CLI.printUsage()

This is consistent with the help text shown in internal/config/help.go which mentions --help.

Fix 2: Generate Proper TOML Sections

File: internal/config/defaults.go

In the gen() function, replace line 64:

OLD (incorrect):

if dat, err = snek.Marshal(toml.Parser()); err != nil {

NEW (correct):

if dat, err = toml.Parser().Marshal(defOpts); err != nil {

Why this works:

  • defOpts is already structured as nested map[string]map[string]interface{}
  • TOML parser's Marshal() method converts nested maps to TOML sections
  • We don't need koanf's flattened structure for generating defaults
  • koanf (snek) is still used for loading and accessing config at runtime

Benefits

  1. --help now works - Consistent with documented behavior
  2. Cleaner TOML output - Proper sections instead of quoted keys
  3. More readable configs - Easier for users to edit
  4. Simpler code - Direct marshaling, no flatten/unflatten cycle
  5. Standards compliant - Follows TOML best practices

Testing

After changes:

# Test help flag
./HellPot --help    # Should show help and exit
./HellPot -h        # Should also show help and exit

# Test config generation
./HellPot -g        # Should generate config.toml
cat config.toml     # Should show proper [sections]

# Verify config still loads
./HellPot           # Should start normally with generated config

Impact

  • Low risk - Only affects CLI argument parsing and config generation
  • No runtime changes - Config loading/reading unchanged
  • Backwards compatible - Existing config files still work
  • User-facing improvement - Better UX for help and config generation

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: bdk38 <244781262+bdk38@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix --help flag and TOML config generation issues Fix --help flag and TOML config generation Mar 6, 2026
Copilot finished work on behalf of bdk38 March 6, 2026 18:24
@bdk38 bdk38 marked this pull request as ready for review March 6, 2026 18:27
@bdk38 bdk38 merged commit 9b1bd36 into main Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants