argmax is a library that allows Rust applications to avoid Argument list too long errors (E2BIG) by providing a std::process::Command wrapper with a

Related tags

Command-line argmax
Overview

argmax

argmax is a library that allows Rust applications to avoid Argument list too long errors (E2BIG) by providing a std::process::Command wrapper with a

fn try_arg
   AsRef
   
    >(
    &
    mut 
    self, arg: S) -> 
    bool
   
  

function that returns false if arg would overflow the maximum size.

Resources

Comments
  • Implement Deref to be able to use std::process:Command methods

    Implement Deref to be able to use std::process:Command methods

    I find this useful in std::process:Command. Useful for possible solutions to something like (writing custom formatting methods for it): https://github.com/sharkdp/fd/issues/1083

    ...and off course other places where argmax is used and we want to print the program name for whatever reason. It will include the entire path given to std::process:Command::new.

    Feel free to ignore/close if this is something that has already been considered, or if you just think it is stupid 🙂

    opened by themkat 7
  • Accounting is wrong when 32-bit build launches a 64-bit binary

    Accounting is wrong when 32-bit build launches a 64-bit binary

    Continuing the discussion from https://github.com/sharkdp/fd/issues/410#issuecomment-970780364

    The actual argv/envp pointer are counted in units of size_of::<*const c_char>(): https://github.com/sharkdp/argmax/blob/51575d76b2c759fb8d0d999522f2e587f5c9a4af/src/unix.rs#L50-L54

    But this is wrong if a 32-bit program is launching a 64-bit one on a 64-bit kernel. This leads to this failure: https://github.com/sharkdp/argmax/runs/4231259608?check_suite_focus=true. It can be reproduced locally with

    $ rustup target add i686-unknown-linux-gnu
    $ cargo test --target=i686-unknown-linux-gnu
    ...
    Trying execution with 260638 args
    thread 'can_run_command_with_maximum_number_of_arguments' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 7, kind: ArgumentListTooLong, message: "Argument list too long" }', tests/main.rs:49:30
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    

    A conservative fix would be to assume that pointers are at least 8 bytes wide on all platforms. Ideally we'd only do this on 64-bit kernels, but I don't know a good way to detect that from userspace.

    opened by tavianator 4
  • Fix tests on all platforms

    Fix tests on all platforms

    This is the current state (copied from https://github.com/sharkdp/fd/issues/410)

    • [x] fix compile errors on all fd-supported platforms
      • [x] i686-pc-windows-mscv
      • [x] i686-unknown-linux-gnu
      • [x] i686-unknown-linux-musl
      • [x] x86_64-apple-darwin
      • [x] x86_64-pc-windows-gnu
      • [x] x86_64-pc-windows-mscv
      • [x] x86_64-unknown-linux-gnu
      • [x] x86_64-unknown-linux-musl
    • [x] fix unit test on all platforms
      • [x] i686-pc-windows-mscv
      • [x] i686-unknown-linux-gnu
      • [x] i686-unknown-linux-musl
      • [x] x86_64-apple-darwin
      • [x] x86_64-pc-windows-gnu
      • [x] x86_64-pc-windows-mscv
      • [x] x86_64-unknown-linux-gnu
      • [x] x86_64-unknown-linux-musl
    • [ ] Make sure that enforced limit is reasonably close* to actual (experimental) limit
      • [x] i686-pc-windows-mscv (679 vs 2045)
      • [x] i686-unknown-linux-gnu (348,906 vs 349,417)
      • [ ] i686-unknown-linux-musl (10,295 vs 349,409)
      • [x] x86_64-apple-darwin (20,585 vs 21,096)
      • [x] x86_64-pc-windows-gnu (679 vs 2045)
      • [x] x86_64-pc-windows-mscv (679 vs 2045)
      • [x] x86_64-unknown-linux-gnu (348,329 vs 348,841)
      • [ ] x86_64-unknown-linux-musl (10,294 vs 349,408)

    *reasonably close: it shouldn't be an order of magnitude smaller than the actual limit.

    opened by sharkdp 2
  • Don't use absolute command paths on Unix

    Don't use absolute command paths on Unix

    Some Unix systems (e.g. Nix, GNU Guix) do not keep binaries other than sh in /bin. While assuming the echo command is present is ok, it should be taken from the user's path.

    opened by dominicm00 0
  • How to handle modifications to the environment variables?

    How to handle modifications to the environment variables?

    Commands inherit the parent's environment variables by default. Right now we check the size of the environment when you create a Command, but it can be modified in the meantime:

        #[test]
        fn test_env() {
            let mut cmd = Command::new("/bin/echo");
    
            // Add as many arguments as possible                                                                                                                                                                                                                                    
            while cmd.try_arg("foo").is_ok() {}
    
            for i in 0..1024 {
                std::env::set_var(format!("VAR{i}"), "VALUE");
            }
    
            assert!(cmd.status().unwrap().success());
        }
    
    test tests::test_env ... FAILED
    
    failures:
    
    ---- tests::test_env stdout ----
    thread 'tests::test_env' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 7, kind: ArgumentListTooLong, message: "Argument list too long" }', src/lib.rs:204:30
    

    We can document that std::env::set_var() invalidates the calculations I guess. But we'll still have to think about this to implement try_env() if we want it.

    opened by tavianator 3
Releases(v0.3.1)
  • v0.3.1(Sep 4, 2022)

    What's Changed

    • Implement Deref to be able to use std::process:Command methods by @themkat in https://github.com/sharkdp/argmax/pull/9
    • Bump nix version and only use the feature we need by @tavianator in https://github.com/sharkdp/argmax/pull/7

    Testing

    • Don't use absolute command paths on Unix by @dominicm00 in https://github.com/sharkdp/argmax/pull/8

    Full Changelog: https://github.com/sharkdp/argmax/compare/v0.3.0...v0.3.1

    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(May 25, 2022)

    • Remove an unused type parameter from Command::spawn() by @tavianator in https://github.com/sharkdp/argmax/pull/4
    • Add methods for adding multiple arguments at once, transactionally by @tavianator in https://github.com/sharkdp/argmax/pull/5
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(May 15, 2022)

Owner
David Peter
David Peter
A full featured, fast Command Line Argument Parser for Rust

clap Command Line Argument Parser for Rust It is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcomma

null 10.4k Jan 10, 2023
Docopt for Rust (command line argument parser).

THIS CRATE IS UNMAINTAINED This crate is unlikely to see significant future evolution. The primary reason to choose this crate for a new project is if

null 743 Jan 1, 2023
A full featured, fast Command Line Argument Parser for Rust

clap Command Line Argument Parser for Rust It is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcomma

Ed Page 0 Jun 16, 2022
A simple, lightweight and extensible command line argument parser for rust codebases

A simple, lightweight and extensible command line argument parser for rust codebases. This crate aims to provide you with an easy-to-use and extensibl

Victor Ndaba 20 Nov 12, 2022
🧠 A command-line utility for switching git branches more easily. Switch branches interactively or use a fuzzy search to find that long-forgotten branch name.

git-smart-checkout A git command extension for switching git branches more efficiently. About Interactively switch branches or fuzzy search for that f

Cezar Craciun 51 Dec 29, 2022
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

Liam Germain 24 Sep 26, 2023
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
Rust derive-based argument parsing optimized for code size

Argh Argh is an opinionated Derive-based argument parser optimized for code size Derive-based argument parsing optimized for code size and conformance

Google 1.3k Dec 28, 2022
A minimal argument parser

Pieces An argument parser built with control in mind. Parsing The results you get are dependent on what order you parse in. If you want to say only pa

ibx34 3 Sep 30, 2021
Argument parsing for the future 🚀

argi Argument parsing for the future ?? Features Macro-based approach, providing an intuitive way to layout a cli Rich auto-help generation, styling b

Owez 132 Oct 23, 2022
Use your computer as a cosmic ray detector! One of the memory errors Rust does not protect against.

Your computer can double up as a cosmic ray detector. Yes, really! Cosmic rays hit your computer all the time. If they hit the RAM, this can sometimes

Johanna Sörngård 110 Jun 16, 2023
Enhance Rust errors with file and line details using the `#[wherr]` macro for clearer debugging.

wherr Crate Discuss wherr on Hacker News Enhance Rust's ? operator by appending file and line number details to errors, simplifying the debugging proc

Joel Jakobsson 49 Sep 6, 2023
Catch Tailwindcss Errors at Compile-Time Before They Catch You, without making any change to your code! Supports overriding, extending, custom classes, custom modifiers, Plugins and many more 🚀🔥🦀

twust Twust is a powerful static checker in rust for TailwindCSS class names at compile-time. Table of Contents Overview Installation Usage Statement

null 15 Nov 8, 2023
JiaShiwen 12 Nov 5, 2022
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
Ideas => Creations, a multi-language CMS(Content Management System) based on Rust Web stacks, with long-term upgrade and maintenance.

Ideas => Creations 中文 RustHub: Rust ideas yesterday, shining creations today! This repository holds source code used to run https://rusthub.org, it's

rusthub.org 4 May 9, 2023
Is the GIL seeing someone else? How's about repetitively calling and seeing how long it takes to answer?

GIL Knocker pip install gilknocker When you thought the GIL was available, and you find yourself suspecting it might be spending time with another. Yo

Miles Granger 4 Jan 18, 2023
Fast tool to scan for valid 7-long imgur ids for the ArchiveTeam imgur efforts (not affiliated or endorsed)

imgur_id7 Fast tool to scan for valid 7-long imgur ids for the ArchiveTeam imgur efforts (not affiliated or endorsed) Optionally uses supplied http pr

Robin Rolf 6 Jun 3, 2023
Tumour-only somatic mutation calling using long reads

smrest smrest is a prototype somatic mutation caller for single molecule long reads. It uses haplotype phasing patterns for tumour samples that have a

Jared Simpson 16 Mar 1, 2024