Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Vinilux

Can't use shell.parse properly

Question

Hello everyone.

I want to use shell.parse in order to pass arguments and options to my program.

I saw in the shell api guide than shell.parse can read arguments and options if they are preceded by a -.

I can take arguments but if a call my program with -p etc doesnt do anything.

Do I have to use the standard local args = ... or local args = {...}?

 

Another question is, what is the correct way of validating arguments and options? Do I have to force an order for arguments?

For example, there are arguments that could be written without options but another arguments can only be passed if the correct option for that argument it's passed.

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

For your first question, you're spot on.

Var args are passed like a function to a program. I'm not sure if they're all strings and/or numbers.. You might have to parse em.. Try something like this..

local args, opts = shell.parse(...)

Link to post
Share on other sites
  • 0

For your first question, you're spot on.

Var args are passed like a function to a program. I'm not sure if they're all strings and/or numbers.. You might have to parse em.. Try something like this..

local args, opts = shell.parse(...)

Yes, I did that exactly, but when I try to use opts it doesnt have anything, but yes args.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.