Skip to content

Commit 2fb2ccf

Browse files
doc: move docs to lib.rs
1 parent f9963c2 commit 2fb2ccf

File tree

6 files changed

+58
-30
lines changed

6 files changed

+58
-30
lines changed

README.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{{ readme }}
2+
3+
{%- if links != "" %}
4+
{{ links }}
5+
{%- endif -%}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
```shell
1717
# Create a GitHub repo & init a Rust project
1818
create-rust-github-repo --name my-new-project
19-
19+
2020
# Copy configs from existing project
2121
create-rust-github-repo --name my-new-project --copy-configs-from ~/workspace/my-existing-project
2222

README.ts

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import * as zx from 'npm:zx'
44
import { z, ZodSchema } from 'https://deno.land/x/[email protected]/mod.ts'
55
import { assertEquals } from 'https://jsr.io/@std/assert/1.0.0/equals.ts'
6+
import { assert } from 'https://jsr.io/@std/assert/1.0.0/assert.ts'
67

78
const CargoToml = z.object({
89
package: z.object({
@@ -21,6 +22,17 @@ const CargoToml = z.object({
2122

2223
type CargoToml = z.infer<typeof CargoToml>;
2324

25+
const CargoMetadataSchema = z.object({
26+
packages: z.array(z.object({
27+
name: z.string(),
28+
targets: z.array(z.object({
29+
name: z.string(),
30+
})),
31+
})),
32+
})
33+
34+
type CargoMetadata = z.infer<typeof CargoMetadataSchema>;
35+
2436
const Repo = z.object({
2537
url: z.string().url(),
2638
})
@@ -37,6 +49,12 @@ const theCargoToml: CargoToml = parse(CargoToml, await $`yj -t < Cargo.toml`)
3749
const { package: { name, description, metadata: { details: { title } } } } = theCargoToml
3850
const bin = name
3951
const help = await $`cargo run --quiet --bin ${bin} -- --help`
52+
const theCargoMetadata: CargoMetadata = parse(CargoMetadataSchema, await $`cargo metadata --format-version 1`)
53+
const thePackageMetadata = theCargoMetadata.packages.find(p => p.name == name)
54+
assert(thePackageMetadata, 'Could not find package metadata')
55+
const target = thePackageMetadata.targets[0]
56+
assert(target, 'Could not find package first target')
57+
const doc = await $`cargo doc2readme --template README.jl --target-name ${target.name} --out -`
4058
const repo: Repo = parse(Repo, await $`gh repo view --json url`)
4159
const extraBins = (await $`find src/bin/*.rs -type f -exec basename {} .rs \\;`).valueOf().split('\n')
4260

@@ -56,35 +74,7 @@ ${autogenerated}
5674
[![Build](${repo.url}/actions/workflows/ci.yml/badge.svg)](${repo.url})
5775
[![Documentation](https://docs.rs/${name}/badge.svg)](https://docs.rs/${name})
5876
59-
## Overview
60-
61-
${description}
62-
63-
## Examples
64-
65-
\`\`\`shell
66-
# Create a GitHub repo & init a Rust project
67-
${bin} --name my-new-project
68-
69-
# Copy configs from existing project
70-
${bin} --name my-new-project --copy-configs-from ~/workspace/my-existing-project
71-
72-
# Clone to a specific directory
73-
${bin} --name my-new-project --dir ~/workspace/my-new-project
74-
75-
# Create a public repo
76-
${bin} --name my-new-project --repo-create-cmd "gh repo create --public {{name}}"
77-
78-
# Create a lib instead of bin
79-
${bin} --name my-new-project --project-init-cmd "cargo init --lib"
80-
\`\`\`
81-
82-
## Features
83-
84-
* [x] Uses existing \`gh\`, \`git\`, \`cargo\` commands
85-
* [x] Supports overrides for all commands
86-
* [x] Supports substitutions (see help below)
87-
* [x] Can be used as a library
77+
${doc.stdout.trim()}
8878
8979
## Installation
9080

install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ npm install --global \
66
77
88

9+
cargo install --git https://github.com/DenisGorbachev/cargo-doc2readme --branch dev
10+
911
# Install yj
1012
curl -L https://github.com/sclevine/yj/releases/download/v5.1.0/yj-linux-amd64 -o /tmp/yj
1113
chmod +x /tmp/yj

src/lib.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
//! # Overview
2+
//!
3+
//! `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.
4+
//!
5+
//! # Examples
6+
//!
7+
//! ```shell,ignore
8+
//! # Create a GitHub repo & init a Rust project
9+
//! create-rust-github-repo --name my-new-project
10+
//!
11+
//! # Copy configs from existing project
12+
//! create-rust-github-repo --name my-new-project --copy-configs-from ~/workspace/my-existing-project
13+
//!
14+
//! # Clone to a specific directory
15+
//! create-rust-github-repo --name my-new-project --dir ~/workspace/my-new-project
16+
//!
17+
//! # Create a public repo
18+
//! create-rust-github-repo --name my-new-project --repo-create-cmd "gh repo create --public {{name}}"
19+
//!
20+
//! # Create a lib instead of bin
21+
//! create-rust-github-repo --name my-new-project --project-init-cmd "cargo init --lib"
22+
//! ```
23+
//!
24+
//! # Features
25+
//!
26+
//! * [x] Uses existing `gh`, `git`, `cargo` commands
27+
//! * [x] Supports overrides for all commands
28+
//! * [x] Supports substitutions (see help below)
29+
//! * [x] Can be used as a library
30+
131
use std::collections::HashMap;
232
use std::env::current_dir;
333
use std::ffi::OsStr;

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clap::Parser;
2+
23
use create_rust_github_repo::CreateRustGithubRepo;
34

45
fn main() -> anyhow::Result<()> {

0 commit comments

Comments
 (0)