Skip to content

Commit

Permalink
Merge pull request #236 from yamadashy/feat/cli-flags
Browse files Browse the repository at this point in the history
feat(cli): Add CLI flags for controlling output sections and content processing
  • Loading branch information
yamadashy authored Dec 31, 2024
2 parents 5821fb1 + 42401bb commit 081c567
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ This format provides a clean, readable structure that is both human-friendly and
- `-i, --ignore <patterns>`: Additional ignore patterns (comma-separated)
- `-c, --config <path>`: Path to a custom config file
- `--style <style>`: Specify the output style (`plain`, `xml`, `markdown`)
- `--no-file-summary`: Disable file summary section output
- `--no-directory-structure`: Disable directory structure section output
- `--remove-comments`: Remove comments from supported file types
- `--remove-empty-lines`: Remove empty lines from the output
- `--top-files-len <number>`: Number of top files to display in the summary
- `--output-show-line-numbers`: Show line numbers in the output
- `--copy`: Additionally copy generated output to system clipboard
Expand Down
12 changes: 12 additions & 0 deletions src/cli/actions/defaultAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ const buildCliConfig = (options: CliOptions): RepomixConfigCli => {
if (options.securityCheck !== undefined) {
cliConfig.security = { enableSecurityCheck: options.securityCheck };
}
if (options.fileSummary !== undefined) {
cliConfig.output = { ...cliConfig.output, fileSummary: options.fileSummary };
}
if (options.directoryStructure !== undefined) {
cliConfig.output = { ...cliConfig.output, directoryStructure: options.directoryStructure };
}
if (options.removeComments !== undefined) {
cliConfig.output = { ...cliConfig.output, removeComments: options.removeComments };
}
if (options.removeEmptyLines !== undefined) {
cliConfig.output = { ...cliConfig.output, removeEmptyLines: options.removeEmptyLines };
}

try {
return repomixConfigCliSchema.parse(cliConfig);
Expand Down
8 changes: 8 additions & 0 deletions src/cli/cliRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export interface CliOptions extends OptionValues {
remote?: string;
remoteBranch?: string;
securityCheck?: boolean;
fileSummary?: boolean;
directoryStructure?: boolean;
removeComments?: boolean; // 追加
removeEmptyLines?: boolean; // 追加
}

export const run = async () => {
Expand All @@ -42,6 +46,10 @@ export const run = async () => {
.option('--top-files-len <number>', 'specify the number of top files to display', Number.parseInt)
.option('--output-show-line-numbers', 'add line numbers to each line in the output')
.option('--style <type>', 'specify the output style (plain, xml, markdown)')
.option('--no-file-summary', 'disable file summary section output')
.option('--no-directory-structure', 'disable directory structure section output')
.option('--remove-comments', 'remove comments')
.option('--remove-empty-lines', 'remove empty lines')
.option('--verbose', 'enable verbose logging for detailed output')
.option('--init', 'initialize a new repomix.config.json file')
.option('--global', 'use global configuration (only applicable with --init)')
Expand Down
152 changes: 152 additions & 0 deletions tests/cli/actions/defaultAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,156 @@ describe('defaultAction', () => {
);
});
});

describe('fileSummary flag', () => {
it('should handle --no-file-summary flag', async () => {
const options: CliOptions = {
fileSummary: false,
};

await runDefaultAction('.', process.cwd(), options);

expect(configLoader.mergeConfigs).toHaveBeenCalledWith(
process.cwd(),
expect.anything(),
expect.objectContaining({
output: {
fileSummary: false,
},
}),
);
});

it('should handle explicit --file-summary flag', async () => {
const options: CliOptions = {
fileSummary: true,
};

await runDefaultAction('.', process.cwd(), options);

expect(configLoader.mergeConfigs).toHaveBeenCalledWith(
process.cwd(),
expect.anything(),
expect.objectContaining({
output: {
fileSummary: true,
},
}),
);
});
});

describe('directoryStructure flag', () => {
it('should handle --no-directory-structure flag', async () => {
const options: CliOptions = {
directoryStructure: false,
};

await runDefaultAction('.', process.cwd(), options);

expect(configLoader.mergeConfigs).toHaveBeenCalledWith(
process.cwd(),
expect.anything(),
expect.objectContaining({
output: {
directoryStructure: false,
},
}),
);
});

it('should handle explicit --directory-structure flag', async () => {
const options: CliOptions = {
directoryStructure: true,
};

await runDefaultAction('.', process.cwd(), options);

expect(configLoader.mergeConfigs).toHaveBeenCalledWith(
process.cwd(),
expect.anything(),
expect.objectContaining({
output: {
directoryStructure: true,
},
}),
);
});
});

describe('removeComments flag', () => {
it('should handle --remove-comments flag', async () => {
const options: CliOptions = {
removeComments: true,
};

await runDefaultAction('.', process.cwd(), options);

expect(configLoader.mergeConfigs).toHaveBeenCalledWith(
process.cwd(),
expect.anything(),
expect.objectContaining({
output: {
removeComments: true,
},
}),
);
});

it('should handle explicit --no-remove-comments flag', async () => {
const options: CliOptions = {
removeComments: false,
};

await runDefaultAction('.', process.cwd(), options);

expect(configLoader.mergeConfigs).toHaveBeenCalledWith(
process.cwd(),
expect.anything(),
expect.objectContaining({
output: {
removeComments: false,
},
}),
);
});
});

describe('removeEmptyLines flag', () => {
it('should handle --remove-empty-lines flag', async () => {
const options: CliOptions = {
removeEmptyLines: true,
};

await runDefaultAction('.', process.cwd(), options);

expect(configLoader.mergeConfigs).toHaveBeenCalledWith(
process.cwd(),
expect.anything(),
expect.objectContaining({
output: {
removeEmptyLines: true,
},
}),
);
});

it('should handle explicit --no-remove-empty-lines flag', async () => {
const options: CliOptions = {
removeEmptyLines: false,
};

await runDefaultAction('.', process.cwd(), options);

expect(configLoader.mergeConfigs).toHaveBeenCalledWith(
process.cwd(),
expect.anything(),
expect.objectContaining({
output: {
removeEmptyLines: false,
},
}),
);
});
});
});

0 comments on commit 081c567

Please sign in to comment.