Skip to content

Variable type conversion with command line variables #2946

Closed

Description

@jkyto

Currently it is only possible to set strings on command line e.g. --variable foo:bar but there is no documented syntax to set up other data types. To be able to set lists and dictionaries would be handy on some cases, for instance.

Activity

  1. aaltat commented on Sep 22, 2018

    @aaltat
    Contributor

    Are you looking similar what is proposed in the #2957 ? If you aren't, could you explain what you are actually want?

  2. pekkaklarck commented on Sep 23, 2018

    @pekkaklarck
    Member

    #2957 covers lists and dicts, but supporting also other base types, mainly numbers and Booleans, could be handy as well. Possible solutions:

    1. Separate prefixes such as INT__ similarly as Support providing list and dictionary variables from command line. #2957 proposes LIST__.

    2. Generic prefix to mean that the value should be evaluated in Python. Could be something like EVAL__ or PYTHON__.

    3. Some other way to specify the type. Syntax inspired by function annotations line --variable VAR:int:42 could work. Should use the same with lists and dicts as well.

    4. Support Robot's variables in values. That would allow e.g. integers like --variable 'VAR:${42}' and also support possible useful usages like -v VAR:foo -v VAR2:${VAR}bar.

  3. pekkaklarck commented on Sep 23, 2018

    @pekkaklarck
    Member

    Especially if we go with the option 3, we should use the new type conversion code to handle the values. We could then consider using the same syntax in the test data as well:

    *** Variables ***
    ${VAR:int}         42
    ${V2:list}         ['foo', 'bar']
    
  4. pekkaklarck commented on Aug 15, 2019

    @pekkaklarck
    Member

    I closed #2957 as a duplicate of this issue. If we add support for non-string variable values from the CLI, we definitely should support lists and dicts as well as numbers and Booleans.

    Thinking this again and looking at the possible solutions I listed above my current thinking is that:

    • Prefixes like INT__ and LIST__ or the generic EVAL__ are all pretty ugly.

    • Postfix used like --variable VAR:int:42 look much better. Supporting them in the Variables section the test data as proposed the comment above would be super useful as well but should get its own issue.

    • Being able to use variables on the CLI like --variable 'VAR:${42}' could be useful as well. It wouldn't support lists/dicts, though, but being able to refer to earlier variables like -v HOST:1.2.3.4 -v 'URL:http://${HOST}/example' would be handy.

    I'd say we should go with the <name>:<type>:<value> design. For backwards compatibility reasons we cannot make the <type> part mandatory, though, and should handle situation where the value contains colons like -v URL:http://.... Basically we should use the type information only if we recognize the part between colons.

  5. added
    good first issue
    help wanted
    on Aug 15, 2019
  6. aaltat commented on Aug 15, 2019

    @aaltat
    Contributor

    I also like the <name>:<type>:<value> syntax and give my vote for it.

  7. added this to the v3.2 milestone on Aug 23, 2019
  8. pekkaklarck commented on Oct 16, 2019

    @pekkaklarck
    Member

    The more I think about this, the more I like the <name>:<type>:<value> syntax. It would also work great with the proposed variable/argument type conversion in test data (#3278). These issues should probably be designed and also implemented together. Especially the latter is too big for RF 3.2 (unless we get external help), and I think this one should be moved from its scope as well.

  9. removed this from the v3.2 milestone on Oct 16, 2019
  10. pekkaklarck commented on May 20, 2025

    @pekkaklarck
    Member

    Variable type conversion has been implemented and will be part of RF 7.3 (#3278). When designing it with @aaltat , we discussed also about command line variables but later forgot about them. Let's add that support in RF 7.4.

  11. 6 remaining items

  12. changed the title [-]Variable type conversion wiht command line variables[/-] [+]Variable type conversion with command line variables[/+] on May 20, 2025
  13. pekkaklarck commented on May 20, 2025

    @pekkaklarck
    Member

    I prototyped this and this turned out to be very easy to implement using syntax name: type:value that, as discussed above, ought to be mostly backwards-compatible. I consider this so important part of the overall variable type conversion that I'll add this to RF 7.3 and create rc3 once this is ready.

  14. modified the milestones: v7.4, v7.3 on May 20, 2025
  15. self-assigned this
    on May 20, 2025
  16. pekkaklarck commented on May 20, 2025

    @pekkaklarck
    Member

    Documenting this will be done as part of documenting #3278.

  17. added a commit that references this issue on May 20, 2025
    7781d8f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions