Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getopts: handling of embedded = differs for --name string and --name=string #14223

Closed
pnkfelix opened this issue May 15, 2014 · 2 comments
Closed

Comments

@pnkfelix
Copy link
Member

Sample program:

extern crate getopts;
use getopts::{optopt,optflagopt,getopts};
use std::os;

fn main() {
    let args = os::args();
    let opts =
        [optopt(    "o", "output", "set output file name", "NAME"),
         optflagopt("a", "attrib", "set attribute", "KEY=VALUE")];
    let matches = match getopts(args.tail(), opts) {
        Ok(m) => { m }
        Err(f) => { fail!(f.to_err_msg()) }
    };
    let output = matches.opt_str("o");
    let keyval = matches.opt_str("a");

    println!("output: {}", output);
    println!("attrib: {}", keyval);
}

Here is a transcript illustrating some interesting invocations

% rustc /tmp/g.rs
% ./g --output=hm
output: Some(hm)
attrib: None
% ./g --attrib
output: None
attrib: None
% ./g --attrib hi
output: None
attrib: Some(hi)
% ./g --attrib hi=world
output: None
attrib: Some(hi=world)
% ./g -a=hi=world
output: None
attrib: Some(=hi=world)
% ./g -a hi=world
output: None
attrib: Some(hi=world)
% ./g --attrib=hi=world
output: None
attrib: Some(hi)
% 

I think that --attrib hi=world and --attrib=hi=world should be treated as equivalent inputs.

From skimming getopts, this should be relatively easy to fix by replacing the call to split('=') with splitn('=', 1).

@pnkfelix
Copy link
Member Author

(technically I guess this would be considering a "breaking-change", since it would be changing the semantics of how getopt behaves in this corner case; though it seems like anyone relying on the current behavior is asking for trouble...)

@steveklabnik
Copy link
Member

This issue has been moved to the getopts repo: rust-lang/getopts#14

lnicola pushed a commit to lnicola/rust that referenced this issue Mar 13, 2023
Add tuple to render_const_scalar

cc `@lowr`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants