Skip to content

Commit

Permalink
doc: move docs to lib.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisGorbachev committed Jul 21, 2024
1 parent f9963c2 commit 2fb2ccf
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 30 deletions.
5 changes: 5 additions & 0 deletions README.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{ readme }}

{%- if links != "" %}
{{ links }}
{%- endif -%}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
48 changes: 19 additions & 29 deletions README.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as zx from 'npm:zx'
import { z, ZodSchema } from 'https://deno.land/x/[email protected]/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({
Expand All @@ -21,6 +22,17 @@ const CargoToml = z.object({

type CargoToml = z.infer<typeof CargoToml>;

const CargoMetadataSchema = z.object({
packages: z.array(z.object({
name: z.string(),
targets: z.array(z.object({
name: z.string(),
})),
})),
})

type CargoMetadata = z.infer<typeof CargoMetadataSchema>;

const Repo = z.object({
url: z.string().url(),
})
Expand All @@ -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')

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ npm install --global \
[email protected] \
[email protected]

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
Expand Down
30 changes: 30 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::Parser;

use create_rust_github_repo::CreateRustGithubRepo;

fn main() -> anyhow::Result<()> {
Expand Down

0 comments on commit 2fb2ccf

Please sign in to comment.