Skip to content

Support user input at runtime #92

Closed
Closed

Description

@ebr

It would be great to pause and wait for user input, for subsequent use in the script:

test:
  cmds:
    - read name
    - echo "hi ${name}"
$ task test 
read name
task: Failed to run task "test": exit status 127

I also tried moving the read command to Taskvars, but still no luck. I suspect this is because execution of go-task does not allocate a TTY? Is there any way to do this currently?

Activity

  1. added
    help wantedIssues that could benefit from members of the community contributing their expertise or experience.
    on Feb 17, 2018
  2. andreynering commented on Feb 17, 2018

    @andreynering
    Member

    I never thought about this possibility, and I don't know why it doesn't work. I'll think about it.

  3. andreynering commented on Mar 4, 2018

    @andreynering
    Member

    This currently possible as follows:

    read:
      cmds:
        - |
          echo "Type value of FOO:"
          read FOO;
          echo "You said: ${FOO}";
      silent: true

    And for allowing read in variables, I don't know if that makes sense. One can pass parameters to tasks using environment variables or the special syntax:

    task foo BAR=baz
  4. tommyknows commented on Feb 19, 2019

    @tommyknows

    Hi,
    Stumbled upon this issue while trying to work out the exact same thing.
    I want to ask the user for input for a few variables that are going to be used throughout the Taskfile.

    Obviously, as you noted, something like this panics:

    vars:
      MY_VAR:
        sh: read

    At the same time, I can't use this:

    env:
      MY_VAR: "{{.MY_VAR}}"
    tasks:
      get-vars:
        cmds:
          - {{if not .MY_VAR}}read MY_VAR; export MY_VAR{{end}}
      show-vars:
        cmds:
          - echo {{.MY_VAR}}

    Is there any way to export variables from the cmds to the taskfile?

  5. andreynering commented on Feb 21, 2019

    @andreynering
    Member

    @tommyknows Isn't passing variables via CLI enough for you? (See my comment here)

  6. tommyknows commented on Feb 22, 2019

    @tommyknows

    Well, as I've got quite a few variables to ask for, no (or only partially).
    I wanna allow the user to supply some variables via CLI (if he wishes to automate the call), and ask for every variable that is missing.

  7. andreynering commented on Feb 24, 2019

    @andreynering
    Member

    I think doing that via read results in a bad UX experience, because the user won't know what variable they are typing.

    If we implement something to allow that, that should have be handled by Task, that would print something like this:

    task: Please type the value for VAR (default: foobar): <cursor>
    

    I still think using the CLI a better on most use cases, though.

  8. andreynering commented on Aug 18, 2019

    @andreynering
    Member

    Some discussion about adding this is happening at #236.

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

    help wantedIssues that could benefit from members of the community contributing their expertise or experience.

    Fields

    No fields configured for feature.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions