A powerful and flexible utility for creating and managing C project directory structures with Lua scripting support.
CDirNuts is a command-line tool that enables you to:
- Generate complete C/C++ project structures with customizable templates
- Use Lua scripting for advanced project generation and automation
- Save and reuse project templates as presets
- Execute shell commands and create complex directory hierarchies programmatically
Whether you need a quick default C/C++ project or a sophisticated custom structure, CDirNuts provides the flexibility to match your workflow.
- Default Project Generation: Creates standardized C/C++ project directory structure
- Lua Scripting API: Full programmatic control over project generation
- Preset System: Save and reuse custom project templates
- Path Manipulation: Advanced path parsing and construction utilities
- Command Execution: Run shell commands from within Lua scripts
- File & Directory Management: Create complex nested structures with content
- Generates essential files (Makefile, README.md, .gitignore, LICENSE)
- Sets up source and include directories
- Includes a basic "Hello, World!" C/C++ program for default projects
- Lua-based configuration for unlimited customization
# Clone the repository
git clone https://github.com/ZiedYousfi/cdirnuts
cd cdirnuts
# Configure and build using CMake with vcpkg
cmake --preset=default
cmake --build build
# Run the utility
./build/cdirnuts- CMake 3.13 or higher
- C++23 compatible compiler (GCC, Clang)
- Lua 5.4 (automatically managed via vcpkg)
- vcpkg (for dependency management)
# Create a new C project using the default_init.lua script
./build/cdirnuts
# Show help
./build/cdirnuts --helpExecute Lua scripts to create custom project structures:
./build/cdirnuts --config my_template.luaSave and reuse project templates:
# List all saved presets
./build/cdirnuts --preset list
# Add a new preset
./build/cdirnuts --preset add my_template /path/to/template.lua
# Use a preset by name
./build/cdirnuts --preset my_template
# Remove a preset
./build/cdirnuts --preset remove my_templatePresets are stored in the path specified by the CDIRNUTS_DIR_PATH environment variable or default to ./.
CDirNuts provides a comprehensive Lua API for creating custom project structures. See LUA_API.md for complete documentation.
-- Create a simple project with custom structure
-- Get current working directory
local cwd = cdirnuts.getCWD()
-- Allocate directories
local project = cdirnuts.create_virtual_dir(cwd .. "/my_app")
local src = cdirnuts.create_virtual_dir(cwd .. "/my_app/src")
-- Create files
local mainFile = cdirnuts.create_virtual_file(
cwd .. "/my_app/src/main.c",
"#include <stdio.h>\n\nint main() {\n printf(\"Hello!\\n\");\n return 0;\n}\n"
)
-- Build the structure
cdirnuts.append_file(src, mainFile)
cdirnuts.append_subdir(project, src)
-- Create on filesystem
cdirnuts.write_virtual_dir(project)- Directory Management:
create_virtual_dir(),write_virtual_dir(),append_subdir() - File Operations:
create_virtual_file(),write_virtual_file(),append_file() - Utilities:
getCWD(),execute_shell_command()
See default_init.lua in the repository for a complete working example.
--help: Display help message and usage information--config <file>: Alias for--lua(legacy support)--preset list: List all saved presets--preset add <name> <path>: Add a new preset--preset remove <name>: Remove a preset--preset <name>: Use a saved preset
./build/cdirnutsCreates a standard C project structure using the built-in default_init.lua script.
./build/cdirnuts --config default_init.luaRuns the provided default_init.lua script to create a custom project with:
- Interactive project name prompt
- Multiple directories (src, include, tests)
- CMakeLists.txt configuration
- Custom file templates
# Create a custom Lua template
cat > my_template.lua << 'EOF'
local cwd = cdirnuts.getCWD()
local project = cdirnuts.create_virtual_dir(cwd .. "/microservice")
-- ... add your custom structure
cdirnuts.write_virtual_dir(project)
EOF
# Save as preset
./build/cdirnuts --preset add microservice my_template.lua
# Use it anytime
./build/cdirnuts --preset microserviceCDirNuts is built with a modular architecture:
-
Core Modules (
src/):main.c- Entry point and CLI argument parsingdir.c- Directory creation and managementpath.c- Path parsing and manipulationconfig.c- Command execution utilitieslua_embed.c- Lua API bindingspreset.c- Preset storage and retrievallog.c- Logging functionalityinit.c- Default project initialization
-
Headers (
include/): Public API declarations -
Build System: CMake with vcpkg for dependency management
CDirNuts includes a comprehensive test suite using Google Test (GTest).
# Build the project with tests (testing is enabled by default)
cmake --preset vcpkg
cmake --build build
# Run tests using CTest
cd build
ctest --output-on-failure
# Or run the test executable directly
./build/cdirnuts_testsThe test suite includes:
- File System Tests (
test_fs.cpp): Path manipulation, file/directory creation, nested structures - Preset Tests (
test_presets.cpp): Preset management, save/load operations, edge cases - Lua Engine Tests (
test_lua.cpp): Lua API bindings, script execution, error handling
All 48 tests verify core functionality and ensure reliability across different scenarios.
See tests/README.md for more information about the test suite.
- Fork the repository
- Create a feature branch (
git checkout -b feat/amazing-feature) - Make your changes
- Test thoroughly (build and run tests)
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feat/amazing-feature) - Submit a pull request
This project is open source. See LICENSE file for details.
- Lua API Documentation - Complete reference for the Lua scripting API
- Default Script - Fully commented example demonstrating all features
For issues, questions, or contributions, please visit the GitHub repository.