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

Do you have an idea for representing key/value options? #77

Open
kendalldita opened this issue Oct 1, 2024 · 3 comments
Open

Do you have an idea for representing key/value options? #77

kendalldita opened this issue Oct 1, 2024 · 3 comments

Comments

@kendalldita
Copy link

Java and other software has key/value pair parameters, e.g. the lang property:

java -Dlang=en -cp some.jar input output

Another example:

xsltproc --param lang en id.xsl in.xml

The parameter name can be anything. Could something like that be represented in docopt syntax?

@Sylvain303
Copy link
Collaborator

@kendalldita did you read http://docopt.org/ ?

Your questions seems not specifically related to docopts bash parser but more about the docopt (without S) language, right?

You should also paste your code you're trying, in order to complete your question, if related to docopts. For more general docopt question probably stackoverflow would be a better place to ask.

https://stackoverflow.com/questions/tagged/docopt

Here is a sample with your input:

#!/usr/bin/env bash
# Usage: xsltproc --param=PARAM INPUT OUTPUT
#        xsltproc --lang=LANG INPUT OUTPUT                                                                                            
#

# no PATH changes required if docopts binary is in the PATH already
PATH=..:$PATH
source ../docopts.sh
HELP=$(docopt_get_help_string $0)
version='0.1'

parsed=$(docopts -A myargs -h "$HELP" -V $version : "$@")
#echo "$parsed"
eval "$parsed"

# main code
for a in ${!myargs[@]} ; do
    echo "$a = ${myargs[$a]}"
done

some use-case:

$  ./xsltproc.sh 
error: 
Usage: xsltproc --param=PARAM INPUT OUTPUT
       xsltproc --lang=LANG INPUT OUTPUT

with string parameter --param do what ever you want with.

$  ./xsltproc.sh --param='lang=en' id.xsl in.xml
OUTPUT = in.xml
--param = lang=en
INPUT = id.xsl

better would be to let docopts parse it by introducing a --lang parameter.

$ ./xsltproc.sh --lang=en id.xsl in.xml
OUTPUT = in.xml
--param = 
INPUT = id.xsl
--lang = en

@kendalldita
Copy link
Author

Yes. In general, I use software that tries to conform to standards, and try to find an audience that is also interested in both conforming to standards, and practical usages of those standards, while the vast majority of people only care about what is in front of their face at the moment. Then questions are shunted away to different environments designed to avoid anyone asking questions.

Thanks for enduring questions this far. I'll now go get my questions rejected on stack overflow.

@Sylvain303
Copy link
Collaborator

Oh, sorry to read that your question was rejected on stackoverflow. 😒

There's way to ask for help, especially in open source and free software community, you may learn with interacting with friendly or not-so-friendly people. 😉

I posted on stackoverflow yesterday for testing, following our conversation.

https://stackoverflow.com/questions/69292099/docopt-required-flag-where-the-value-for-it-can-only-be-one-of-a-few-options#new-answer

You should notice as I mentioned about docopt:

You should, may be, read more carefully how people get answer for there question. What you could improve on what I saw on the issues we exchanged is:

  • provide more detailed sample of code of what you're trying to achieve
  • read: https://dontasktoask.com/ and linked https://xyproblem.info/
  • explain the path you've followed already
  • give some background may also help
  • (re-)read "The Four Agreements" and be patient and do your best 😉

Yes, this is long and sometime disappointing, sometime very grateful 🤷‍♀️

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