From 2fb2ccfb4d47f8b15fc656f71d6417e4b4bc792d Mon Sep 17 00:00:00 2001 From: Denis Gorbachev <829578+DenisGorbachev@users.noreply.github.com> Date: Sun, 21 Jul 2024 12:24:14 +0700 Subject: [PATCH] doc: move docs to lib.rs --- README.jl | 5 +++++ README.md | 2 +- README.ts | 48 +++++++++++++++++++----------------------------- install.sh | 2 ++ src/lib.rs | 30 ++++++++++++++++++++++++++++++ src/main.rs | 1 + 6 files changed, 58 insertions(+), 30 deletions(-) create mode 100644 README.jl diff --git a/README.jl b/README.jl new file mode 100644 index 0000000..3dffcdf --- /dev/null +++ b/README.jl @@ -0,0 +1,5 @@ +{{ readme }} + +{%- if links != "" %} + {{ links }} +{%- endif -%} diff --git a/README.md b/README.md index c902e5f..a863b36 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ ```shell # Create a GitHub repo & init a Rust project create-rust-github-repo --name my-new-project - + # Copy configs from existing project create-rust-github-repo --name my-new-project --copy-configs-from ~/workspace/my-existing-project diff --git a/README.ts b/README.ts index 43d4ab5..81ed614 100755 --- a/README.ts +++ b/README.ts @@ -3,6 +3,7 @@ import * as zx from 'npm:zx' import { z, ZodSchema } from 'https://deno.land/x/zod@v3.23.8/mod.ts' import { assertEquals } from 'https://jsr.io/@std/assert/1.0.0/equals.ts' +import { assert } from 'https://jsr.io/@std/assert/1.0.0/assert.ts' const CargoToml = z.object({ package: z.object({ @@ -21,6 +22,17 @@ const CargoToml = z.object({ type CargoToml = z.infer; +const CargoMetadataSchema = z.object({ + packages: z.array(z.object({ + name: z.string(), + targets: z.array(z.object({ + name: z.string(), + })), + })), +}) + +type CargoMetadata = z.infer; + const Repo = z.object({ url: z.string().url(), }) @@ -37,6 +49,12 @@ const theCargoToml: CargoToml = parse(CargoToml, await $`yj -t < Cargo.toml`) const { package: { name, description, metadata: { details: { title } } } } = theCargoToml const bin = name const help = await $`cargo run --quiet --bin ${bin} -- --help` +const theCargoMetadata: CargoMetadata = parse(CargoMetadataSchema, await $`cargo metadata --format-version 1`) +const thePackageMetadata = theCargoMetadata.packages.find(p => p.name == name) +assert(thePackageMetadata, 'Could not find package metadata') +const target = thePackageMetadata.targets[0] +assert(target, 'Could not find package first target') +const doc = await $`cargo doc2readme --template README.jl --target-name ${target.name} --out -` const repo: Repo = parse(Repo, await $`gh repo view --json url`) const extraBins = (await $`find src/bin/*.rs -type f -exec basename {} .rs \\;`).valueOf().split('\n') @@ -56,35 +74,7 @@ ${autogenerated} [![Build](${repo.url}/actions/workflows/ci.yml/badge.svg)](${repo.url}) [![Documentation](https://docs.rs/${name}/badge.svg)](https://docs.rs/${name}) -## Overview - -${description} - -## Examples - -\`\`\`shell -# Create a GitHub repo & init a Rust project -${bin} --name my-new-project - -# Copy configs from existing project -${bin} --name my-new-project --copy-configs-from ~/workspace/my-existing-project - -# Clone to a specific directory -${bin} --name my-new-project --dir ~/workspace/my-new-project - -# Create a public repo -${bin} --name my-new-project --repo-create-cmd "gh repo create --public {{name}}" - -# Create a lib instead of bin -${bin} --name my-new-project --project-init-cmd "cargo init --lib" -\`\`\` - -## Features - -* [x] Uses existing \`gh\`, \`git\`, \`cargo\` commands -* [x] Supports overrides for all commands -* [x] Supports substitutions (see help below) -* [x] Can be used as a library +${doc.stdout.trim()} ## Installation diff --git a/install.sh b/install.sh index 2f4a875..706677b 100755 --- a/install.sh +++ b/install.sh @@ -6,6 +6,8 @@ npm install --global \ remark-validate-links@8.0.0 \ remark-lint-no-dead-urls@1.1.0 +cargo install --git https://github.com/DenisGorbachev/cargo-doc2readme --branch dev + # Install yj curl -L https://github.com/sclevine/yj/releases/download/v5.1.0/yj-linux-amd64 -o /tmp/yj chmod +x /tmp/yj diff --git a/src/lib.rs b/src/lib.rs index d8ba2a1..3b29208 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,33 @@ +//! # Overview +//! +//! `create-rust-github-repo` is a CLI program that creates a new repository on GitHub, clones it locally, initializes a Rust project, copies the configs from a pre-existing directory. +//! +//! # Examples +//! +//! ```shell,ignore +//! # Create a GitHub repo & init a Rust project +//! create-rust-github-repo --name my-new-project +//! +//! # Copy configs from existing project +//! create-rust-github-repo --name my-new-project --copy-configs-from ~/workspace/my-existing-project +//! +//! # Clone to a specific directory +//! create-rust-github-repo --name my-new-project --dir ~/workspace/my-new-project +//! +//! # Create a public repo +//! create-rust-github-repo --name my-new-project --repo-create-cmd "gh repo create --public {{name}}" +//! +//! # Create a lib instead of bin +//! create-rust-github-repo --name my-new-project --project-init-cmd "cargo init --lib" +//! ``` +//! +//! # Features +//! +//! * [x] Uses existing `gh`, `git`, `cargo` commands +//! * [x] Supports overrides for all commands +//! * [x] Supports substitutions (see help below) +//! * [x] Can be used as a library + use std::collections::HashMap; use std::env::current_dir; use std::ffi::OsStr; diff --git a/src/main.rs b/src/main.rs index 5c0e79d..c795faa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use clap::Parser; + use create_rust_github_repo::CreateRustGithubRepo; fn main() -> anyhow::Result<()> {