These are chat archives for kbknapp/clap-rs

4th
Mar 2018
Nirudium
@NoorMkdad
Mar 04 2018 17:30

Hi, I am unable to get my args becuase I always get a `thread 'main' panicked at 'Argument short must be unique

    -c is already in use', C:\Users\oalmo\.cargo\registry\src\github.com-1ecc6299db9ec823\clap-2.30.0\src\app\parser.rs:182:13

note: Run with RUST_BACKTRACE=1 for a backtrace.` Error

Denis Lisov
@tanriol
Mar 04 2018 17:48
@NoorMkdad Looks like you've specified several different arguments to have the same short form ("-c").
Nirudium
@NoorMkdad
Mar 04 2018 18:01
All I have is an option with const as the short
and even when I change it I get the issue
Denis Lisov
@tanriol
Mar 04 2018 18:02
Could you show your code?
Nirudium
@NoorMkdad
Mar 04 2018 18:03
Yes
I still get the error
Denis Lisov
@tanriol
Mar 04 2018 18:08
Your exact code works on the playground. Are you sure you're not running some different code by mistake?
Nirudium
@NoorMkdad
Mar 04 2018 18:09
I recompiled w/ cargo build to test it
Still doesnt work
Kevin K.
@kbknapp
Mar 04 2018 18:09
@NoorMkdad I'm not getting the same error from what you've posted
Nirudium
@NoorMkdad
Mar 04 2018 18:10
:thinking:
That's weird
Kevin K.
@kbknapp
Mar 04 2018 18:10
I did notice that you have short("chr") but the short is supposed to only be a single character
Nirudium
@NoorMkdad
Mar 04 2018 18:10
Oh ok
Denis Lisov
@tanriol
Mar 04 2018 18:10
I guess there was short("con") too and this was the source of the collision.
Nirudium
@NoorMkdad
Mar 04 2018 18:11
Ah
Know I get ya
Kevin K.
@kbknapp
Mar 04 2018 18:11
Yep
If you change those to long it'll work
Nirudium
@NoorMkdad
Mar 04 2018 18:12
long rather than short?
Ok
Thank you.
Kevin K.
@kbknapp
Mar 04 2018 18:14
if you want --chr instead of just -c which is what short("chr") produces
no problem!
Nirudium
@NoorMkdad
Mar 04 2018 18:15
I still get the error
I changed the code, recompiled
Kevin K.
@kbknapp
Mar 04 2018 18:15
Can you post the link to the new code?
Kevin K.
@kbknapp
Mar 04 2018 18:16
Are you running the old binary? Try cargo clean first
because in that new code there are no shorts...so it's not possible to have a conflict with them
Denis Lisov
@tanriol
Mar 04 2018 18:16
@NoorMkdad The same error? Really sounds like you're running something different... debug vs release binary?
Nirudium
@NoorMkdad
Mar 04 2018 18:17
running debug
But i'll run cargo clean
then cargo build
Nirudium
@NoorMkdad
Mar 04 2018 18:23
cargo clean seems to have broke something
The target directory is now under "lockdown"
Kevin K.
@kbknapp
Mar 04 2018 18:23
The only thing cargo clean does is delete your target directory
I've never heard of that :worried:
Denis Lisov
@tanriol
Mar 04 2018 18:24
What do you mean by lockdown?
Nirudium
@NoorMkdad
Mar 04 2018 18:24
It can't be read and written to
Kevin K.
@kbknapp
Mar 04 2018 18:24
rm -rf target/ :P
Nirudium
@NoorMkdad
Mar 04 2018 18:24
All it is is "Acsess Denied"
welp ok
Kevin K.
@kbknapp
Mar 04 2018 18:25
Are you on Linux?
Nirudium
@NoorMkdad
Mar 04 2018 18:26
Nope, on windows
but I have linux utils
Still doesn't delete
Kevin K.
@kbknapp
Mar 04 2018 18:26
Hmm, maybe could some of the issue. I've had some strange issues like that when using the Bash on Windows features
I'd open cmd.exe as an Admin and just delete the target directory
Nirudium
@NoorMkdad
Mar 04 2018 18:27
I also have Ubuntu on the Linux Subsystem, want me to try that?
Kevin K.
@kbknapp
Mar 04 2018 18:27
You could, couldn't really hurt anything
Nirudium
@NoorMkdad
Mar 04 2018 18:27
C:\Users\oalmo\Projects\dndgen (master -> origin) λ del target/ Invalid switch - "".
wat
Kevin K.
@kbknapp
Mar 04 2018 18:28
If you can reproduce what got you to that step, I'd maybe consider a bug report on cargo
Nirudium
@NoorMkdad
Mar 04 2018 18:28
I was in the dir when I ran cargo clean
Kevin K.
@kbknapp
Mar 04 2018 18:28
cause cargo clean shouldn't be messing with permissions at all
Nirudium
@NoorMkdad
Mar 04 2018 18:28
as in I was cd'd into target/debug/

`error: could not remove build directory

Caused by:
The process cannot access the file because it is being used by another process. (os error 32)`

Kevin K.
@kbknapp
Mar 04 2018 18:29
ah, so it was trying to delete a directory in use
Nirudium
@NoorMkdad
Mar 04 2018 18:29
Yeah
shoulda said that
Kevin K.
@kbknapp
Mar 04 2018 18:29
and then when you backed out of that dir and ran cargo clean again it gave all the permission errors?
Nirudium
@NoorMkdad
Mar 04 2018 18:29
Yep
Kevin K.
@kbknapp
Mar 04 2018 18:30
If I revert to my windows admin days I'd say reboot :P haha
Still though, running cargo clean in a directory you're cd'd into shouldn't do anything with permissions
Nirudium
@NoorMkdad
Mar 04 2018 18:32
I'll reboot
Kevin K.
@kbknapp
Mar 04 2018 18:32
On Linux it works as expected, I know that doesn't help your case, but maybe there's a platform specific bug?
Nirudium
@NoorMkdad
Mar 04 2018 18:32
It could be a plat specific error
Rebooting so wait, I'll tell you if issue is fixed
Btw please add mult-character shorts
Kevin K.
@kbknapp
Mar 04 2018 18:33
kevin@pop-os: ~ 
➜ cd /tmp

kevin@pop-os: /tmp 
➜ cargo new tester --bin
     Created binary (application) `tester` project

kevin@pop-os: /tmp 
➜ cd tester 

kevin@pop-os: /tmp/tester 
➜ cargo build      
   Compiling tester v0.1.0 (file:///tmp/tester)
    Finished dev [unoptimized + debuginfo] target(s) in 0.55 secs

kevin@pop-os: /tmp/tester 
➜ ls -l         
total 4
-rw-rw-r-- 1 kevin kevin  47 Mar  4 13:31 Cargo.lock
-rw-rw-r-- 1 kevin kevin 103 Mar  4 13:30 Cargo.toml
drwxrwxr-x 1 kevin kevin  14 Mar  4 13:30 src
drwxrwxr-x 1 kevin kevin  10 Mar  4 13:31 target

kevin@pop-os: /tmp/tester 
➜ cd target/debug 

kevin@pop-os: /tmp/tester/target/debug 
➜ cargo clean      

kevin@pop-os: /tmp/tester/target/debug 
➜ cd ../../

kevin@pop-os: /tmp/tester 
➜ ls -l        
total 4
-rw-rw-r-- 1 kevin kevin  47 Mar  4 13:31 Cargo.lock
-rw-rw-r-- 1 kevin kevin 103 Mar  4 13:30 Cargo.toml
drwxrwxr-x 1 kevin kevin  14 Mar  4 13:30 src
Denis Lisov
@tanriol
Mar 04 2018 18:34
@NoorMkdad I'd guess you want alias instead of short
Kevin K.
@kbknapp
Mar 04 2018 18:35
@NoorMkdad I've been considering adding multi-char shorts, but right now they conflict with stackable shorts where -zfb is the same as -z -f -b
So it'd be an opt in setting that enables -chr and disables the ability to stack shorts
There's also a ton of people who are used to stacking shorts with values where -oval is actually -o val and mult-char shorts conflict with that too
But an opt-in setting is still possible
In fact, if you'd like to put it on the issue tracker, I'd be happy to guide someone to making such a feature or implementing it once I get v3 released
Denis Lisov
@tanriol
Mar 04 2018 18:39
@kbknapp Maybe not "multi-char shorts", but "allow longs with single hyphen", which disables shorts altogether?
Kevin K.
@kbknapp
Mar 04 2018 18:40
yeah, that would be a way to do it as well
Nirudium
@NoorMkdad
Mar 04 2018 18:41
I'll pop an issue
Kevin K.
@kbknapp
Mar 04 2018 18:41
I have no idea if there is a demand for the ability to use both multi-char shorts and longs? i.e. -type and --type in the same application?
Thanks @NoorMkdad
:)
Nirudium
@NoorMkdad
Mar 04 2018 18:41
Also
rebooting worked
Still confused as to what happened
Kevin K.
@kbknapp
Mar 04 2018 18:42
yeah that's super strange!
Nirudium
@NoorMkdad
Mar 04 2018 18:43
for the multi-char shorts we can have a .chaining() method to the App struct
Kevin K.
@kbknapp
Mar 04 2018 18:43
What do you mean by chaining?
Nirudium
@NoorMkdad
Mar 04 2018 18:43
short chaining
Oh, you call it stackable options
Kevin K.
@kbknapp
Mar 04 2018 18:44
stacking already works
Nirudium
@NoorMkdad
Mar 04 2018 18:44
the .stackable() method is the opt in
.stackable(false) to disable arg stacking
Kevin K.
@kbknapp
Mar 04 2018 18:45
ah I see, so you want to have the multi-char shorts, but also the opt in ability to still stack?
Nirudium
@NoorMkdad
Mar 04 2018 18:45
Yes
So there's no extra hassle in setting the extra dep setting in cargo.toml
just to get multi-character shorts
so then a simple method would be fine
Denis Lisov
@tanriol
Mar 04 2018 18:46
I'd actually suggest an InferArguments setting that would make --cha automatically work for for --charisma, as well as any other unambiguous prefix.
Kevin K.
@kbknapp
Mar 04 2018 18:46
so -type would be parsed as a single arg, but -fbz would still be -f -b -z, or are you saying you want to stack single args with multi-char shorts (-typefbz being -type -f -b -z)?
Denis Lisov
@tanriol
Mar 04 2018 18:47
There's already one for subcommands, but not for arguments, unless I'm missing something.
Kevin K.
@kbknapp
Mar 04 2018 18:47
@NoorMkdad when I say opt-in, I mean using an AppSettings variant, not a cargo dep feature
Nirudium
@NoorMkdad
Mar 04 2018 18:47
@kbknapp That's what I was suggesting
Allow me to send an example
Kevin K.
@kbknapp
Mar 04 2018 18:49
Please do :)
Nirudium
@NoorMkdad
Mar 04 2018 18:50
https://hastebin.com/cupiyaxenu.java < Simply look to line 3
Kevin K.
@kbknapp
Mar 04 2018 18:51
Yeah, that's how the AppSettings variants work
you'd simply do something like setting(AppSettings::DisableStackableShorts) or whatever we'd end up calling it
find being a huge application that uses these -type style args still supports -oval (-o val)style args, so there's precedent for at least supporting that still
Not to say we have to be 1:1 with find, but still
Nirudium
@NoorMkdad
Mar 04 2018 18:55
ah
kbknapp/clap-rs#1201 Opened the issue
Kevin K.
@kbknapp
Mar 04 2018 18:56
:+1: thanks@
!*
Nirudium
@NoorMkdad
Mar 04 2018 18:56
np, happy to contribute
I may not be able to contribute w/ code but I'll be happy to open up an issue
Kevin K.
@kbknapp
Mar 04 2018 19:03
Opening the issue is step 1 and much appreciated :)
Nirudium
@NoorMkdad
Mar 04 2018 19:49
I may have another issue now..
I'm not getting any output from my debug config
Kevin K.
@kbknapp
Mar 04 2018 20:09
What do you mean?
Nirudium
@NoorMkdad
Mar 04 2018 20:13
Nothing gets printed
when I run the executable
Kevin K.
@kbknapp
Mar 04 2018 20:14
Are you talking about clap debugging, or cargo?
Nirudium
@NoorMkdad
Mar 04 2018 20:14
the executable itself
Kevin K.
@kbknapp
Mar 04 2018 20:14
can you show the code?
Kevin K.
@kbknapp
Mar 04 2018 20:26
It prints name: "10", strength: "4", dexterity: "3" , constitution: "1", intelligence: "17", wisdom "10", charisma: "16"
on my machine*
Denis Lisov
@tanriol
Mar 04 2018 20:35
@NoorMkdad By the way, have you looked at structopt?
Nirudium
@NoorMkdad
Mar 04 2018 20:42
@kbknapp That is strange, I don't get anything printed
Welp, running cargo clean && cargo build && cd /target/debug && test
Denis Lisov
@tanriol
Mar 04 2018 20:52
@NoorMkdad Why not cargo run?
Nirudium
@NoorMkdad
Mar 04 2018 20:52
Ah
Didn't know that existed
Denis Lisov
@tanriol
Mar 04 2018 20:55
If you need arguments to your program, they go after -- as follows: cargo run -- --charisma=10
Nirudium
@NoorMkdad
Mar 04 2018 20:55
Ghandi the boi works
William Murphy
@willmurphyscode
Mar 04 2018 20:57
@kbknapp Thanks! Also, I'm ran into a little trouble getting this line to compile both with and without the vec_map feature: https://github.com/kbknapp/clap-rs/blob/v3-master/src/app/parser.rs#L121 It looks like we need to add a pub fn keys to the internal implementation of vec map, but I'm having trouble getting a signature so that line 121 on the parser doesn't care about the feature flag. I ended up doing this: https://github.com/kbknapp/clap-rs/pull/1198/files#diff-3519f1369b63436798d9d7841c7940e2R122 but that feels a little drastic. Let me know what you think, when you have a chance.