Skip to content

Commit

Permalink
Merge pull request #13 from gmickel/add-inverted-interactive-mode
Browse files Browse the repository at this point in the history
feat(cli): add --invert option for interactive filtering
  • Loading branch information
gmickel authored Jul 21, 2024
2 parents df9a406 + 405c96e commit cdecf46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export function cli(args: string[]) {
'Do not respect entries in .gitignore',
false,
)
.option('--invert', 'Selected files will be excluded', false)
.action(async (options) => {
try {
await interactiveMode(options);
Expand Down
17 changes: 12 additions & 5 deletions src/cli/interactive-filtering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface InteractiveModeOptions {
customIgnores?: string[];
cachePath?: string;
respectGitignore?: boolean;
invert?: boolean;
}

export async function interactiveMode(options: InteractiveModeOptions) {
Expand All @@ -40,12 +41,14 @@ export async function interactiveMode(options: InteractiveModeOptions) {

const userFilters = options.filter || [];

const selectedFiles = await selectFiles(basePath);
const selectedFiles = await selectFiles(basePath, options.invert ?? false);

// Combine user filters with selected files
const combinedFilters = [...new Set([...userFilters, ...selectedFiles])];

console.log(chalk.cyan('Files to be processed:'));
console.log(
chalk.cyan(`Files to be ${options.invert ? 'excluded' : 'included'}:`),
);
for (const filter of combinedFilters) {
console.log(chalk.cyan(` ${filter}`));
}
Expand All @@ -65,7 +68,8 @@ export async function interactiveMode(options: InteractiveModeOptions) {
const processedFiles = await processFiles({
...options,
path: basePath,
filter: combinedFilters,
filter: options.invert ? undefined : combinedFilters,
exclude: options.invert ? combinedFilters : options.exclude,
});
spinner.succeed('Files processed successfully');

Expand Down Expand Up @@ -104,12 +108,15 @@ export async function interactiveMode(options: InteractiveModeOptions) {
}
}

async function selectFiles(basePath: string): Promise<string[]> {
async function selectFiles(
basePath: string,
invert: boolean,
): Promise<string[]> {
const answer = await inquirer.prompt([
{
type: 'file-tree-selection',
name: 'selectedFiles',
message: 'Select files and directories:',
message: `Select files and directories to be ${invert ? 'excluded' : 'included'}:`,
root: basePath,
multiple: true,
enableGoUpperDirectory: true,
Expand Down

0 comments on commit cdecf46

Please sign in to comment.