Skip to content

Argument Parsing has strange behaviour #32

@ianfhunter

Description

@ianfhunter

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions