3 releases

0.1.2 May 22, 2024
0.1.1 Mar 5, 2024
0.1.0 Mar 5, 2024

#808 in Command line utilities

Download history 34/week @ 2024-09-23 21/week @ 2024-09-30 2/week @ 2024-10-07

228 downloads per month

MIT license

12KB
142 lines

sargs

sargs is a command-line tool designed as an alternative to xargs. Unlike xargs, it allows for the execution of subsequent commands in a streaming fashion before the input-side program finishes. This enables real-time data processing, allowing for more efficient workflows.

Crates.io Version

Language

Features

  • Asynchronous Execution: Executes subsequent commands as soon as data becomes available, without waiting for the input-side program to completely finish.
  • High Efficiency: Processes large amounts of data quickly while keeping memory consumption low, thanks to streaming.
  • Flexibility: Can be used in combination with various shell environments and command-line tools, catering to a wide range of applications.

Installation

Currently, sargs can be installed using Cargo, the Rust package manager.

cargo install sargs-cmd

Usage

The basic usage is similar to xargs, but sargs differs in that data is passed to the subsequent command as a stream. Below is an example of taking data from standard input and passing each line to the echo command.

cat example.txt | sargs echo

The command above reads each line from example.txt and passes it to the echo command as it is read, allowing for real-time processing of the file's contents. The difference in behavior from xargs may not be immediately apparent in this example.

For instance, if a command that reads one line and waits for one second is inserted in the middle of the cat command, xargs will read all lines and then execute the command for all lines, while sargs will execute the command immediately after reading each line.

cat example.txt | slow_pass_command | sargs echo

Configuration and Options

sargs offers a wide range of customizable options. You can adjust its behavior through command-line options. All options and their descriptions can be accessed using the following command.

sargs --help

Usage: sargs [OPTIONS] [ARGS]...

Arguments:
  [ARGS]...  

Options:
  -I <INPUT_PLACEHOLDER>           
      --buffer-size <BUFFER_SIZE>  
  -h, --help                       Print help
  -V, --version                    Print version

INPUT_PLACEHOLDER

You can specify a placeholder for the data passed to the subsequent command using the -I or --input-placeholder option.

cat example.txt | sargs -I __INPUT__ echo __INPUT__

In the command above, __INPUT__ will be replaced with the contents of each line when passed to the echo command.

BUFFER_SIZE

You can specify the number of buffers for the output command using the --buffer-size option. The default is 128.

Contributions

sargs is an open-source project and welcomes contributions from the community. Feel free to submit bug reports, feature suggestions, and pull requests through the GitHub repository.

License

sargs is released under the MIT License.

Dependencies

~4–11MB
~97K SLoC