yini-cli 1.3.4 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,11 @@
1
1
  export const descriptions = {
2
2
  yini: 'The official terminal / command-line (CLI) for parsing and validating YINI configuration files.',
3
3
  'For-command-parse': 'Parse a YINI file (*.yini) and output the result as JSON or JavaScript.',
4
- 'For-command-validate': 'Validate a YINI file and print a validation report.',
4
+ 'For-command-validate': `Validate one or more YINI files.
5
+
6
+ <file> Validate a single file.
7
+ <directory> Validate all .yini files in the directory.
8
+
9
+ You can provide multiple files and directories, separated by spaces.`,
5
10
  'For-command-info': 'Display extended information about the YINI CLI environment.',
6
11
  };
@@ -8,7 +8,7 @@ import { getPackageName, getPackageVersion } from '../utils/yiniCliHelpers.js';
8
8
  */
9
9
  export const getHelpTextBefore = () => {
10
10
  return `${getPackageName()} ${getPackageVersion()}
11
- YINI CLI (Yet another INI)
11
+ YINI CLI (by the YINI-lang project)
12
12
 
13
13
  The official terminal / command-line (CLI) for parsing and validating YINI
14
14
  configuration files. A config format, inspired by INI, with type-safe values,
@@ -28,7 +28,8 @@ Quick Examples:
28
28
  $ yini parse file.yini --json
29
29
  $ yini parse file.yini --js
30
30
  $ yini parse file.yini -o output.json
31
- $ yini validate --strict config.yini
31
+ $ yini validate config.yini --stats
32
+ $ yini validate . --strict
32
33
 
33
34
  For help with a specific command, use -h or --help. For example:
34
35
  $ yini validate --help
@@ -40,11 +41,13 @@ Example YINI configuration file (config.yini)
40
41
  title = 'My App'
41
42
  items = 10
42
43
  debug = ON
44
+ tags = ['web', 'demo', 'prod']
43
45
 
44
46
  ^ Server
45
- host = 'localhost'
46
- port = 8080
47
+ host = 'localhost'
48
+ port = 8080
47
49
  useTLS = OFF
50
+ limits = { timeout: 30, keepAlive: true }
48
51
 
49
52
  // Sub-section of Server.
50
53
  ^^ Login
@@ -52,10 +55,10 @@ Example YINI configuration file (config.yini)
52
55
  password = 'secret'
53
56
  ========================================================
54
57
 
55
- More info:
58
+ More information:
56
59
  https://github.com/YINI-lang/yini-cli
57
60
 
58
- YINI homepage:
61
+ Homepage:
59
62
  https://yini-lang.org
60
63
  `;
61
64
  };
package/dist/index.js CHANGED
@@ -2,13 +2,13 @@
2
2
  //
3
3
  // (!) IMPORTANT: Leave the top shebang as the very first line! (otherwise command will break)
4
4
  //
5
- // index.ts
5
+ // src/index.ts
6
6
  import { createRequire } from 'module';
7
- import { Command } from 'commander';
7
+ import { Command, Option } from 'commander';
8
8
  import { enableHelpAll } from './cli/helpAll.js';
9
9
  import { printInfo } from './commands/infoCommand.js';
10
10
  import { parseFile } from './commands/parseCommand.js';
11
- import { validateFile, } from './commands/validateCommand.js';
11
+ import { validateTargets, } from './commands/validateCommand.js';
12
12
  import { isDebug, isDev } from './config/env.js';
13
13
  import { descriptions as descr } from './descriptions.js';
14
14
  import { getHelpTextAfter, getHelpTextBefore, } from './globalOptions/helpOption.js';
@@ -43,20 +43,21 @@ const program = new Command()
43
43
  .description(descr.yini)
44
44
  // Below will replace all auto-registered items (especially the descriptions starting with a capital and ending with a period).
45
45
  .version(getPackageVersion(), '-v, --version', 'Display the version number.')
46
- .helpOption('-h, --help', 'Display full help for all commands.')
46
+ .helpOption('-h, --help', 'Display full help for all commands.') // Yes, shows help for ALL commands via the enableHelpAll() function.
47
47
  .helpCommand('help <command>', 'Display help for a specific command.');
48
48
  program.addHelpText('before', getHelpTextBefore());
49
49
  program.addHelpText('after', getHelpTextAfter());
50
50
  /**
51
- * The (main/global) option: "--strict, --quite, --silent"
51
+ * The (main/global) options: "--strict, --quiet, --silent"
52
52
  */
53
53
  // Suggestions for future: --verbose, --debug, --no-color, --color, --timing, --stdin
54
54
  program
55
55
  .option('--strict', 'Enable strict parsing mode.')
56
+ .option('--lenient', 'Use lenient mode (this is the default).')
56
57
  // .option('-f, --force', 'Continue parsing even if errors occur.')
57
- .option('-q, --quiet', 'Reduce output (show only errors).')
58
- .option('-s, --silent', 'Suppress all output (even errors, exit code only).')
59
- .option('--verbose', 'Display extra information.')
58
+ .option('-q, --quiet', 'Suppress successful per-file output; still show failures and final summary.')
59
+ .option('-s, --silent', 'Suppress validation output and use exit code only.')
60
+ .option('--verbose', 'Show extra processing details.')
60
61
  .action((options) => {
61
62
  debugPrint('Run global options');
62
63
  if (isDebug()) {
@@ -78,7 +79,7 @@ const parseCmd = program
78
79
  .option('--yaml', 'Output as YAML.')
79
80
  .option('--xml', 'Output as XML.')
80
81
  // File handling options.
81
- .option('-o, --output <file>', 'Write output to <file>. By default, an existing file is only overwritten if it is older than the input YINI file.')
82
+ .option('-o, --output <file>', 'Write output to <file>. By default, an existing output file is only overwritten if it is older than the input YINI file.')
82
83
  .option('--overwrite', 'Always overwrite the output file, even if it is newer than the input YINI file.')
83
84
  .option('--no-overwrite', 'Fail if the output file already exists.')
84
85
  // Behavior options.
@@ -88,10 +89,6 @@ const parseCmd = program
88
89
  .action((file, options) => {
89
90
  const globals = program.opts(); // Global options.
90
91
  const mergedOptions = { ...globals, ...options }; // Merge global options with per-command options.
91
- if (mergedOptions.js && mergedOptions.compact) {
92
- console.error('Error: --js and --compact cannot be combined.');
93
- process.exit(1);
94
- }
95
92
  debugPrint('Run command "parse"');
96
93
  debugPrint('isDebug(): ' + isDebug());
97
94
  debugPrint('isDev() : ' + isDev());
@@ -104,33 +101,54 @@ const parseCmd = program
104
101
  });
105
102
  appendGlobalOptionsTo(parseCmd);
106
103
  /**
107
- * The command: "validate <file>"
104
+ * The command: "validate <fileOrDirectory...>"
108
105
  */
109
106
  const validateCmd = program
110
- .command('validate <file>')
107
+ .command('validate <fileOrDirectory...>')
111
108
  .description(descr['For-command-validate'])
112
- .option('--stats', 'Include a statistics section (e.g., key count, nesting depth, etc.).')
113
- // .option(
114
- // '--details',
115
- // 'Print detailed validation info (e.g., line locations, error codes, descriptive text, etc.).',
116
- // )
117
- .action((file, options) => {
118
- const globals = program.opts(); // Global options.
119
- const mergedOptions = { ...globals, ...options }; // Merge global options with per-command options.
120
- debugPrint('Run command "parse"');
109
+ // ─────────────────────────────
110
+ // Reporting / behavior
111
+ // ─────────────────────────────
112
+ .option('--warnings-as-errors', 'Treat warnings as errors for exit code purposes.')
113
+ .option('--stats', 'In text mode, stats only shown when file mode validates exactly one file.')
114
+ .addOption(new Option('--format <type>', 'Output format for validation results: text | json')
115
+ .choices(['text', 'json'])
116
+ .default('text'))
117
+ // Execution controls (nice-to-have)
118
+ .option('--fail-fast', 'Stop after first file that fails validation.')
119
+ .option('--max-errors <n>', 'Stop after N total errors (across files).', (v) => {
120
+ const n = Number.parseInt(v, 10);
121
+ if (!Number.isFinite(n) || n < 1) {
122
+ throw new Error('--max-errors must be a positive integer.');
123
+ }
124
+ return n;
125
+ })
126
+ // ─────────────────────────────
127
+ // Input handling
128
+ // ─────────────────────────────
129
+ // Default: recursive (so only expose the negated option)
130
+ .option('--no-recursive', 'Do not scan subdirectories.')
131
+ // ─────────────────────────────
132
+ // Output handling - WAIT WITH THESE
133
+ // ─────────────────────────────
134
+ // .option('-o, --output <file>', 'Write validation report to file.')
135
+ // .option('--overwrite', 'Allow overwriting an existing output file.')
136
+ // .option('--no-overwrite', 'Prevent overwriting an existing output file.')
137
+ .action((fileOrDirectories, options) => {
138
+ const globals = program.opts();
139
+ const mergedOptions = { ...globals, ...options };
140
+ debugPrint('Run command "validate"');
121
141
  debugPrint('isDebug(): ' + isDebug());
122
- debugPrint('isDev() : ' + isDev());
123
- debugPrint(`<file> = ${file}`);
142
+ debugPrint('isDev(): ' + isDev());
143
+ // console.log('options:')
144
+ // console.log(options)
124
145
  if (isDebug()) {
125
146
  console.log('mergedOptions:');
126
147
  console.log(toPrettyJSON(mergedOptions));
127
148
  }
128
- if (file) {
129
- validateFile(file, mergedOptions);
130
- }
131
- else {
149
+ if (!fileOrDirectories?.length)
132
150
  program.help();
133
- }
151
+ validateTargets(fileOrDirectories, mergedOptions);
134
152
  });
135
153
  appendGlobalOptionsTo(validateCmd);
136
154
  /**
@@ -150,4 +168,6 @@ appendGlobalOptionsTo(infoCmd);
150
168
  // NOTE: Converting YINI files to other formats than json and js.
151
169
  // Other format should go into a new CLI-command called 'yini-convert' to not let this command grow too large.
152
170
  enableHelpAll(program);
153
- program.parseAsync();
171
+ // program.parseAsync()
172
+ const normalizedArgv = process.argv.map((arg) => arg === '--no-subdirs' ? '--no-recursive' : arg);
173
+ program.parseAsync(normalizedArgv);
@@ -1,3 +1,4 @@
1
+ // src/utils/string.ts
1
2
  export const toColRow = (size, label, value) => {
2
3
  return `${label.padEnd(size)} ${value}`;
3
4
  };
@@ -0,0 +1,130 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.5.0 - 2026 June
4
+ - Bumped dependency `yini-parser` to `^1.6.0` with YINI Specification RC 6 parser support, which brings:
5
+ - Improved parser diagnostics and structured issue reporting.
6
+ - Support for the latest **RC 6** mode-declaration behavior.
7
+ - Improved handling of duplicate sections and duplicate keys.
8
+ - Improved section marker parsing, including marker separators.
9
+ - Improved string concatenation validation.
10
+ - Improved EOF handling for files without a final trailing newline.
11
+ - And more.
12
+
13
+ - **Improved:** Included `docs/CHANGELOG.md` in the package.
14
+ - Fixed CLI parse error reporting so parse failures are printed by `yini-cli` instead of relying on the parser library to write diagnostics directly to `stderr`.
15
+ - Updated validation behavior to support the newer parser diagnostics model, including `passed-with-warnings` results for valid files that produce warnings.
16
+ - Updated tests and fixtures for the newer parser behavior, including coverage for valid files without a final newline at EOF.
17
+ - Confirmed that `yini-cli` remains quiet by default for JSON validation output, while text-mode validation still reports user-facing diagnostics where appropriate.
18
+
19
+ ## 1.4.0 - 2026 Apr
20
+ - Bumped dependency `yini-parser` to `^1.5.0` which brings:
21
+ - **Updated** to match **YINI Specification RC.5**: includes synced grammar files and the latest section-header parsing rules.
22
+ - **Stricter**, more predictable strict mode: now requires exactly one explicit top-level section and a closing `/END` terminator.
23
+ - **Improved** parser reliability overall: better handling of null/empty values, cleaner `throwOnError` behavior, and expanded validation and test coverage.
24
+ - **Added:** New `validate` command.
25
+ ```txt
26
+ Validate one or more YINI files.
27
+
28
+ <file> Validate a single file.
29
+ <directory> Validate all .yini files in the directory.
30
+
31
+ You can provide multiple files and directories, separated by spaces.
32
+
33
+ Options:
34
+ --warnings-as-errors Treat warnings as errors for exit code purposes.
35
+ --stats In text mode, stats only shown when file mode validates exactly one file.
36
+ --format <type> Output format for validation results: text | json (choices: "text", "json",
37
+ default: "text")
38
+ --fail-fast Stop after first file that fails validation.
39
+ --max-errors <n> Stop after N total errors (across files).
40
+ --no-recursive Do not scan subdirectories.
41
+ -h, --help Display full help for all commands.
42
+ ```
43
+ - **Changed:** The short flag for strict mode is now `-S` (capital). Lowercase `-s` is now reserved for `--silent`, which aligns better with common CLI conventions.
44
+ - **Improved:** Improved the usability of the `parse` command.
45
+ - **Improved:** Test fixtures and CLI tests were reorganized for better clarity, separation, and Windows-safe argument handling.
46
+
47
+ ## 1.3.4 - 2026 Apr
48
+ - **Promoted** YINI CLI is now considered stable (non-beta) after iterative beta releases and refinements.
49
+ - **Fixed:** Rebuilt the project and reduced reported from 9 vulnerabilities (5 moderate, 4 high) to 0.
50
+ - **Updated:** Bumped dependency `yini-parser` to `^1.4.3`.
51
+
52
+ ## 1.3.4-beta - 2026 Mar
53
+ - **Updated:** Bumped dependency `yini-parser` to `^1.4.3-beta` that consists of:
54
+ - Fixed: Error messages and thrown parse errors now include correct line and column information again.
55
+ - Improved: Syntax and string-related parse errors are now clearer and more consistent.
56
+ - Improved: Reduced some duplicate follow-up errors during recovery after invalid input.
57
+
58
+ ## 1.3.3-beta - 2026 Mar
59
+ - **Updated:** Bumped dependency `yini-parser` to `^1.4.2-beta`.
60
+
61
+ ## 1.3.2-beta - 2026 Mar
62
+ - **Updated:** Bumped dependency `yini-parser` to `^1.4.1-beta`.
63
+ - **Fixed:** `parse` now returns a non-zero exit code for invalid input that does not produce usable parsed output.
64
+ - **Improved:** Better alignment with the latest parser diagnostics and recovery behavior.
65
+ - **Improved:** `parse` command file output behavior.
66
+ - Added fast pre-check to skip parsing when the destination is newer than the source.
67
+ - Centralized output write policy and skip detection.
68
+ - **Improved:** Avoid unnecessary file rewrites when generated output is unchanged.
69
+
70
+ ## 1.3.1-beta - 2026 Mar
71
+ - **Improved:** `parse` command file write policy.
72
+ - Destination files newer than the source are now **skipped with a warning** instead of causing an error.
73
+ - Helps prevent unnecessary build failures in CI pipelines and static site generators (e.g. Astro).
74
+ - **Improved:** Output files are only rewritten when the generated content has actually changed, reducing redundant file writes.
75
+
76
+ ## 1.3.0-beta - 2026 Mar
77
+ - **Updated:** Bumped dependency `yini-parser` to `^1.4.0-beta`.
78
+ - **Added:** CLI now supports parsing/validating **Classic (C) strings** (escape sequences) via the updated parser.
79
+ - **Note:** Default (raw) strings are unchanged (backslashes `\` and `\n` remain as-is unless using `c"..."` / `C'...'`).
80
+ - **Added:** New output formats for the `parse` command:
81
+ - `--yaml` to export parsed data as **YAML**
82
+ - `--xml` to export parsed data as **XML**
83
+ - **Refactored:** Output format handling internally to improve robustness, simplify debugging, and make the code easier to test and maintain.
84
+
85
+ ## 1.2.1-beta - 2026 Feb
86
+ - **Improved:** `validate` command:
87
+ - Strengthened `validate` command diagnostics handling and metadata guards.
88
+ - Replaced unsafe internal assertions with controlled error handling.
89
+ - Improved silent mode behavior and exit code consistency.
90
+
91
+ ## 1.2.0-beta - 2026 Feb
92
+ - **Improved:** Updated `--help` to display full help for all commands, while preserving command-specific help through `yini help <command>`.
93
+ - **Changed:** Showing extended information now uses the `info` command only. The global `--info` option has been removed — please use `yini info` instead.
94
+ - **Updated:** `parse` command:
95
+ - Deprecated `--pretty` (JSON is now the default; use `--json` explicitly if desired).
96
+ - `--compact` now outputs compact JSON (no whitespace).
97
+ - Added `--js` option to output JavaScript-style objects.
98
+ - Improved `--output` file handling:
99
+ - By default, the output file is written only if it does not exist or is older than the source YINI file.
100
+ - Added `--overwrite` to always replace existing files.
101
+ - Added `--no-overwrite` to prevent replacing existing files.
102
+
103
+ ## 1.1.1-beta - 2025 Dec
104
+ - **Updated:** Updated to use the latest YINI Parser version `1.3.2-beta` from `1.3.0-beta`.
105
+
106
+ ## 1.1.0-beta - 2025 Sep
107
+ - **New command:** New command `validate` to validate parsing of a YINI file.
108
+ - **Added** --strict as global option, to enable parsing in strict mode.
109
+ - **Added** -q, --quiet as global option, to reduce output (show only errors).
110
+ - **Added** --silent as global option, will suppress all output (even errors, exit code only).
111
+ - **CI/Tooling (GitHub Actions):** Added security and quality checks:
112
+ - **Security:** CodeQL, dependency checke (`npm audit`) + lockfile-lint, Gitleaks (SARIF), Semgrep (SARIF).
113
+ - **CI CLI test**.
114
+ - **Regression tests:** run across a Node/OS matrix.
115
+ - **Releases:** npm publish with provenance (tag-driven).
116
+ - Removed per-command --strict flags.
117
+
118
+ ## 1.0.3-beta - 2025 Sep
119
+ - **Updated:** Now uses latest `yini-parser` library `v1.1.0-beta`, for greatly improved parsing, compatibility, and error handling with more descriptive and accurate error messages.
120
+
121
+ ## 1.0.2-beta - 2025 Aug
122
+ - Bumped internal YINI Parser library to version 1.0.2-beta, which fixes and improves number parsing to fully support negative values and edge cases for integers, floats, hexadecimal, binary, octal, duodecimal, and exponential numbers.
123
+ - Added this file into the repo.
124
+
125
+ ---
126
+
127
+ **^YINI ≡**
128
+ > A simple, structured, and human-friendly configuration format.
129
+
130
+ [yini-lang.org](https://yini-lang.org) · [YINI on GitHub](https://github.com/YINI-lang)
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "yini-cli",
3
- "version": "1.3.4",
4
- "description": "Official YINI CLI for validating, parsing, and converting a human-friendly config format with real structure, nested sections, and predictable strict or lenient parsing.",
3
+ "version": "1.5.0",
4
+ "description": "Official command-line tool for validating and converting YINI files — YINI is an INI-inspired, human-readable configuration format with explicit structure and predictable parsing.",
5
5
  "keywords": [
6
6
  "yini",
7
7
  "cli",
@@ -26,19 +26,20 @@
26
26
  }
27
27
  },
28
28
  "bin": {
29
- "yini": "./dist/index.js"
29
+ "yini": "dist/index.js"
30
30
  },
31
31
  "homepage": "https://yini-lang.org/",
32
32
  "license": "Apache-2.0",
33
33
  "files": [
34
34
  "dist/",
35
35
  "README.md",
36
+ "docs/CHANGELOG.md",
36
37
  "LICENSE",
37
38
  "sample.yini"
38
39
  ],
39
40
  "repository": {
40
41
  "type": "git",
41
- "url": "https://github.com/YINI-lang/yini-cli.git"
42
+ "url": "git+https://github.com/YINI-lang/yini-cli.git"
42
43
  },
43
44
  "private": false,
44
45
  "scripts": {
@@ -51,7 +52,7 @@
51
52
  "run:parse": "npm run start -- parse sample.yini",
52
53
  "run:validate": "npm run start -- validate sample.yini",
53
54
  "test:smoke": "vitest tests/smoke",
54
- "test:general": "vitest tests/general",
55
+ "test:general": "vitest tests/global-options.test.ts",
55
56
  "test": "vitest run",
56
57
  "test:debug": "cross-env isDebug=1 vitest run --reporter=verbose",
57
58
  "test:general:debug": "cross-env isDebug=1 npm run test:general",
@@ -63,7 +64,7 @@
63
64
  "format": "prettier --check .",
64
65
  "format:fix": "prettier --write .",
65
66
  "build": "tsc",
66
- "clean": "rm -rf dist",
67
+ "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\"",
67
68
  "prepare": "npm run build",
68
69
  "prepublishOnly": "npm run lint && npm test && npm run build"
69
70
  },
@@ -72,12 +73,12 @@
72
73
  "commander": "^14.0.1",
73
74
  "xmlbuilder2": "^4.0.3",
74
75
  "yaml": "^2.8.2",
75
- "yini-parser": "^1.4.3"
76
+ "yini-parser": "^1.6.0"
76
77
  },
77
78
  "devDependencies": {
78
79
  "@eslint/js": "^9.31.0",
79
80
  "@ianvs/prettier-plugin-sort-imports": "^4.4.2",
80
- "@types/node": "^22.15.3",
81
+ "@types/node": "^22.19.19",
81
82
  "@typescript-eslint/eslint-plugin": "^8.37.0",
82
83
  "@typescript-eslint/parser": "^8.37.0",
83
84
  "cross-env": "^7.0.3",
@@ -87,7 +88,7 @@
87
88
  "execa": "^9.6.0",
88
89
  "husky": "^9.1.7",
89
90
  "lint-staged": "^16.0.0",
90
- "nyc": "^17.1.0",
91
+ "nyc": "^18.0.0",
91
92
  "prettier": "^3.5.3",
92
93
  "tsx": "^4.7.0",
93
94
  "typescript": "^5.8.3",
@@ -95,10 +96,10 @@
95
96
  },
96
97
  "lint-staged": {
97
98
  "src/**/*.{js,jsx,json,ts,tsx,css,scss}": [
98
- "prettier --config ./.prettierrc --write"
99
+ "prettier --config ./prettier.config.cjs --write"
99
100
  ]
100
101
  },
101
102
  "engines": {
102
- "node": ">=13"
103
+ "node": ">=18"
103
104
  }
104
105
  }