Skip to content

Commit 6811e85

Browse files
committed
Add force option to pull command
1 parent 67e181e commit 6811e85

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ Qiita 上で更新を行い、手元で変更を行っていない記事ファ
207207
npx qiita pull
208208
```
209209

210+
以下のコマンドで、ローカルの記事を全て同期します。
211+
212+
```console
213+
npm qiita pull --force
214+
```
215+
210216
### version
211217

212218
Qiita CLI のバージョンを確認できます。

src/commands/pull.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@ import { QiitaApi } from "../qiita-api";
77
import { startLocalChangeWatcher, startServer } from "../server/app";
88

99
export const pull = async (argv: string[]) => {
10-
const args = arg({}, { argv });
10+
const args = arg(
11+
{
12+
"--force": Boolean,
13+
},
14+
{ argv }
15+
);
1116

1217
const qiitaApi = await getQiitaApiInstance();
1318
const fileSystemRepo = await getFileSystemRepo();
19+
const isLocalUpdate = args["--force"];
1420

15-
await syncArticlesFromQiita({ fileSystemRepo, qiitaApi });
21+
await syncArticlesFromQiita({ fileSystemRepo, qiitaApi, isLocalUpdate });
1622
console.log("Sync local articles from Qiita");
1723
console.log("Successful!");
1824
};

src/lib/file-system-repo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,9 @@ export class FileSystemRepo {
276276
}
277277
}
278278

279-
async saveItems(items: Item[]) {
279+
async saveItems(items: Item[], isLocalUpdate: boolean = false) {
280280
const promises = items.map(async (item) => {
281-
await this.syncItem(item);
281+
await this.syncItem(item, false, isLocalUpdate);
282282
});
283283

284284
await Promise.all(promises);

src/lib/sync-articles-from-qiita.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import { config } from "./config";
55
export const syncArticlesFromQiita = async ({
66
fileSystemRepo,
77
qiitaApi,
8+
isLocalUpdate = false,
89
}: {
910
fileSystemRepo: FileSystemRepo;
1011
qiitaApi: QiitaApi;
12+
isLocalUpdate?: boolean;
1113
}) => {
1214
const per = 100;
1315
const userConfig = await config.getUserConfig();
@@ -20,6 +22,6 @@ export const syncArticlesFromQiita = async ({
2022
const result = userConfig.includePrivate
2123
? items
2224
: items.filter((item) => !item.private);
23-
await fileSystemRepo.saveItems(result);
25+
await fileSystemRepo.saveItems(result, isLocalUpdate);
2426
}
2527
};

0 commit comments

Comments
 (0)