{"action":"created","issue":{"url":"https://api.github.com/repos/uutils/coreutils/issues/1006","repository_url":"https://api.github.com/repos/uutils/coreutils","labels_url":"https://api.github.com/repos/uutils/coreutils/issues/1006/labels{/name}","comments_url":"https://api.github.com/repos/uutils/coreutils/issues/1006/comments","events_url":"https://api.github.com/repos/uutils/coreutils/issues/1006/events","html_url":"https://github.com/uutils/coreutils/issues/1006","id":193188628,"number":1006,"title":"Thoughts on using clap in certain places?","user":{"login":"kbknapp","id":6942134,"avatar_url":"https://avatars.githubusercontent.com/u/6942134?v=3","gravatar_id":"","url":"https://api.github.com/users/kbknapp","html_url":"https://github.com/kbknapp","followers_url":"https://api.github.com/users/kbknapp/followers","following_url":"https://api.github.com/users/kbknapp/following{/other_user}","gists_url":"https://api.github.com/users/kbknapp/gists{/gist_id}","starred_url":"https://api.github.com/users/kbknapp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kbknapp/subscriptions","organizations_url":"https://api.github.com/users/kbknapp/orgs","repos_url":"https://api.github.com/users/kbknapp/repos","events_url":"https://api.github.com/users/kbknapp/events{/privacy}","received_events_url":"https://api.github.com/users/kbknapp/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-12-02T18:46:13Z","updated_at":"2016-12-04T21:06:32Z","closed_at":null,"body":"What are the maintainers thoughts on using [`clap`](https://github.com/kbknapp/clap-rs) in certain spots? First, let me say that I'm not advocating a wholesale switch to `clap` for all things! :stuck_out_tongue_winking_eye:  \r\n\r\nI'm just curious if the maintainers are open to some PRs where I think the codebase can become more concise. There's also some nice cases where `clap` provides some additional functionality basically for free (such as bash, fish, zsh, or powershell completion file generations, context sensitive error messages, etc.).\r\n\r\nI've been looking through some of the codebase and there are a decent number of spots where the code is duplicating what `clap` is already doing.\r\n\r\nAs a *super* simple and short example; implementation of things like `yes` go down to just this:\r\n\r\n```rust\r\n#[macro_use]\r\nextern crate clap;\r\n\r\n#[macro_use]\r\nextern crate uucore;\r\n\r\nuse clap::{App, Arg};\r\nuse std::io::Write;\r\n\r\npub fn uumain(args: Vec<String>) -> i32 {\r\n    let m = App::new(\"yes\")\r\n\t.about(\"Repeatedly output a line with all specified STRING(s), or 'y'.\")\r\n\t.version(crate_version!())\r\n\t.arg(Arg::with_name(\"STRING\")\r\n\t    .help(\"The STRING(s) to repeatedly output\")\r\n\t    .multiple(true)\r\n\t    .default_value(\"y\"))\r\n\t.get_matches_from(args);\r\n    \r\n    let s = m.values_of(\"STRING\").unwrap().collect::<Vec<_>>().join(\" \");\r\n    while pipe_println!(\"{}\", s) { }\r\n\r\n    0\r\n}\r\n```\r\n\r\nThere's some more complex scenarios like `od` which [contains the comment](https://github.com/uutils/coreutils/blob/a6cda50ac8ffd886fa6efa9727a3070b23834fbc/src/od/parse_formats.rs#L95-L103):\r\n\r\n```\r\n/// getopts, docopt, clap don't seem suitable to parse the commandline\r\n/// arguments used for formats. In particular arguments can appear\r\n/// multiple times and the order they appear in, is significant.\r\n///\r\n/// arguments like -f, -o, -x can appear separate or combined: -fox\r\n/// it can also be mixed with non format related flags like -v: -fvox\r\n/// arguments with parameters like -w16 can only appear at the end: -fvoxw16\r\n/// parameters of -t/--format specify 1 or more formats.\r\n/// if -- appears on the commandline, parsing should stop.\r\n```\r\n\r\nYet the what is described is *exactly* how `clap` parses the arguments, i.e. running `od -fvoxw16` is perfectly valid to `clap` and parsed in the matches as `-f -o -x -v -w=16`, and `clap` also respects `--`. So the effort is somewhat being duplicated.\r\n\r\n----\r\n\r\nDoing a few PRs also helps me maintain `clap` as it can point me to additional pain points and what still needs fixing, adding, changing, etc. :smile: \r\n\r\nAlso, thanks for this great project, it's super exciting!"},"comment":{"url":"https://api.github.com/repos/uutils/coreutils/issues/comments/264731157","html_url":"https://github.com/uutils/coreutils/issues/1006#issuecomment-264731157","issue_url":"https://api.github.com/repos/uutils/coreutils/issues/1006","id":264731157,"user":{"login":"wimh","id":468963,"avatar_url":"https://avatars.githubusercontent.com/u/468963?v=3","gravatar_id":"","url":"https://api.github.com/users/wimh","html_url":"https://github.com/wimh","followers_url":"https://api.github.com/users/wimh/followers","following_url":"https://api.github.com/users/wimh/following{/other_user}","gists_url":"https://api.github.com/users/wimh/gists{/gist_id}","starred_url":"https://api.github.com/users/wimh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wimh/subscriptions","organizations_url":"https://api.github.com/users/wimh/orgs","repos_url":"https://api.github.com/users/wimh/repos","events_url":"https://api.github.com/users/wimh/events{/privacy}","received_events_url":"https://api.github.com/users/wimh/received_events","type":"User","site_admin":false},"created_at":"2016-12-04T21:06:32Z","updated_at":"2016-12-04T21:06:32Z","body":"I am responsible for the `od` comment mentioned above. What I mean is that `od -o -d` and `od -d -o` should provide **different** results. Looking at the source, a `HashMap` is internally used to store the parsed arguments, so that does not seem possible. I believe this is very exotic behaviour, so I don't expect this to be implemented in a generic commandline parser.\r\n\r\nStill it would be possible to use `clap` instead of `getopts` in `od` for commandline validation and arguments for which the order does not matter.\r\n"}}
{"actor":{"display_login":"wimh"}}