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

CLI - Add feature to print markdown docs #2276

Merged
merged 18 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
50 changes: 50 additions & 0 deletions .github/workflows/cli-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
on:
pull_request:
merge_group:
workflow_dispatch:
inputs:
pr_number:
description: 'Pull Request Number'
required: false
default: ''

name: Check CLI Docs

jobs:
cli_docs:
runs-on: ubuntu-latest
steps:
- name: Find Git ref
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
PR_NUMBER="${{ github.event.inputs.pr_number || null }}"
if test -n "${PR_NUMBER}"; then
GIT_REF="$( gh pr view --repo clockworklabs/SpacetimeDB $PR_NUMBER --json headRefName --jq .headRefName )"
else
GIT_REF="${{ github.ref }}"
fi
echo "GIT_REF=${GIT_REF}" >>"$GITHUB_ENV"
- name: Checkout sources
uses: actions/checkout@v4
with:
ref: ${{ env.GIT_REF }}
- uses: dsherret/rust-toolchain-file@v1
- uses: actions/setup-dotnet@v4
with:
global-json-file: modules/global.json
- name: Checkout docs
uses: actions/checkout@v4
repository: clockworklabs/spacetime-docs
ref: master
path: spacetime-docs
- name: Check for docs change
run: |
cargo run --features markdown-docs -p spacetimedb-cli > spacetime-docs/docs/cli-reference.md
cd spacetime-docs
if ! git diff-index --quiet HEAD; then
echo "It looks like the CLI docs have changed"
git diff
exit 1
fi
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ bytestring = { version = "1.2.0", features = ["serde"] }
cargo_metadata = "0.17.0"
chrono = { version = "0.4.24", default-features = false }
clap = { version = "4.2.4", features = ["derive", "wrap_help"] }
clap-markdown = "0.1.4"
colored = "2.0.0"
console = { version = "0.15.6" }
convert_case = "0.6.0"
Expand Down
4 changes: 4 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ license-file = "LICENSE"
description = "A command line interface for SpacetimeDB"
rust-version.workspace = true

[features]
markdown-docs = []

[lib]
bench = false

Expand Down Expand Up @@ -70,6 +73,7 @@ walkdir.workspace = true
wasmbin.workspace = true
wasmtime.workspace = true
webbrowser.workspace = true
clap-markdown.workspace = true

[target.'cfg(windows)'.dependencies]
windows-sys = { workspace = true, features = ["Win32_System_Console"] }
Expand Down
9 changes: 9 additions & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use spacetimedb_paths::{RootDir, SpacetimePaths};
#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

#[cfg(not(feature = "markdown-docs"))]
#[tokio::main]
async fn main() -> anyhow::Result<ExitCode> {
// Compute matches before loading the config, because `Config` has an observable `drop` method
Expand All @@ -31,6 +32,14 @@ async fn main() -> anyhow::Result<ExitCode> {
exec_subcommand(config, &paths, root_dir, cmd, subcommand_args).await
}

#[cfg(feature = "markdown-docs")]
#[tokio::main]
async fn main() -> anyhow::Result<ExitCode> {
let markdown = clap_markdown::help_markdown_command(&get_command());
println!("{}", markdown);
Ok(ExitCode::SUCCESS)
}

fn get_command() -> Command {
Command::new("spacetime")
.version(version::CLI_VERSION)
Expand Down
Loading