Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Mar 01 2020 13:10
    pksunkara commented #1711
  • Mar 01 2020 13:09
    pickfire commented #1711
  • Mar 01 2020 13:07
    pickfire commented #1710
  • Mar 01 2020 12:14
    bors[bot] commented #1710
  • Mar 01 2020 12:14
    CreepySkeleton commented #1710
  • Mar 01 2020 12:09
    CreepySkeleton commented #1710
  • Mar 01 2020 12:09
    CreepySkeleton commented #1710
  • Mar 01 2020 12:08
    pksunkara review_requested #1710
  • Mar 01 2020 11:49
    pickfire commented #1710
  • Mar 01 2020 11:47
    pksunkara commented #1711
  • Mar 01 2020 11:44
    pickfire opened #1711
  • Mar 01 2020 11:44
    pickfire labeled #1711
  • Mar 01 2020 11:36
    pickfire synchronize #1710
  • Mar 01 2020 09:10
    pickfire commented #1710
  • Mar 01 2020 09:09
    pickfire opened #1710
  • Mar 01 2020 08:30
    pksunkara commented #1655
  • Mar 01 2020 08:29
    pickfire commented #1655
  • Feb 29 2020 16:49
    bors[bot] closed #1709
  • Feb 29 2020 16:49
    bors[bot] commented #1709
  • Feb 29 2020 16:07
    pksunkara commented #1709
nivpgir
@nivpgir
I want to use the clap with it's struct opt features

tried adding:

[dependencies]
clap = "~3.0.0-beta.1"

to my Cargo.toml
but sadly:

$ cargo build --release
warning: unused manifest key: target.armv7-unknown-linux-gnueabihf.linker
    Updating crates.io index
error: failed to select a version for the requirement `clap = "~3.0.0"`
  candidate versions found which didn't match: 2.33.0, 2.32.0, 2.31.2, ...
  location searched: crates.io index

this is what I get.
what am I doing wrong?

Denis Lisov
@tanriol
IIUC, no 3.0 preview versions have been published yet.
nivpgir
@nivpgir

so... is it ok that it's in the readme...?
I've found this issue: clap-rs/clap#1589
and in it clap is used like this:

[dependencies]
clap = { git = "https://github.com/clap-rs/clap", features = ["wrap_help"] }

which works...
but how is the readme version supposed to work if no version 3.0 is published?
I'm a rust noob so maybe there's a cargo configuration or something else I'm missing, or maybe it's not supposed to work now? and only on some future version...?

Denis Lisov
@tanriol
The readme seems to be already (partially) updated for the future beta release, but the release has not happened yet.
nivpgir
@nivpgir
OK, I understand, thanks for the patience, I'll just use it from the git for now
Ahmed Abd El Mawgood
@oddcoder
Hello world!
is there a way in clap where I can say
that this argument cannot be used with any other arguments ?
even required ones ?
something like create --help for example (not for help but something different)
Scott Mattan
@rustysys-dev

I got this error:

procyclinsur@P428Scott rediskv]$ cargo run -- -k hello
   Compiling rediskv v0.1.0 (/home/procyclinsur/rust/rediskv)
error[E0599]: no method named `value_of` found for type `std::result::Result<clap::ArgMatches<'_>, clap::Error>` in the current scope
  --> src/main.rs:26:23
   |
26 |     let key = matches.value_of("key").unwrap();
   |                       ^^^^^^^^ method not found in `std::result::Result<clap::ArgMatches<'_>, clap::Error>`

error[E0599]: no method named `value_of` found for type `std::result::Result<clap::ArgMatches<'_>, clap::Error>` in the current scope
  --> src/main.rs:27:25
   |
27 |     let value = matches.value_of("value").unwrap_or("");
   |                         ^^^^^^^^ method not found in `std::result::Result<clap::ArgMatches<'_>, clap::Error>`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0599`.
error: could not compile `rediskv`.

For this code:

extern crate clap;
use clap::{App, Arg, ErrorKind};

fn main() {
    let matches = App::new("rediskv")
        .version("v1.0-beta")
        .author("Scott Mattan <xxxxx@gmail.com>")
        .about("Reads and writes values from redis")
        .arg(Arg::with_name("key")
             .short("k")
             .required(true)
             .value_name("KEY_NAME")
             .help("Redis Key Name")
             .takes_value(true))
        .arg(Arg::with_name("value")
             .short("i")
             .value_name("VALUE")
             .help("Redis Key Value")
             .takes_value(true))
        .get_matches_from_safe(vec![
                               "rediskv"
        ]);

    assert!(matches.is_err());
    assert_eq!(matches.unwrap_err().kind, ErrorKind::MissingRequiredArgument);
    let key = matches.value_of("key").unwrap();
    let value = matches.value_of("value").unwrap_or("");
    println!("Key: {}", key);
    println!("Value: {}", value);
}

When ArgMatches contains the method in question.

Not sure what I am doing wrong, has anyone seen this?

Denis Lisov
@tanriol
The return value of get_matches_from_safe is a Result, which is an enum containing either an ArgMatches struct or an error. You cannot use value_of unless the arguments parse successfully (and you check for that or at least unwrap).
Scott Mattan
@rustysys-dev
@tanriol Thanks for your reply!, I apologize for my delay in responding, you were right, and it I was able to get it working to some extent by treating it as an enum, but thigs didn't work correctly... I think using get_matches_from_safe was incorrect for my current usecase.. I think I should have used get_matches_safe or get_matches.
Scott Mattan
@rustysys-dev

Is there anyway to have subcommands accept args from a parent command so that I do not have to redefine them multiple times?

for example:

let matches = App::new("rediskv")
        .version("v1.0-beta")
        .author("Scott Mattan")
        .about("Reads and writes values from redis")
        .arg(Arg::with_name("key")
             .short("k")
             .value_name("KEY_NAME")
             .required(true)
             .help("Redis Key Name")
             .takes_value(true))
        .arg(Arg::with_name("value")
             .short("i")
             .value_name("VALUE")
             .help("Redis Key Value")
             .takes_value(true))
        .subcommand(SubCommand::with_name("insert") 
                    .about("inserts data into redis")
                    .version("v1.0-beta")
                    .author("Scott Mattan")
                    .args(["key", "value"]))
        .subcommand(SubCommand::with_name("get") 
                    .about("inserts data into redis")
                    .version("v1.0-beta")
                    .author("Scott Mattan")
                    .args(["key"]))
        .get_matches();

Or in this case should I create the Arg::with_name() separately and then just add them.

Denis Lisov
@tanriol
Scott Mattan
@rustysys-dev

@tanriol After looking around, it doesn't seem like there is a required_if subcommand which would be nice since a global arg doesn't seem to be requireable

That being said, thank you!!

Jean Manguy
@jeanmanguy
hi, sorry I am getting started with rust and clap my question might be stupid, how should I proceed if I want to store the the matches of a subcommand in a struct? Different subcommand matches would be stored in different structs, for different use etc. It gets weird with lifetimes, I'm not sure I'm heading on the right direction. Any examples out there ?
Denis Lisov
@tanriol
Have you looked at structopt?
Jean Manguy
@jeanmanguy
I know about it, but I discarded it because I already had clap working before, but maybe it can help
Matthew Pocock
@drdozer
hi - I am using clap 3 beta and the Clap annotation on a struct
I would like to match on the struct, and print out help if some branches of the match are hit -- is there a way to programatically print out the help?
Matthew Pocock
@drdozer
I see .print_help() but I can't see how to call it with my #[derive(Clap)] struct Opts
Denis Lisov
@tanriol
Opts::into_app()?
Matthew Pocock
@drdozer
Ah - I think that's it - I hadn't got the IntoApp trait imported
Matthew Pocock
@drdozer
so I have a sub-crate that isolates my diesel code - it has an autogenerated schema.rs, and a hand-rolled model.rs containing various querieables and insertables.
I have some "business logic" (a phrase I really don't like) that ensures that the raw data objects honour my application requirements e.g. hashed passwords are hashed
does that go into models.rs, or into some separate business logic file? This is really the API that should be used external to the crate
or does it just go direct into lib.rs?
Jonas Natten
@jnatten
Hey there, I'm trying to make a cli where the user can tag stuff with mrt -t test and then later reference the tag with mrt +test other_command. Is there a way to have a different prefix than - in clap? (Python does it like this: https://docs.python.org/3/library/argparse.html#prefix-chars)
Matthew Pocock
@drdozer
Oh sorry! Wrong room
Stephen Chavez
@redragonx
error: failed to select a version for the requirement clap = "^3.0.0-beta.1"
candidate versions found which didn't match: 2.33.0, 2.32.0, 2.31.2,
Hi all, when I try to setup clap, i get that error
used the readme as a guide.
Denis Lisov
@tanriol
The readme is for the 3.0 branch which has not been released yet. clap = "2.33" should work for the latest currently released version.
Stephen Chavez
@redragonx
Any fixes?
ok
ty
oh its you @tanriol
The rust community must be close :)
Any reason not to use 3.0 branch locally?
Denis Lisov
@tanriol
I do monitor the communication channels of the libraries I'm interested in... usually works as "come in to ask a question and never leave if the channel is quiet enough" :-)
Depends on your use case, probably. My personal rule of thumb is to use released versions only unless there's some specific reason to require a newer one.
Stephen Chavez
@redragonx
i dont plan on using the structopt feature yet.
so 2.33 it is
Mehdi Sadeghi
@mehdisadeghi
Good morning. Does someone know whether we can order subcommands? e.g. help comes first, then the rest of subcommands. Sorry for not reading the code! I'm just learning Rust and it is too much to dig into the library code.
Mehdi Sadeghi
@mehdisadeghi
Nevermind, found it! (display_order: 1000), (display_order: 1001), etc.
Howerver I have another question. How can I add default value and env option to an arguement with the clap_app! macro? e.g. (@arg BUS: "socketcan interface")
Mehdi Sadeghi
@mehdisadeghi
Found that one too! (@arg BUS: default_value[vcan0] "socketcan interface")
This channel is pure magic. You just ask the questsions. The answers appear in your mind. Have a good day!