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

getopts #1856

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft

getopts #1856

wants to merge 2 commits into from

Conversation

chri2
Copy link
Contributor

@chri2 chri2 commented May 28, 2024

This is a draft that tested o.k. on the CI for apps for flohmarkt_ynh.

  • keeps backward compatibility
  • allows use of named and positional parameters
  • variables for returned parameters can be defined as arrays to have each content of a parameter that is used multiple times returned in its own array element
    • old behaviour: concatenate seperated by ';' is preserved if
    • use of arrays allows return values of parameters used multiple times to contain ';'
  • namerefs are used instead of eval to assign to indirect variables

chri2 added 2 commits May 28, 2024 12:42
* allow positional and named parameters
* re-organized code
* still could be refactored again
she-bang
@chri2
Copy link
Contributor Author

chri2 commented May 28, 2024

what it could be good for:

Let's say you want to parse a command line like --header="Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" --header='Forwarded: by="10.0.0.1"; for="192.168.0.1:4711"; proto=http; host="www.example.com:8080'. Those parameters to --header contain ';' and it would complicated to split them correctly into their parts if they would be concatenated by ';'.

example:

# usage: ynh_local_curl "page" "key1=value1" "key2=value2" ...
# | arg: -l --line_match: check answer against an extended regex
# | arg: -m --method:     request method to use: POST (default), PUT, GET, DELETE
# | arg: -H --header:     add a header to the request (can be used multiple times)
# | arg: -d --data:       data to be PUT or POSTed. Can be used multiple times.

    local -A args_array=( [l]=line_match= [m]=method= [H]=header= [n]=no_sleep [L]=location= [d]=data= [u]=user= [p]=password= )
    local method
    local -a header 
    local location
    local user
    local password
    local -a data

chri2 added a commit to chri2/yunohost that referenced this pull request May 29, 2024
@chri2 chri2 mentioned this pull request May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants