rscripter 0.1.1

Template for writing scripts in rust
Documentation
  • Coverage
  • 0%
    0 out of 16 items documented0 out of 5 items with examples
  • Size
  • Source code size: 9.24 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 655.17 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • aQaTL/rscripter
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • aQaTL

rscripter

Recommended quick setup

I recommend leveraging cargo-generate.

  1. If you don't have cargo-generate already, install it:
cargo install cargo-generate
  1. Generate your repo using this one as a template:
cargo generate -n my-rust-scripts aQaTL/rscripter 

Take a look at examples in the examples directory.

  1. Let's say you want to create a script that pings 1.1.1.1 3 times.
  • Start by creating a file in src/bin/
/// src/bin/ping_cldflr.rs

use rscripter::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
	cmd!("ping", "-c", "3", "1.1.1.1")?;
	
	Ok(())
}
  • Test it
$ cargo run --bin ping_cldflr
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/ping_cldflr`
ping -c 3 1.1.1.1
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=56 time=51.9 ms
64 bytes from 1.1.1.1: icmp_seq=2 ttl=56 time=51.7 ms
64 bytes from 1.1.1.1: icmp_seq=3 ttl=56 time=43.6 ms

--- 1.1.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 43.574/49.041/51.858/3.866 ms
  • You can install all scripts from the bin directory
cargo install --path . -f
  • Now you can use the scripts without cargo anyhwere
me@pc:~$ ping_cldflr
ping -c 3 1.1.1.1
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=56 time=51.9 ms
64 bytes from 1.1.1.1: icmp_seq=2 ttl=56 time=51.7 ms
64 bytes from 1.1.1.1: icmp_seq=3 ttl=56 time=43.6 ms
me@pc:~$