Search by

sy / genini

syone

Command line INI file generator.

1.1.1 2026-11-29 18:07 UTC

This package is auto-updated.

Last update: 2026-11-30 08:36:24 UTC


README

Command line INI file generator: it asks a series of questions on the terminal and writes the answers as key = value lines.

Installation

composer require sy/genini

Composer exports the genini script as vendor/bin/genini.

Usage

vendor/bin/genini '<json>'

The single argument is a JSON object describing the file to create. The file path is resolved against the current directory, so call it from the project root (an absolute path works too).

Key Required Content
file yes path of the INI file to create
input yes, non empty ordered map name => { question, default }

Each input entry produces one line of the file:

  • question — the prompt printed on the terminal; the key name is used when it is absent;
  • default — the value used when the answer is empty (or when the entry declares no default).

Keys are written in the order of the input object, values are written verbatim (never quoted nor escaped), and the file has no section header: it is flat, one key = value per line, which is what the framework INI reader expects.

Behaviour

Situation Message Exit code
file created <file> created successfully! 0
file already exists INI file already exists 0
no argument Missing command line argument 1
file absent from the JSON INI file parameter not defined 1
input absent or empty INI file input parameter not defined 1
write failure Write file error! 2 — PHP also warns on stderr (file_put_contents(): Failed to open stream)

An existing file is never read nor written: the script stops at once with exit 0, which makes the call idempotent and safe on every install.

A terminal is required. Answers are read with readline(), which writes its prompt to the terminal and returns an empty string when stdin is not a TTY — the prompts do not even reach a captured pipe, only the banner does (the banner is written with ANSI colour escapes). Without a terminal every answer is empty, so every value falls back to its default and a file of empty values is created (the incident behind C64). A wrapper must therefore keep the terminal attached: sy install passes tty: true to its command runner for exactly this reason.

Example

vendor/bin/genini '{"file":"protected/conf/database.ini","input":{"host":{"question":"MySQL hostname"},"port":{"question":"MySQL port","default":"3306"},"password":{"question":"Database password"}}}'

    Welcome to the INI file generator

This command will guide you through creating your protected/conf/database.ini file.

MySQL hostname []: db.local
MySQL port [3306]:
Database password []: s3cret

protected/conf/database.ini created successfully!

protected/conf/database.ini:

host = db.local
port = 3306
password = s3cret

An empty answer takes the default, so MySQL port [3306] left blank writes port = 3306.

Used by

sy/bootstrap ships bin/sy, which reads extra.sy.ini from a project composer.json and calls vendor/bin/genini once for each declared file that is missing, passing the input map as JSON and keeping the terminal attached. Once the files exist, bin/sy runs the extra.sy.install commands; on the next composer install every file is present, so genini is not called at all.