Skip to content

Commit 8b34bcf

Browse files
committed
feat: replace in file multiples paths
1 parent a34da03 commit 8b34bcf

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/commands/replace-in-file/index.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ export default class ReplaceInFile extends Command {
3030
required: true,
3131
multiple: true,
3232
}),
33-
path: Flags.string({
33+
paths: Flags.string({
3434
char: 'p',
35-
description: 'path of file',
35+
description: 'paths of files',
3636
required: true,
37+
multiple: true,
3738
}),
3839
from: Flags.string({
3940
char: 'f',
@@ -50,16 +51,23 @@ export default class ReplaceInFile extends Command {
5051
}
5152

5253
async run(): Promise<void> {
53-
const {flags: {organization, repositories, path, from, to}} = await this.parse(ReplaceInFile)
54+
const {flags: {organization, repositories, paths, from, to}} = await this.parse(ReplaceInFile)
5455
validateRepoNames(repositories)
5556
const octoFactory = repositoryFactory.get('octokit')
5657
for (const repo of repositories) {
57-
console.log(info(`Read File ${path} in ${repo}`))
58-
const response = await octoFactory.readFile({owner: organization, repo, path})
59-
const data = atob(response.data.content)
60-
console.log(data)
61-
const infonew = btoa(data.replace(from, to))
62-
await octoFactory.writeFile({owner: organization, repo, path, content: infonew})
58+
for (const path of paths) {
59+
console.log(info(`Read File ${path} in ${repo}`))
60+
const response = await octoFactory.readFile({owner: organization, repo, path})
61+
const data = atob(response.data.content)
62+
const infonew = btoa(data.replace(from, to))
63+
await octoFactory.writeFile({owner: organization, repo, path, content: infonew})
64+
console.log(info(`File in ${path}
65+
from:
66+
${data}
67+
to:
68+
${infonew}
69+
in: ${repo}`))
70+
}
6371
}
6472
}
6573
}

0 commit comments

Comments
 (0)