Skip to content
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

feat(cli): support pull/push/link on multiple mermaid files at once #15

Merged
merged 6 commits into from
Apr 16, 2024

Conversation

aloisklink
Copy link
Contributor

Draft PR: This PR is stacked on top of:

Please change this PR to target main once #12 has been merged.

📖 Description

Currently, the mermaid-chart CLI can only pull/push/link a single file at a time.

This PR adds support for pulling/pushing/linking multiple files at once with the @mermaidchart/cli CLI, e.g. like mermaid-chart pull file1 file2.

If using bash, this means you can run commands like npx mermaid-chart pull docs/*.mmd, as your shell will automatically expand docs/*.mmd.

me@pc:~$ npx mermaid-chart --help
Usage: mermaid-cli [options] [command]

CLI for interacting with https://MermaidChart.com, the platform that makes collaborating with Mermaid diagrams easy.

Options:
  -V, --version               output the version number
  -c, --config <config_file>  The path to the config file to use. (default: "/home/alois/.config/mermaid-chart.toml")
  -h, --help                  display help for command

Commands:
  whoami                      Display Mermaid Chart username
  login                       Login to a Mermaid Chart account
  logout                      Log out of a Mermaid Chart account
  link <path...>              Link the given Mermaid diagrams to Mermaid Chart
  pull [options] <path...>    Pulls documents from Mermaid Chart
  push <path...>              Push local diagrams to Mermaid Chart
  help [command]              display help for command

link-ing multiple files

When running mermaid-chart link diagram1.mmd diagram2.mmd diagram3.mmd, the mermaid-chart CLI will ask the user if they want to upload all the diagrams to the same project. If not, then the CLI will ask the user for the project for each diagram:

me@pc:~/MermaidChart/plugins/packages/cli (feat/support-multiple-files-at-once-in-cli)$ npx ts-node@^11.0.0-beta.1 --esm ./src/cli.ts link test/output/unsynced*.mmd
? Select a project to upload test/output/unsynced1.mmd to tmp
? Would you like to upload all diagrams to this project? no
? Select a project to upload test/output/unsynced2.mmd to tmp
? Select a project to upload test/output/unsynced3.mmd to tmp
? Select a project to upload test/output/unsynced.mmd to
  personal
  GitHub Actions test projecttmp

push/pull-ing multiple files

When pulling/pushing multiple files, the CLI will print some info about each file:

me@pc:~/MermaidChart/plugins/packages/cli (feat/support-multiple-files-at-once-in-cli)$ npx ts-node@^11.0.0-beta.1 --esm ./src/cli.ts push test/output/unsynced*.mmd
✅ - test/output/unsynced3.mmd is up to date
✅ - test/output/unsynced2.mmd is up to date
✅ - test/output/unsynced1.mmd is up to date
me@pc:~/MermaidChart/plugins/packages/cli (feat/support-multiple-files-at-once-in-cli)$ npx ts-node@^11.0.0-beta.1 --esm ./src/cli.ts pull test/output/unsynced*.mmd
✅ - test/output/unsynced1.mmd is up to date
✅ - test/output/unsynced2.mmd was updated
✅ - test/output/unsynced3.mmd is up to date

Copy link

vercel bot commented Dec 1, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
office-plugin-site ⬜️ Ignored (Inspect) Visit Preview Apr 16, 2024 8:48am

Support pulling/pushing multiple files at once with the
`@mermaidchart/cli` CLI, e.g. like `mermaid-chart pull file1 file2`.
Add support for running `mermaid-chart link diagram1.mmd diagram2.mmd`.

The CLI tool will ask the user if they want to upload all diagrams to
the same project. Otherwise it will ask the user for the correct project
for each diagram:

```console
$ npx @mermaidchart/cli link test/output/unsynced.mmd test/output/unsynced1.mmd
? Select a project to upload test/output/unsynced.mmd to personal
? Would you like to upload all 2 diagrams to this project? (Y/n)
```
Remove the `paths` var from `getProjectId()` function.

This means we can keep track of which call is the first/second call,
without needing a `paths` var (useful when we support diagrams without a
path).

Intead we use `Cache.previousSelectedProjectId` and
`Cache.usePreviousSelectedProjectId`.
Micro-op, I'm mainly doing this so the code is cleaner, not so that the
code is faster!
I did this in a separate commit from the previous one, in order to make
the `git diff` easier to read for reviewers.
Base automatically changed from feat/add-mermaid-chart-cli to main April 16, 2024 08:45
Fix merge conflict in packages/cli/src/commander.ts
@aloisklink aloisklink marked this pull request as ready for review April 16, 2024 08:48
@aloisklink aloisklink merged commit 9384306 into main Apr 16, 2024
6 checks passed
@aloisklink aloisklink deleted the feat/support-multiple-files-at-once-in-cli branch April 16, 2024 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants