Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument Parsing has strange behaviour #32

Open
ianfhunter opened this issue Dec 1, 2023 · 1 comment
Open

Argument Parsing has strange behaviour #32

ianfhunter opened this issue Dec 1, 2023 · 1 comment

Comments

@ianfhunter
Copy link

If I want to provide an optional argument to my alias, for example !myalias debugmode, the logic inside draconic for parsing arguments is not very helpful.

If I call the following code as !bug hello and just !bug

!alias bug embed
-desc "Hi {{'%1%'}}

The first will print "Hi hello" and the latter "Hi %1%".

I would expect that when %1% is not provided, it would be replaced with an empty string, so we could do something like this:

!alias bug embed
-desc "Hi {{'%1%' if '%1%' != '' else ''}}

However, because it's not replaced, it's impossible to detect if the value isn't provided reliably

!alias bug embed
-desc "Hi {{'%1%' if '%1%' != '%1%' else ''}}

Will return "%1%" because both sides of the comparison are replaced.

The only workaround I can think of is something like:

!alias bug embed
-desc "Hi {{'%1%' if "%" not in '%1%' else ''}}

However, that would exclude valid inputs like "Hi 100%"

I do not know that the other argument parse types - "%*%", "&1&", etc work any better.

Proposed Solution: If I was writing this code, I would expect these to be replaced with None or "" on no argument received

@Lathaon
Copy link

Lathaon commented Dec 1, 2023

A common solution has been this:

!alias bug embed
-desc "Hi {{"&1&" if "&1&" != "&"+"1&" else ""}}"

Personally I prefer to work with &ARGS&, as lists of arguments feel cleaner to work with in most cases.

(As a side note, I'd recommend visiting Avrae's Discord server rather than jumping straight to GitHub)

@ianfhunter ianfhunter changed the title Argument Parsing Argument Parsing has strange behaviour Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants