0

I have a program which wraps another executable. I need to provide some interface so that we my program is called, user can provide any arbitrary arguments which will be passed on to the executable that it wraps. For example:

When user calls

$ myprogram --call -additional -a -b -c 1 -d=true

I would like my program to call

wrapped_executable -a -b -c 1 -d=true

What is the best way to achieve this using flags package?

askedOct 14, 2021 at 13:45
fhcat's user avatar
2
  • Theflag-package is order-agnostic. It cannot help you with this unless you put-a -b -c 1 -d=true in quotes.CommentedOct 14, 2021 at 13:51
  • This is pretty easy if you run it using the shell correctly asmyprogram -call -additional "-a -b -c 1 -d=true". Shells break up CLI arguments on spaces.CommentedOct 14, 2021 at 13:51

1 Answer1

1

From theflag docs docs:

Flag parsing stops just before the first non-flag argument ("-" is anon-flag argument) or after the terminator "--".

so when invoking your outer exe, replace-additional with--:

$ myprogram --call --  -a -b -c 1 -d=true

and then to get the arguments after the--:

flag.Parse()args := flag.Args() // []string{"-a", "-b", "-c", "1", "-d=true"}
answeredOct 14, 2021 at 13:57
colm.anseo's user avatar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.