Status:
tngis currently under active development (WIP).
We are actively shaping the core architecture, and contributions of any size are highly welcome and appreciated.
If you would like to help improvetng, please check out the Contributing section below.
tng is currently under heavy development.
The public API, configuration format, and internal architecture may change between versions.
tng stands for touch 'N generate.
It is a command-line tool designed to create "ready-to-use" programming files by:
- creating files if they do not exist, and
- filling them with configurable boilerplate text (headers, license, metadata, etc.)
based on file name and file extension.
The goal is to make it easy to:
- standardize file headers and licenses,
- keep comments and structure consistent across a project,
- avoid manually copying boilerplate into each new source file.
tng operates on a set of target files and a configuration file.
At a high level, for each target file:
- If the file does not exist,
tngcreates it (similar totouch). tngreads a configuration file (e.g.tng.conf) that defines:- how to comment generated text,
- where to find the license,
- what header/footer text to insert,
- how to behave per file extension.
- Based on the file extension (e.g.
cpp,h,c,txt, etc.),tngselects a matching configuration section. - It then generates a buffer (header, license, metadata, footer) and writes it into the file according to the rules in the configuration.
If no matching section for a specific extension is found, tng falls back to a [GLOBAL] section (if defined).
tng file1.txt file2.txt -c /PATH/TO/CONFIG_FILE/tng.conftngchecksfile1.txtandfile2.txt:- if a file does not exist, it will be created.
tngreads the configuration file:-c /PATH/TO/CONFIG_FILE/tng.conf
- If the configuration defines behavior for
.txtfiles,tnguses that section to:- determine comment style,
- determine how to insert license text,
- decide which header/footer text to use.
For instance, if in the config we have:
[txt]
comment = YES
line_prefix = "//"
license_path = "/home/username/license-file/"and a license file like:
HERE IS LICENSE FILEthen the resulting file1.txt / file2.txt could look like:
// HERE IS LICENSE FILE CONTENT(The exact content depends on the header_text, footer_text, comment style, and other options defined in the configuration.)
tng uses a configuration file (for example tng.conf) to define behavior per extension and a global fallback.
Below is a simplified version of the example you provided, with explanations.
- For boolean variables you can use
<YES>or<NO>as aliases for<true>or<false>(btw: also you can now useyesorno). - Paths must be absolute. Relative (non-absolute) paths are not allowed.
- Use triple quotes
"""for multi-line string values. - Sections are declared using
[section_name].
For example:[cpp, c, cc, hpp, h]defines a section that applies to multiple extensions.[GLOBAL]defines fallback behavior for files whose extension does not match any other section.
[cpp, c, cc, hpp, h]
####################################
############## Policy ##############
# First we have buffer setup.
# define buffer writted with comment
# define comment element's
# define license path
#
# Use comment for all tng generated text for files
comment = YES
comment_style = block # block or line
overwrite_existing_file = YES
# Each element of comment for multi-line comment or liner comment
# In this example we have
#
# // Line
#
# /*
# * Non-liner or Block comment
# */
#
line_prefix = "//"
block_header = "/*"
block_line_prefix = " * "
block_footer = " */"
# Include license file in project
include_license = YES
# Locate license path
license_path = "/home/exampleUserName/license-file/"
# TODO: use PWD in here
# -> license_path = "PWD/license/"
# Pre configed
include_license_before_header = YES
space_between_header_footer = 4
####################################
############## Layout ##############
header_text = """
Project by : Ilia Abolghasemy (aka: gfaerny, Iliya Abolghasemi)
"""
footer_text="""
Copyright by Ilia Abolghasemy
"""[GLOBAL]
# This section is used when no per-extension section matches.
# You can define default comment style, header/footer, and license handling here.Behavior note:
When tng processes a file:
- It tries to find a section matching that file’s extension (for example
[cpp, c, cc, hpp, h]). - If none match, it falls back to
[GLOBAL](if defined). - If neither a specific extension section nor
[GLOBAL]exists, behavior is undefined (or will result in an error, depending on implementation).
tng uses a structured error system defined in error.hpp.
Throughout the codebase, you may see comments like:
// TODO: throw errorThese mark places where proper error reporting should be implemented using the error API.
- Error codes and categories are defined as enums (for example
ErrorCode,ParserError, etc.) inerror.hpp. - An error object (exception type) is constructed using these enums.
- Errors are thrown instead of using raw strings or ad-hoc mechanisms.
The process to implement these TODOs is:
-
Locate error definitions
Open:
include/tng/error.hpp(Or the corresponding header in your tree.) This file defines:
- error codes (enums),
- error categories,
- error classes / exception types,
- helper functions or factories, if any.
-
Add a new error code (if needed)
If the scenario is not covered by any existing error code, add a new enumerator to the appropriate enum, following the existing naming conventions.
Example:
enum class error_type { cannot_open_create_file, expected_file_n_find, file_does_n_exist, arg_expected_argument, c_array_dn_more, c_more_less_symbol_EFNS, c_no_config_file_select, c_cant_select_multi_conf };
-
Replace
// TODO: throw errorwith a proper throwFor example, instead of:
// TODO: throw error this config probelm. no file selected for configyou might write:
throw tng_error{.error_type_o = error_type::c_no_config_file_select, .error_massage = {"no file selected for config"}};
We welcome contributions to tng. The project is under active development and there are many areas where you can help:
- implementing missing error handling (
// TODO: throw error), - extending configuration features,
- improving documentation and examples,
- adding tests for configuration parsing and file generation.
The easiest way to get started is to search for:
// TODO:
in the codebase. Many of these are intentionally left as entry points for contributors.
Examples of current TODO categories:
// TODO: throw error
Implement error handling using the structured error API inerror.hpp.// TODO: use PWD in here
Improve path handling to optionally supportPWD-based relative paths.// TODO: Did we have to write modifie analyzer ...
Design and implement logic for deciding when generated buffers should be rewritten.
tng is a under BSD license.
Please refer to the LICENSE file in the repository for the exact license terms.