How bashly-framework/bashly works
1. What this repo is
Bashly is a Ruby-based CLI framework and generator whose primary output is a single generated Bash script. The Ruby app is the build-time engine; the generated Bash script is the runtime artifact used by end users.
2. Top-level execution boundary
The main entrypoint is bin/bashly, which loads the Ruby library under lib/bashly. From there, the app exposes subcommands such as init, generate, add, render, validate, doc, preview, shell, and completions.
3. Command-line application layer
lib/bashly/cli.rb and lib/bashly/commands/* define the user-facing tool behavior. This layer handles orchestration: parsing CLI arguments for Bashly itself, dispatching to a subcommand, and coordinating file I/O and output generation.
4. Configuration input model
Bashly is driven by YAML config files, with schema definitions under schemas/ and templates under lib/bashly/templates/. The key inputs are the CLI spec file (bashly.yml), optional settings, and optional strings/override files. These define commands, subcommands, flags, arguments, env vars, and doc output.
5. Domain model for generated scripts
The lib/bashly/script/ directory contains the internal representation of the target Bash program: commands, flags, arguments, dependencies, environment variables, variables, catch-alls, and wrappers. This is the core abstraction layer that turns YAML configuration into a structured script model.
6. Validation and introspection
The script/introspection/ and config_validator.rb code enforce structural rules before generation. This is where Bashly checks things like uniqueness, required fields, flag/argument constraints, command naming, and visibility/private/public behavior so invalid CLIs fail early.
7. Rendering pipeline
The generation step uses a template/rendering system under lib/bashly/views/ and lib/bashly/render_context.rb / render_source.rb. The views are .gtx templates for assembling the final Bash script sections: wrapper, parsing, usage text, command dispatch, validations, hooks, and helpers. This is the main transformation boundary from model to output.
8. Generated script composition
The script output is intentionally modular before being flattened into one file. The views include reusable pieces for command filtering, arg parsing, help text, global flags, initialization hooks, and command bodies. That design makes the final script standalone while keeping generation maintainable in Ruby.
9. Optional framework-style libraries
lib/bashly/libraries/ contains built-in reusable assets that can be injected into generated CLIs, such as:
- completions support
- colors
- INI/config management
- YAML helpers
- stacktrace handling
- validations
- hooks
These are treated as reusable bundled features rather than part of the core parser.
10. Docs, completion, and auxiliary outputs
Bashly also generates supporting artifacts: shell completions, Markdown/manpage docs, and example command/help output. The render-specific libraries under lib/bashly/libraries/render/ and the docs templates under lib/bashly/docs/ support these secondary outputs.
11. Examples as architectural contracts
The large examples/ tree is not just samples; it documents supported shapes of the configuration and generated script behavior. Each example is a small end-to-end workspace with its own src/bashly.yml, command files, optional libs/settings, and test script, showing how the generator behaves across features.
12. Test strategy
spec/approvals/ captures approved outputs for generated scripts, docs, and examples, while spec/bashly/ contains unit and integration coverage for the Ruby generator itself. This strongly suggests the repo is validated by output comparison, not only by internal unit tests.
13. Distribution and packaging
The project is published as a Ruby gem and also packaged as a Docker image. That means the generator is meant to run both in a local Ruby environment and in containerized CI/tooling workflows, but the architecture remains centered on “Ruby generator -> Bash output.”
14. Overall data flow
The main flow is: user config files and command source files go into the Ruby generator, the config is validated and converted into an internal script model, templates render the model into a standalone Bash script, and optional docs/completions/support files are emitted alongside it.
Main entry points: views Views · config.rb Config · script Script model · bashly Ruby specs
Components 19
CLI app
Ruby entrypoint and command dispatch layer.
- bin/bashly · Executable that boots the Ruby CLI.
bin/bashly - CLI · Top-level application orchestration and subcommand routing.
lib/bashly/cli.rb - Commands · User-facing actions like init, generate, add, render, validate, doc, preview, shell, and completions.
lib/bashly/commands
Core model
Configuration loading, validation, and script domain objects.
- Config · Loads and represents Bashly YAML and settings inputs.
lib/bashly/config.rb - Schemas · JSON schema definitions for config, settings, and strings.
schemas/bashly.json - Validator · Checks config structure, names, flags, args, visibility, and other constraints.
lib/bashly/config_validator.rb - Script model · Internal representation of the generated Bash program.
lib/bashly/script - Introspection · Derives command, flag, argument, dependency, and visibility metadata from the script model.
lib/bashly/script/introspection
Rendering
Template-based transformation from model to generated Bash and docs.
- Views · GTX templates that assemble script sections and helper fragments.
lib/bashly/views - Render ctx · Holds rendering state and source mappings during generation.
lib/bashly/render_context.rb - Render source · Represents renderable input sources for templates and docs.
lib/bashly/render_source.rb - Wrapper · Generated script header and runtime bootstrap layer.
lib/bashly/views/wrapper - Command views · Parsing, dispatch, usage, validation, hooks, and command-body templates.
lib/bashly/views/command - Doc views · Templates for Markdown and manpage-style documentation.
lib/bashly/libraries/render
Bundled libraries
Reusable assets injected into generated scripts or auxiliary outputs.
- Built-ins · Core reusable bundled assets such as colors, config, help, hooks, ini, stacktrace, validations, and yaml.
lib/bashly/libraries - Render libs · Bundled render targets for documentation output formats.
lib/bashly/libraries/render
Examples & tests
Example workspaces and approval-based validation of generated output.
- Examples · End-to-end sample workspaces that exercise supported configuration and generation patterns.
examples - Approvals · Approved generated outputs for scripts, docs, completions, and examples.
spec/approvals - Ruby specs · Unit and integration coverage for the generator and its subsystems.
spec/bashly
Connections 23
- bin/bashly → CLI: boots · Executable starts the Ruby application.
- CLI → Commands: dispatches · Routes arguments into subcommand handlers.
- Commands → Config: loads · Commands read config and settings inputs.
- Config → Schemas: validates against · Configuration structure is checked against schemas.
- Config → Validator: checks · Config is normalized and validated before generation.
- Validator → Script model: builds · Valid config is converted into the script domain model.
- Script model → Introspection: analyzed by · Introspection derives script metadata and constraints.
- Introspection → Validator: feeds rules · Derived metadata informs validation decisions.
- Script model → Render ctx: renders with · Model data is passed into the rendering context.
- Render ctx → Render source: sources · Context tracks the source objects being rendered.
- Render ctx → Views: drives · Templates are selected and rendered through context.
- Views → Wrapper: includes · Wrapper templates produce the Bash bootstrap section.
- Views → Command views: includes · Command templates produce parsing and dispatch sections.
- Views → Doc views: includes · Doc-related templates emit markdown and manpage output.
- Built-ins → Script model: injects · Bundled libraries become available to generated scripts.
- Render libs → Doc views: supports · Render libraries back secondary documentation output.
- Examples → Config: demonstrates · Example workspaces model supported config shapes and features.
- Approvals → Views: verifies · Golden outputs lock template rendering behavior.
- Approvals → Examples: captures · Approved outputs cover example workspaces and workflows.
- Ruby specs → CLI: tests · Specs cover CLI orchestration and command behavior.
- Ruby specs → Config: tests · Specs cover config loading and validation.
- Ruby specs → Script model: tests · Specs cover script model and introspection behavior.
- Ruby specs → Views: tests · Specs cover rendering templates and output assembly.