Skip to content

CLI --base-dir flag is silently ignored in generate command #1168

@alexgorbatchev

Description

@alexgorbatchev

Bug Description

The --base-dir / -b CLI flag on the generate command is silently ignored. The flag is accepted without error but has no effect on the output directory.

Root Cause

In src/cli/index.ts:180, the Commander.js option is defined as:

.option("-b, --base-dir <paths>", "Base directories to generate files (comma-separated for multiple paths)")

Commander.js camelCases --base-dir to baseDir, but the action handler at src/cli/index.ts:209 reads options.baseDirs (plural):

.action(async (options) => {
    await generateCommand({
        // ...
        baseDirs: options.baseDirs,  // ← always undefined, should be options.baseDir
        // ...
    });
});

Since options.baseDirs is always undefined, the value falls through to the config file's baseDirs or the default [process.cwd()] at src/config/config-resolver.ts:141:

baseDirs: baseDirs ?? configByFile.baseDirs ?? getDefaults().baseDirs,

Additional Issue

Even if the property name were fixed, the option at src/cli/index.ts:180 lacks a value parser to split comma-separated paths into an array (unlike --features which has one). So it would pass a single string instead of string[] to ConfigResolver.resolve().

Steps to Reproduce

rulesync generate --targets claudecode --features '*' --base-dir "./some-dir" --verbose

Observe in verbose output:

[rulesync] ℹ Base directories: /current/working/dir

The base directory is always cwd, regardless of what --base-dir is set to.

Expected Behavior

The --base-dir flag should override baseDirs from the config, and the specified directory should be used as the output base directory.

Suggested Fix

In src/cli/index.ts, change:

baseDirs: options.baseDirs,

to:

baseDirs: options.baseDir ? options.baseDir.split(",").map((p) => p.trim()) : undefined,

Environment

  • rulesync: 7.6.3
  • Node.js: v22.12.0
  • OS: macOS (Darwin 25.2.0)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions