Skip to content

Add an If command #6

Description

@RomainGehrig

If(a, b, c)

  • First argument is a Python method that evaluates to True/False (by Python truthiness rules)
  • Second argument is a command for the true branch
  • Third argument is a command for the else branch, if given.

Design question: when should the first argument be evaluated ?

  • At compose time: we only have access to config and args. Theoretically, only the arguments of the taken branch would be needed but the branch may change between invocations. Argparser would then complain of missing or unrecognized parameters.
  • At run time: we have access to config, args and previous command output but we don't know which branch would be taken so we need arguments for both.

Alternative: StdinConverter can be (partially) used to replace the executed command at run time. Eg. StdinConverter(Cmd(sub=BranchA()), converter=lambda s: {} if not predicate(s) else {'sub': BranchB()}). However, it would not expose the arguments of BranchB and Cmd is a command that takes a subcommand as its argument.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    designThis needs some thinkingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions