Skip to content

Commit c8dc45c

Browse files
committed
Add force option to pull command
1 parent dc8470f commit c8dc45c

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

README.md

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

210+
`--force`オプションを用いることで、記事ファイルをを全て強制的に Qiita と同期します。
211+
212+
```console
213+
npx qiita pull --force
214+
# -f は--force のエイリアスとして使用できます。
215+
npx qiita pull -f
216+
```
217+
210218
### version
211219

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

src/commands/pull.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@ 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+
"-f": "--force",
14+
},
15+
{ argv }
16+
);
1117

1218
const qiitaApi = await getQiitaApiInstance();
1319
const fileSystemRepo = await getFileSystemRepo();
20+
const isLocalUpdate = args["--force"];
1421

15-
await syncArticlesFromQiita({ fileSystemRepo, qiitaApi });
22+
await syncArticlesFromQiita({ fileSystemRepo, qiitaApi, isLocalUpdate });
1623
console.log("Sync local articles from Qiita");
1724
console.log("Successful!");
1825
};

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)