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
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
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
JiaShiwen 12 Nov 5, 2022
CarLI is a framework for creating single-command and multi-command CLI applications in Rust

CarLI is a framework for creating single-command and multi-command CLI applications in Rust. The framework provides error and IO types better suited for the command line environment, especially in cases where unit testing is needed.

Kevin Herrera 3 Jan 21, 2022
Rust library crate providing utility functions for diff and patch of slices

This crate provides the Change enum as an abstraction for diff::Result, lcs_diff::DiffResult, and wu_diff::DiffResult; the diff_changes(), diff_diff()

qtfkwk 5 Oct 19, 2022
Pure rust library for reading / writing DNG files providing access to the raw data in a zero-copy friendly way.

DNG-rs   A pure rust library for reading / writing DNG files providing access to the raw data in a zero-copy friendly way. Also containing code for re

apertus° - open source cinema 4 Dec 1, 2022
A library providing helpers for various StarkNet fees related tasks.

?? How Much ? ?? Table of Contents About Getting Started Prerequisites Installation Usage Estimate fees on network Authors & contributors Security Lic

Abdel @ StarkWare 4 Dec 15, 2022
Rust-battery - Rust crate providing cross-platform information about the notebook batteries.

battery Rust crate providing cross-platform information about the notebook batteries. Table of contents Overview Supported platforms Install Examples

svartalf 326 Dec 21, 2022
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_

Cecile Tonglet 3 Jan 11, 2023
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

Yosh 4 Feb 27, 2023
Are we lang yet? A simple website providing information about the status of Rust's language development ecosystem.

Are We Lang Yet This project answers the question "Is the Rust ecosystem ready to use for language development yet?". arewelangyet.com What is this? C

null 8 Dec 7, 2022
A truly zero-dependency crate providing quick, easy, reliable, and scalable access to the name "jordin"

jordin Finally! A truly zero-dependency crate providing quick, easy, reliable, and scalable access to the name "jordin". Additionally, this one-of-a-k

jordin 2 Aug 4, 2022