Skip to content

Add force option to pull command #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ Qiita 上で更新を行い、手元で変更を行っていない記事ファ
npx qiita pull
```

`--force`オプションを用いることで、記事ファイルをを全て強制的に Qiita と同期します。

```console
npx qiita pull --force
# -f は --force のエイリアスとして使用できます。
npx qiita pull -f
```

### version

Qiita CLI のバージョンを確認できます。
Expand Down
11 changes: 9 additions & 2 deletions src/commands/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import { QiitaApi } from "../qiita-api";
import { startLocalChangeWatcher, startServer } from "../server/app";

export const pull = async (argv: string[]) => {
const args = arg({}, { argv });
const args = arg(
{
"--force": Boolean,
"-f": "--force",
},
{ argv }
);

const qiitaApi = await getQiitaApiInstance();
const fileSystemRepo = await getFileSystemRepo();
const isLocalUpdate = args["--force"];

await syncArticlesFromQiita({ fileSystemRepo, qiitaApi });
await syncArticlesFromQiita({ fileSystemRepo, qiitaApi, isLocalUpdate });
console.log("Sync local articles from Qiita");
console.log("Successful!");
};
4 changes: 2 additions & 2 deletions src/lib/file-system-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,9 @@ export class FileSystemRepo {
}
}

async saveItems(items: Item[]) {
async saveItems(items: Item[], isLocalUpdate: boolean = false) {
const promises = items.map(async (item) => {
await this.syncItem(item);
await this.syncItem(item, false, isLocalUpdate);
});

await Promise.all(promises);
Expand Down
4 changes: 3 additions & 1 deletion src/lib/sync-articles-from-qiita.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { config } from "./config";
export const syncArticlesFromQiita = async ({
fileSystemRepo,
qiitaApi,
isLocalUpdate = false,
}: {
fileSystemRepo: FileSystemRepo;
qiitaApi: QiitaApi;
isLocalUpdate?: boolean;
}) => {
const per = 100;
const userConfig = await config.getUserConfig();
Expand All @@ -20,6 +22,6 @@ export const syncArticlesFromQiita = async ({
const result = userConfig.includePrivate
? items
: items.filter((item) => !item.private);
await fileSystemRepo.saveItems(result);
await fileSystemRepo.saveItems(result, isLocalUpdate);
}
};