Skip to content

Commit

Permalink
Create some auxiliary scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
fmease committed Dec 30, 2024
1 parent e4e9003 commit 4799237
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/rereadme linguist-language=Rust
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/README.backup.md
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,25 @@ However if that's too wordy for you and you don't care about passing arguments /

## Command-Line Interface

<!--{COMMAND-->
`rruxwry -h`:

```
A wrapper around rust{,do}c for rust{,do}c devs
Usage: rruxwry <COMMAND>
Commands:
build Compile the given crate
doc Document the given crate
build Compile the given crate with rustc
doc Document the given crate with rustdoc
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
```
<!--COMMAND}-->

<!--{COMMAND-->
`rruxwry build -h`:

```
Compile the given crate with rustc
Expand Down Expand Up @@ -156,9 +157,10 @@ Options:
--color <WHEN> Control when to use color [default: auto] [possible values: auto, always, never]
-h, --help Print help
```
<!--COMMAND}-->

<!--{COMMAND-->
`rruxwry doc -h`:

```
Document the given crate with rustdoc
Expand Down Expand Up @@ -196,6 +198,7 @@ Options:
--color <WHEN> Control when to use color [default: auto] [possible values: auto, always, never]
-h, --help Print help
```
<!--COMMAND}-->

Additionally, *rruxwry* recognizes the environment variables `RUSTFLAGS` and `RUSTDOCFLAGS`.

Expand Down
6 changes: 6 additions & 0 deletions etc/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh

CARGO_MANIFEST_DIR="$( dirname $( realpath $0 ) )/../"

cargo build --release --manifest-path="$CARGO_MANIFEST_DIR/Cargo.toml" \
&& cp "$CARGO_MANIFEST_DIR/target/release/rruxwry" "$HOME/.bin/"
63 changes: 63 additions & 0 deletions etc/rereadme
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env -S cargo -Zscript
---
[package]
edition = "2024"
---
//! Regenerate the `README.md`.
#![feature(exit_status_error)]

use std::{env, error::Error, path::Path, process::Command};

fn main() -> Result<(), Box<dyn Error>> {
let project_path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/.."));
let binary_path =
project_path.join("target/release/rruxwry").with_extension(env::consts::EXE_EXTENSION);
let readme_path = project_path.join("README.md");
std::fs::copy(&readme_path, project_path.join("README.backup.md"))?;
let source = std::fs::read_to_string(&readme_path)?;

let mut result = Vec::with_capacity(source.len());
let mut state = State::Keep;

for line in source.lines() {
match state {
State::Keep => {
if line == "<!--{COMMAND-->" {
state = State::Seek;
}
}
State::Seek => state = State::Skip,
State::Skip => {
if line == "<!--COMMAND}-->" {
state = State::Keep;
} else {
continue;
}
}
}

result.extend_from_slice(line.as_bytes());
result.push(b'\n');

if let State::Skip = state {
let line = line.strip_prefix("`rruxwry ").unwrap();
let line = line.strip_suffix("`:").unwrap();
let mut output = Command::new(&binary_path).args(line.split(" ")).output()?;
output.status.exit_ok()?;
assert!(output.stderr.is_empty());
result.extend_from_slice(b"```\n");
result.append(&mut output.stdout);
result.extend_from_slice(b"```\n");
}
}

std::fs::write(readme_path, result)?;

Ok(())
}

enum State {
Keep,
Seek,
Skip,
}

0 comments on commit 4799237

Please sign in to comment.