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

Avoid using arrays and work with List<String> #768

Open
bayrakta opened this issue Sep 17, 2024 · 0 comments
Open

Avoid using arrays and work with List<String> #768

bayrakta opened this issue Sep 17, 2024 · 0 comments

Comments

@bayrakta
Copy link

As I could not find any mechanism to extend a list, I am trying to build a list of strings and work with the result in several spots to loop on it. The main idea is building a comma separated list as string and then split it by comma. However, the split method returns an array of String and I am not able to iterate on it. (The only method which works with an array is the join method, which can actually only work on a result of the split method and I don't see any meaningful use case for it.)

I would propose the following options to enhance the scripting capabilities :

  • Provide custom additional methods split and join, which work with List<String>, instead of using the ones from StringUtils.
  • Alternatively, new additional method(s) might be introduced to extend an existing list, such as extendList(List<String>, String) and appendList(List<String>, List<String>).

Sample block when the method extendList introduced :

- DEF MY_SITE_LIST=[]
- FOR siteNode IN CHILDREN OF /content:
    - DEF siteName=${siteNode.name}
    - DEF MY_SITE_LIST=${extendList(MY_SITE_LIST, siteName)}

- FOR siteName IN ${MY_SITE_LIST}:
    - DEF siteGroupName="sample-group-${siteName}"
    - ${siteGroupName}:
        - path: "/home/groups/myproject/${siteGroupName}"

P.S.: Once the improvements prepared, the last block needs to be tested. As far as I remember, the changes on MY_LIST is only in effect within the outermost FOR loop. Outside of the loop, it remains intact. This causes code duplicates, as overriding a global variable within a loop is not possible.

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

1 participant