Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 02:38
    maicallist edited #1532
  • 02:27
    maicallist edited #1532
  • 02:20
    maicallist edited #1532
  • 02:19
    maicallist edited #1532
  • 02:18
    maicallist edited #1532
  • 02:16
    maicallist edited #1532
  • 02:15
    maicallist edited #1532
  • Aug 22 21:37
    rivy commented #1531
  • Aug 22 21:34
    rivy commented #1531
  • Aug 22 05:28
    maicallist edited #1532
  • Aug 22 05:12
    maicallist edited #1532
  • Aug 22 04:59
    maicallist opened #1532
  • Aug 20 17:37
    kozross commented #1529
  • Aug 20 17:36
    kozross commented #1529
  • Aug 20 13:04
    zrzka commented #1529
  • Aug 13 14:03
    Eijebong opened #1531
  • Aug 09 11:00
    malarinv commented #251
  • Aug 09 10:57
    malarinv commented #251
  • Aug 02 20:35
    xidaxmb commented #1530
  • Aug 02 20:34
    xidaxmb opened #1530
Wewe Lads
@AuroransSolis
I'm not sure how to compact it so that it shows something like <DATABASE ARGUMENT> <PATH>. On top of that, I made a help subcommand that takes the arguments --conflict-resolution, --show <DB TYPE>, or --query <DB TYPE>, and trying to do any of those brings up a message that I've given arguments incorrectly.
Wewe Lads
@AuroransSolis

Managed to work out a couple of issues myself, but not this one:

[auro@auro-laptop osu-db-manager]$ target/debug/osu-db-manager info --conflict-resolution
error: The following required arguments were not provided:
    --collection <PATH>
    --osu <PATH>
    --scores <PATH>

USAGE:
    osu-db-manager --jobs <JOBS> --collection <PATH> --osu <PATH> --scores <PATH>

For more information try --help

I was hoping that those arguments wouldn't be required when using a subcommand?

Jeffrey Massung
@massung
Is it possible to give a SubCommand a short name or alias?
Jeffrey Massung
@massung

Not sure how common this is, but my use case of clap is in a REPL-like environment. I download something, and then prompt the user to enter commands that allow navigating, filtering, sorting, etc. of the data. I use clap to parse all the options. The user can do things like...

> search "foo"
> sort -by date -desc
> open 4

Each of those: "search", "sort", "open" are subcommands. It's all great and works wonderfully, but it'd be nice if users could use shortened command names (e.g. "o" for "open").

Wewe Lads
@AuroransSolis
@massung SubCommand::with_name gives you an App<'a, 'b>, so maybe you can just do .alias()?
Or .aliases() if need be.
Wewe Lads
@AuroransSolis
I haven't been able to find any mention of making arguments not required if a subcommand is used in the docs so far.
Wewe Lads
@AuroransSolis
Never mind, found it. .setting(AppSettings::SubcommandNegateReqs).
Jeffrey Massung
@massung
ill give it a try, thanks
Jeffrey Massung
@massung
that worked. so obvious now. thanks :)
Nathan Goldbaum
@ngoldbaum
is there a way to dispatch over subcommands? I kinda want to structure the dispatch from my main() function by basically doing something like
match app.get_matches() {
    SomeSubcommandMatch => { // implementation of the subcommand }
}
is there a way to do that?
(kinda newish to rust and clap)
ah i want ArgMatches.subcommand_name()
ngoldbaum @ngoldbaum kinda wants to make a doc PR to expose that in the readme
Denis Lisov
@tanriol
@ngoldbaum You may also want to take a look at structopt
Nathan Goldbaum
@ngoldbaum
@tanriol sorry, how does that answer my question? isn't that just a different way of defining the options?
Denis Lisov
@tanriol
That's a different way of both defining and using the options. Basically, instead of clap-level value_of/values_of/occurrences_of/is_present with the option names as strings and values as strings you can just receive a struct/enum with the values already with the correct types and in fields with names that are guaranteed to match the definitions. Instead of a match app.get_matches() and manually querying the arguments in each branch, you can match Arguments::from_args() and get the parameters in the same match.
Nathan Goldbaum
@ngoldbaum
ah i see, so i'd match on the different subcommand enum variants
tecosaur
@tecosaur
Hello, just started looking at this crate and I've run into a bit of an issue I'm hoping you guys would be willing to help with
I found https://clap.rs/2016/10/25/an-update/ and stole borrowed that code
However to my surprise I'm getting an error!
image.png
Any suggestions?
(UTC+8 so don't expect a response to questions until a good few hours)
Denis Lisov
@tanriol
The code looks wrong, my guess is that it should have been just shell.parse().unwrap()
tecosaur
@tecosaur
That did it :)
tecosaur
@tecosaur

Another thing, if you guys don't mind.
I'm moving from a python library (click) where I was able to have sub commands structured like this:

main.py
commands
├── subcommand1.py
├── subcommand2.py
└── subcommand3.py

Is there an easy way to accomplish this with clap?

Cliff Dyer
@jcdyer
@kbknapp Is there anything I can do to help move along PRs and issues? I'm happy to help out with code review or triage, or anything else you need.
I was originally scoping out the issues to see if I could contribute some code, but it looks like the backlog is big enough already. :)
Cliff Dyer
@jcdyer
@tecosaur: I don't think clap will automate that for you, but a match on matches.subcommand_name(), and a dispatch to a function in the appropriate submodule shouldn't be too complex. You might need a mod.rs in your commands directory to load the subcommand modules. If you have questions about structuring your code into modules, start with chapter seven of The Book: Managing Growing Projects with Packages, Crates, and Modules, and if that doesn't clear it up for you, ask for clarification here. :)
Then your main.rs would look something like this:
mod commands;

fn main() {
    let matches = get_args();
    match matches.subcommand_name() {
        "get" => commands::get::run(),
        "put" => commands::put::run(),
        _ => panic!("Unknown subcommand"),
    }
}
Vitaly Shukela
@vi
Can I have something like this in clap: myprog --opt1=val1 --flag2 arg1 --opt1=val55 --flag3 arg2 - multiple sets of command-line options per positional argument?
Cliff Dyer
@jcdyer
Do you mean that val1 and flag2 are specifically connected to arg1, and that val55 and flag3 are connected to arg2? Like the way sox works?
I don't actually know how you would do that in clap.
Kyle Wood
@DemonWav
Is completion script generation (at least for zsh) working right now? Using clap 2.33.0 the scripts I'm generating aren't working at all
cargo completions are also not working which doesn't appear to be clap generated though, so maybe it's an issue on my end
but rustup completions are working just fine and have been for a while
Kyle Wood
@DemonWav
both the _rustup and my _paperd files do look identical in structure, and they are sitting right next to each other
I really have no idea
Kyle Wood
@DemonWav
okay now it's working I guess? No idea
Philip Ridout
@phill-ridout_gitlab
Hello! So I want to take an input file and out put file arg. But I want them as Path/Bug
  • Hello! So I want to take an input file and out put file arg. But I want them as Path/Buf what's the best way to achieve this?
Stéphane Campinas
@scampi
Hi!
I am trying to reproduce a parser with awk's usage
Usage: awk [POSIX or GNU style options] -f progfile [--] file ...
Usage: awk [POSIX or GNU style options] [--] 'program' file ...
for now, i cannot manage to express that if a program is not passed in argument then -f is required
do you know if that is somehow possible ?
Cliff Dyer
@jcdyer
@phill-ridout_gitlab If you want to use raw clap, you can use matches.get("path").map(PathBuf::from). If you want more strongly typed data in general, look at the structopt crate, you can just add a path: PathBuf (or path: Option<PathBuf> field to your struct, and get what you want.
@scampi Check the documentation for ArgGroup. It looks like that may do what you want.