Repository: microsoft/edit
File: src/bin/edit/main.rs (Rust)

Code before:
    // The best CLI argument parser in the world.
    let args = env::args_os().collect::<Vec<OsString>>();
    if args.iter().any(|arg| arg == "-h" || arg == "--help" || (cfg!(windows) && arg == "/?")) {
        print_help();
        return Ok(true);
    } else if args.iter().any(|arg| arg == "-v" || arg == "--version") {
        print_version();
        return Ok(true);
    }

    let paths = args
        .iter()
        .skip(1)
        .filter_map(|arg| {
            if arg == "-" {
                // We ignore it
                return None;
            }
            let p = cwd.join(Path::new(arg));
            let p = path::normalize(&p);
            if p.is_dir() {
                return None;
            }
            Some(p)
        })
        .collect::<Vec<PathBuf>>();

    if paths.len() > 1 {
        for p in paths {
            state.documents.add_file_path(&p)?;
        }
    } else if paths.len() == 1 {
        let p = paths[0].clone();
        if let Some(parent) = p.parent() {
            cwd = parent.to_path_buf();
        }
        state.documents.add_file_path(&p)?;
    } else {
        if let Some(mut file) = sys::open_stdin_if_redirected() {
            let doc = state.documents.add_untitled()?;
            let mut tb = doc.buffer.borrow_mut();
            tb.read_file(&mut file, None)?;
            tb.mark_as_dirty();
        } else {
            state.documents.add_untitled()?;
        }
    }

    state.file_picker_pending_dir = DisplayablePathBuf::new(cwd);
    Ok(false)
}

Review comment (suggestion):
I think we should mostly keep the existing logic and write it like this:
```rs
// you can see examples for this if you search for "scratch_arena" in the project
let scratch = scratch_arena(None);
let mut paths = Vec::new_in(&*scratch);

// The best CLI argument parser in the world.
for arg in env::args_os().skip(1) {
    // ... existing code ...
    } else if arg == "-" {
        // vvvvvvv Crucial change from your PR vvvvvvv
        paths.clear();
        break;
    } else {
        // ... existing code ...
        paths.push(p);
    }
}
```

Code after:

// Returns true if the application should exit early.
fn handle_args(state: &mut State) -> apperr::Result<bool> {
    let scratch = scratch_arena(None);
    let mut paths: Vec<PathBuf, &Arena> = Vec::new_in(&*scratch);
    let mut cwd = env::current_dir()?;

    // The best CLI argument parser in the world.
    for arg in env::args_os().skip(1) {
        if arg == "-h" || arg == "--help" || (cfg!(windows) && arg == "/?") {
            print_help();
            return Ok(true);
        } else if arg == "-v" || arg == "--version" {
            print_version();
            return Ok(true);
        } else if arg == "-" {
            paths.clear();
            break;
        }
        let p = cwd.join(Path::new(&arg));
        let p = path::normalize(&p);
        if !p.is_dir() {
            paths.push(p);
        }
    }

    for p in &paths {
        state.documents.add_file_path(p)?;
    }
    if let Some(parent) = paths.first().and_then(|p| p.parent()) {
        cwd = parent.to_path_buf();
    }

    if let Some(mut file) = sys::open_stdin_if_redirected() {
        let doc = state.documents.add_untitled()?;
        let mut tb = doc.buffer.borrow_mut();
        tb.read_file(&mut file, None)?;
        tb.mark_as_dirty();
    } else if paths.is_empty() {
        // No files were passed, and stdin is not redirected.
        state.documents.add_untitled()?;
    }

    state.file_picker_pending_dir = DisplayablePathBuf::new(cwd);
    Ok(false)
}

fn print_help() {
    sys::write_stdout(concat!(
        "Usage: edit [OPTIONS] [FILE]\r\n",
        "Options:\r\n",