🍬 shell-candy is a library that wraps Rust's `std::process::Command`

Overview

🍬 shell-candy

This crate wraps std::process::Command, providing an easier mechanism for handling individual log lines from external tools.

Usage

This example shows the basic usage of ShellTask: create one from a POSIX-style command, and then run it with a log line handler that you write yourself. This handler can either continue for every line for the length of the program, or it can return early and shut down the program.

You could use this function to pass log lines through your own log formatter like so:

eprintln!("info: {}", &message), } ShellTaskBehavior::<()>::Passthrough })?; Ok(()) }">
use anyhow::Result;
use shell_candy::{ShellTaskLog, ShellTaskBehavior, ShellTask};

fn main() -> Result<()> {
  let task = ShellTask::new("rustc --version")?;
  task.run(|line| {
    match line {
      ShellTaskLog::Stdout(message) | ShellTaskLog::Stderr(message) => eprintln!("info: {}", &message),
    }
    ShellTaskBehavior::<()>::Passthrough
  })?;
  Ok(())
}

You could also use this function to return early if a command meets a specific criteria (like encountering an unrecoverable error):

{ if message.contains("an error that is unlikely to be in your git logs but just might be") { return ShellTaskBehavior::<()>::EarlyReturn(Err(anyhow!("encountered an error while running 'git log'").into())); } }, } ShellTaskBehavior::<()>::Passthrough })?; Ok(()) }">
use anyhow::{anyhow, Error, Result};
use shell_candy::{ShellTaskLog, ShellTaskBehavior, ShellTask};

fn main() -> Result<()> {
  let task = ShellTask::new("git log")?;
  task.run(|line| {
    match line {
      ShellTaskLog::Stdout(message) | ShellTaskLog::Stderr(message) => {
        if message.contains("an error that is unlikely to be in your git logs but just might be") {
          return ShellTaskBehavior::<()>::EarlyReturn(Err(anyhow!("encountered an error while running 'git log'").into()));
        }
      },
    }
    ShellTaskBehavior::<()>::Passthrough
  })?;
  Ok(())
}

More information

See the docs for more detailed information and example usage.

You might also like...
KAIVM is a multiplatform Command Line Interface (CLI) designed to simplify the process of downloading, managing, configuring, and running different versions of Shinkai Node
KAIVM is a multiplatform Command Line Interface (CLI) designed to simplify the process of downloading, managing, configuring, and running different versions of Shinkai Node

KAIVM - Shinkai Version Manager KAIVM is a multiplatform Command Line Interface (CLI) designed to simplify the process of downloading, managing, confi

Command-line tool designed to simplify the process of managing multiple .NET SDK versions on your system

.NET Version Manager (dver) Overview dver is a command-line tool designed to simplify the process of managing multiple .NET SDK versions on your syste

A micro crate that simplifies a bit the use of the std macro thread_local!.

with-thread-local A micro crate that simplifies a bit the use of the std macro thread_local!. extern crate regex; use with_thread_local::with_thread_

Prototype of the `std::io::ensure!` family of macros

io-ensure Prototype of the `std::io::ensure` family of macros API Docs | Releases | Contributing Installation $ cargo add io-ensure Safety This crate

An alternative `std`-like implementation built on origin

origin-studio An alternative `std`-like implementation built on origin origin-stdio is an alternative std-like implementation built on origin. At this

A drop-in replacement for std::time::Instant that is faster and more accurate.

Fastant A drop-in replacement for std::time::Instant that measures time with high performance and high accuracy powered by Time Stamp Counter (TSC). U

A library that allows for the arbitrary inspection and manipulation of the memory and code of a process on a Linux system.
A library that allows for the arbitrary inspection and manipulation of the memory and code of a process on a Linux system.

raminspect raminspect is a crate that allows for the inspection and manipulation of the memory and code of a running process on a Linux system. It pro

Shell scripting that will knock your socks off
Shell scripting that will knock your socks off

atom Shell scripting that will knock your socks off. NOTE: Click the image above for a video demonstration.

A new type of shell
A new type of shell

A new type of shell

Owner
Avery Harnish
I make devtools for web engineers.
Avery Harnish
Wraps cargo to move target directories to a central location [super experimental]

targo Wraps cargo to move target directories to a central location [super experimental] To use, cargo install --git https://github.com/sunshowers/targ

Rain 18 Jan 7, 2023
Sugar is an alternative to the current Metaplex Candy Machine CLI

Sugar: A Candy Machine CLI Sugar is an alternative to the current Metaplex Candy Machine CLI. It has been written from the ground up and includes seve

Metaplex Foundation 152 Dec 23, 2022
A Rust on-site channel benchmarking helper. Inter-Process (async / busy) & Intra-Process (async single threaded / async multi threaded)

On-Site Rust Channel Benchmarking Helper Deploy on server to determine which public crates are the fastest for communicating in different architecture

null 23 Jul 9, 2024
This library provides a convenient derive macro for the standard library's std::error::Error trait.

derive(Error) This library provides a convenient derive macro for the standard library's std::error::Error trait. [dependencies] therror = "1.0" Compi

Sebastian Thiel 5 Oct 23, 2023
A command-line shell like fish, but POSIX compatible.

A command-line shell like fish, but POSIX compatible.

Seiya Nuta 813 Dec 29, 2022
Application microframework with command-line option parsing, configuration, error handling, logging, and shell interactions

Abscissa is a microframework for building Rust applications (either CLI tools or network/web services), aiming to provide a large number of features w

iqlusion 524 Dec 26, 2022
A command line interface meant to bridge the gap between Rust and shell scripting

clawbang A command line interface meant to bridge the gap between Rust and shell scripting. Intended for use with HEREDOCs and shebangs: $ clawbang <<

Chris Dickinson 52 Mar 25, 2022
Non-interactive nREPL client for shell scripts and command-line

nreplops-tool (nr) nreplops-tool (nr) is a non-interactive nREPL client designed to be used in shell scripts and on the command-line. Early α warning:

Matti Hänninen 3 Jul 1, 2022
A command-line tool for patching shell scripts inspired by resholve

patsh A command-line tool for patching shell scripts inspired by resholve nix run github:nix-community/patsh -- -f script.sh Usage Usage: patsh [OPTIO

Nix community projects 23 Jan 7, 2023