script-server icon indicating copy to clipboard operation
script-server copied to clipboard

BUG/FEATURE REQUEST: "Param" does not support spaces

Open 0lionelzhang0 opened this issue 1 year ago • 3 comments

Script config in UI: image

The test script:

from argparse import ArgumentParser


def parse_args():
    parser = ArgumentParser()
    parser.add_argument("--extra_label", nargs=2, action="append", metavar=("LABEL_NAME", "LABEL_VALUE"))
    return parser.parse_args()


args = parse_args()
print(args.extra_label)

Output error: image

When I copy paste the command that was supposed run in the "HISTORY" menu, it runs successfully: image


The suspected reason for error, is that there can't be spaces in the command ("result"). E.g. when I added the two lines that are commented below, it would work (and commenting out the original append option_name line).

image

0lionelzhang0 avatar Aug 09 '24 17:08 0lionelzhang0

What if you invoke it as "--extra_label=LabelB"?

Shell convention says that long-name arguments should have their values set with =, and short-name arguments assign from the value following the argument.

On Fri, Aug 9, 2024, 1:57 PM Lionel Zhang @.***> wrote:

Script config in UI: image.png (view on web) https://github.com/user-attachments/assets/7d4f9fd7-3f36-4e2b-a352-ddf9ce16b15c

The test script:

from argparse import ArgumentParser

def parse_args(): parser = ArgumentParser() parser.add_argument("--extra_label", nargs=2, action="append", metavar=("LABEL_NAME", "LABEL_VALUE")) return parser.parse_args()

args = parse_args() print(args.extra_label)

Output error: image.png (view on web) https://github.com/user-attachments/assets/ec9748f3-e452-4496-b037-32c260c10bd0

When I copy paste the command that was supposed run in the "HISTORY" menu, it runs successfully: image.png (view on web) https://github.com/user-attachments/assets/f6018e28-5f99-43df-8a47-8b87322c7f1b

The suspected reason for error, is that there can't be spaces in the command ("result"). E.g. when I added the two lines that are commented below, it would work.

image.png (view on web) https://github.com/user-attachments/assets/4277cd75-288d-4cbf-8bc6-32363836a832

— Reply to this email directly, view it on GitHub https://github.com/bugy/script-server/issues/758, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3HBI3VLSRL6GBKIYGBPKNLZQT7JRAVCNFSM6AAAAABMI4RILSVHI2DSMVQWIX3LMV43ASLTON2WKOZSGQ2TQNBQGY3TEMI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

MNeill73 avatar Aug 09 '24 18:08 MNeill73

Hi @0lionelzhang0, it's supposed to work this way. Everything is sent to scripts as isolated arguments, i.e. effectively the same as being wrapped in quotes, e.g. script.py '--extra_label LabelB' bb in your case. To override such a behaviour, script server would need an explicit parameter for it OR allow to specify param as an array (I think this is a cleaner option). If you can mark the parameter as required, you can add a constant value before this parameter as a workaround.

@MNeill73 from what I know, argparse won't work with this syntax. Thanks for the suggestion though!

bugy avatar Aug 09 '24 19:08 bugy

Thank you for getting back to me so quickly! I understand that this behavior is expected based on the implementation. It was just a little unintuitive and frustrating when trying to debug, since the command shown in the "HISTORY" and log files doesn't reflect the "invisible" single-quotes that the backend executes the command with.

0lionelzhang0 avatar Aug 09 '24 20:08 0lionelzhang0