Opinionated set of extensions for use with rust-script

Overview

rust-script-ext

Opinionated set of extensions for use with rust-script.

Using rust-script to run Rust like a shell script is great! This crate provides an opinionated set of extensions tailored towards common patterns in scripts. These patterns include file reading, argument parsing, error handling. The goal is for script writers to focus on the business logic, not implementing parsers, handling errors, parsing arguments, etc.

$ cargo install rust-script
..
$ cat ./template.rs
#!/usr/bin/env -S rust-script -c
//! You might need to chmod +x your script!
//! ```cargo
//! [dependencies.rust-script-ext]
//! git = "https://github.com/kurtlawrence/rust-script-ext"
//! rev = "4fe5b852eb2daffb8c188774961dd9baeb7b0c72"
//! ```

use rust_script_ext::prelude::*;

fn main() {
    // fastrand comes from rust_script_ext::prelude::*
    let n = std::iter::repeat_with(|| fastrand::u32(1..=100))
        .take(5)
        .collect::<Vec<_>>();

    println!("Here's 5 random numbers: {n:?}");
}
$ ./template.rs
Here's 5 random numbers: [28, 97, 9, 23, 58]

Template Quickstart

template.rs contains a simple scaffold for a rust-script[-ext]:

curl -L https://github.com/kurtlawrence/rust-script-ext/raw/main/template.rs -o my-script.rs
chmod +x my-script.rs
./my-script.rs

What's included?

What rust-script-ext provides is continually evolving. It is best to review the API documentation. At a high level, the crate provides helpers and data structures which are common in a scripting environment, such as easy error handling, file reading, serialisation/deserialisation, etc. If you find something lacking, I encourage you to open a PR!

Versioning

Versioning does not follow semver as would a normal crate. Instead, it is best to pin a script to a revision number of the repository. As most scripts are ephemeral, or at least not pushed to a large userbase, this encourages a simple versioning scheme where you will be mostly guaranteed that when you run the script, it will compile! Leaving off the revision number should also be fairly safe (cargo should lock it to a revision), but moving the script to another system or clearing the cache could potentially break compilation.

You might also like...
Replace an app's icon from a png with a single terminal script. Made with Rust

Replace macOS App Icon Replace an app's icon from a png with a single terminal CLI. Made with Rust

Fix the simple rust script as shown in README.md
Fix the simple rust script as shown in README.md

Rust Fix Me Steps Create a Github account. (If you already have one no issues) Star this repository. Fork this repository to your Github account. Clon

A small script in rust to get the cpu usage in %'s with a gradient color for the text
A small script in rust to get the cpu usage in %'s with a gradient color for the text

cpu_usage-polybar A small script in rust to get the cpu usage in %'s with a gradient color for the text To get it to work on your PC you will have to

An elegant language for script-kiddies and terminal squatters.

Tonic An elegant language for script-kiddies and terminal squatters. About I started Tonic to complete the Advent of Code 2021. My eventual goal is to

❗️ Small script to view GitHub notifications in the terminal
❗️ Small script to view GitHub notifications in the terminal

github-notifications Small script to view GitHub notifications in the terminal Shows and color-codes the notification source, eg if you're the owner o

Cargo script subcommand

cargo-script cargo-script is a Cargo subcommand designed to let people quickly and easily run Rust "scripts" which can make use of Cargo's package eco

Nvm - Node Version Manager - POSIX-compliant bash script to manage multiple active node.js versions

Node Version Manager Table of Contents Intro About Installing and Updating Install & Update Script Additional Notes Troubleshooting on Linux Troublesh

Write a simple CLI script, that when given a 64-byte encoded string

Write a simple CLI script, that when given a 64-byte encoded string, it finds a suitable 4-byte prefix so that, a SHA256 hash of the prefix combined with the original string of bytes, has two last bytes as 0xca, 0xfe. Script should expect the original content of the string to be passed in hexadecimal format and should return two lines, first being the SHA256 string found and second 4-byte prefix used (in hexadecimal format).

A small script to facilitate the making of .src.spm.tar.gz packges

SPM-Helper Rust version: Installation PYTHON: install python and git Clone the repo with this command: git clone -b Python https://github.com/Soviet-L

Comments
  • Invoking commands

    Invoking commands

    Needs thought about the API since this is extremely common in scripts.

    • [ ] Research existing options
    • [ ] Develop API
    • [ ] Implement
    • [ ] Test
    • [ ] Document
    enhancement 
    opened by kurtlawrence 0
Owner
Kurt Lawrence
Mining Engineer and Software Developer. Specialised in 3D spatial math and programming languages.
Kurt Lawrence
Given a set of kmers (fasta format) and a set of sequences (fasta format), this tool will extract the sequences containing the kmers.

Kmer2sequences Description Given a set of kmers (fasta / fastq [.gz] format) and a set of sequences (fasta / fastq [.gz] format), this tool will extra

Pierre Peterlongo 22 Sep 16, 2023
Generic extensions for tapping values in Rust.

tap Suffix-Position Pipeline Behavior This crate provides extension methods on all types that allow transparent, temporary, inspection/mutation (tappi

Alexander Payne 213 Dec 30, 2022
A simple, opinionated way to run containers for tests in your Rust project.

rustainers rustainers is a simple, opinionated way to run containers for tests. TLDR More information about this crate can be found in the crate docum

wefox 4 Nov 23, 2023
A very opinionated, zero-configuration shell prompt

A very opinionated, zero-configuration shell prompt

amy null 8 Nov 4, 2021
A lightweight, opinionated CQRS and event sourcing framework targeting serverless architectures.

cqrs A lightweight, opinionated CQRS and event sourcing framework targeting serverless architectures. Command Query Responsibility Segregation (CQRS)

Serverless Technology 161 Dec 29, 2022
MinMon - an opinionated minimal monitoring and alarming tool

MinMon - an opinionated minimal monitoring and alarming tool (for Linux) This tool is just a single binary and a config file. No database, no GUI, no

Florian Wickert 177 Jan 5, 2023
A opinionated and fast static analyzer for PHP.

TLDR; A static analyzer for PHP. It helps you catch common mistakes in your PHP code. These are the current checks implemented. Extending undefined cl

Denzyl Dick 11 Mar 6, 2023
Beautiful, minimal, opinionated CLI prompts inspired by the Clack NPM package

Effortlessly build beautiful command-line apps with Rust ?? ✨ Beautiful, minimal, opinionated CLI prompts inspired by the @clack/prompts npm package.

Alexander Fadeev 7 Jul 23, 2023
Opinionated, zero-config linter for JavaScript monorepos

Sherif: Opinionated, zero-config linter for JavaScript monorepos About Sherif is an opinionated, zero-config linter for JavaScript monorepos. It runs

Tom Lienard 219 Oct 10, 2023
comfy is a flexible command script manager / runner written in Rust

comfy is a cross-platform command script manager / runner tool, which allows you to run commands in the command line itself, but being these predefined in a portable and universal .comfy file.

daCoUSB 17 Nov 12, 2021