Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Dec 01 23:07
    dylni commented #1524
  • Nov 29 23:35
    Dylan-DPC closed #1599
  • Nov 28 21:56
    bacongobbler commented #1599
  • Nov 28 21:56
    bacongobbler synchronize #1599
  • Nov 28 21:35
    fvictorio commented #984
  • Nov 28 20:42
    Dylan-DPC commented #1599
  • Nov 28 20:41
    Dylan-DPC commented #984
  • Nov 28 20:38
    fvictorio commented #984
  • Nov 27 19:55
    sergeyklay commented #1089
  • Nov 27 19:55
    sergeyklay commented #1089
  • Nov 27 13:22
    rtucker-mozilla commented #1431
  • Nov 27 13:21
    matthiasbeyer closed #1595
  • Nov 27 13:21
    matthiasbeyer commented #1595
  • Nov 26 20:06
    RaboliotLeGris commented #1595
  • Nov 26 17:45
    m-ou-se commented #1477
  • Nov 26 17:39
    Dylan-DPC closed #1602
  • Nov 26 17:39
    Dylan-DPC closed #1390
  • Nov 26 17:38
    Dylan-DPC commented #1602
  • Nov 26 16:34
    m-ou-se opened #1602
  • Nov 26 13:18
    davidMcneil commented #1519
tecosaur
@tecosaur
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.
Hongde Liu
@enginespot
Hi , currently I am using clap , I want to log all of the commands user input , I am not sure how to do it , so can anybody help me:) Thanks.
I tried to use matches , info!("{:?}", &matches); but the output a little poor readability
Cliff Dyer
@jcdyer
If you just want the original command line invocation, you don't need clap. std::env::args() should get you the results you need.
Gabriele Bianchet-David
@Larisho
Hi! Does anyone know how to specify that an argument takes 0 or more values? This scenario isn't mentioned in the docs
Hongde Liu
@enginespot
Hi @jcdyer , I want to use clap to parse commands , and also I want to log user input , hmm... I can use std::env::args() , but the format is not very well , so if clap can format all of the command will be well:)
Benn Sundsrud
@bsundsrud
Is there a way to get a positional arg to show up after a named arg? I've got a subcommand where i've got the usage showing up as cmd subcommand <FILE> -n <SOME_VAL>
also the gitter link on https://github.com/clap-rs/clap points to non-existent gitter clap-rs/clap
in the readme
Za Wilcox
@zancas
Hi!
zancas
@zancas_gitlab
Hey folks, I was wondering what the state-of -the-art on specifying Args as enum variants? How about using StructOpt? I've looked at the blog posts, I was wondering if there were popular examples somewhere?
Justin Starry
@jstarry
Hello, thought I'd throw another question out into the wild :wink: Is there a way to specify sensitive input such as passwords via stdin somehow?
Justin Starry
@jstarry
Realized that hidden input is out of scope for a cli argument parser :) nvm!
David McNeil
@davidMcneil
I recently put together a proof-of-concept macro for easily integrating clap with a config file. I would love any feedback on the approach. It heavily relies on features in clap v3. Is there a tracking issue for the v3 release? I would love to contriute.
David McNeil
@davidMcneil
I found the v3 tracking issue clap-rs/clap#1037. However, the last update is from a while a go. Is the transition to v3 something well suited for community contribution to tackle? It would be great to get a list of outstanding issues. Thanks for the great library! I would love to help get it over the v3 milestone.
nivpgir
@nivpgir
hi
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