Files
argparser/README.md
2025-10-11 05:03:12 +02:00

2.5 KiB

Bash Argument Parser Generator

A self-contained web application for interactively building bash argument parsing code. Zero external dependencies - single binary deployment.

Features

  • Zero Dependencies: Single Go binary with embedded assets
  • Real-time Help Preview: See generated help output as you type
  • Clean Separation: Frontend assets organized in separate directories
  • Auto-expanding Rows: New input rows appear automatically
  • Dark Terminal Theme: Professional terminal-style interface
  • Copy to Clipboard: One-click script copying

Architecture

argparse-builder/
├── main.go              # Go server with embedded FS
├── static/
│   ├── css/
│   │   └── style.css    # Styling
│   └── js/
│       └── app.js       # Frontend logic
└── templates/
    └── index.html       # HTML template

All files are embedded using //go:embed directive, resulting in a single binary.

Build

go build -o argparse-builder

Run

./argparse-builder

Server starts on port 8080. Open http://localhost:8080 in your browser. Demo available at: https://pages.git.pynezz.dev/argparse-builder

Usage

  1. Add Custom Header (optional): Set a greeting or description
  2. Define Arguments:
    • Parameters: -v --verbose (flag syntax)
    • Variable Name: verbose (internal variable)
    • Help Text: Description shown in help output
  3. Real-time Preview: Help output updates as you type
  4. Generate: Click "Generate BASH" to create the script
  5. Copy: Use the copy button to get the generated code

Example Output

For inputs:

  • Header: "My Script v1.0"
  • Arguments: -v --verbose, verbose, "Enable verbose output"

Generates a complete bash script with:

  • Usage function with formatted help
  • Argument parsing with case statements
  • Variable initialization
  • Unknown option handling
  • -h/--help support

Technical Details

  • Language: Go 1.21+
  • Embedding: embed.FS for asset bundling
  • Binary Size: ~9MB (includes runtime and all assets)
  • HTTP Server: Standard library net/http
  • Frontend: Vanilla JavaScript (no frameworks)

Performance

  • Instant startup (no compilation)
  • Low memory footprint
  • Efficient static file serving from memory
  • No external network calls

Security Considerations

  • Input sanitization on server side
  • No shell execution
  • Template-based HTML generation
  • CORS headers not set (localhost only by default)