pystardust / ani-cli

A cli tool to browse and play anime
GNU General Public License v3.0
7.77k stars 539 forks source link

What to do with piped input? #636

Closed rakusan2 closed 2 years ago

rakusan2 commented 2 years ago

Currently, piped input causes the script to break.

The following code can consume this input

if [ ! -t 0 ]; then
        # consume input
    pipe_input=$(cat)
        # replace stdin with tty
    exec 0</dev/tty
fi

The question after is what to do with it

  1. Use it as a query
  2. Use it as anime id
    • Possibly fall back to a querry
  3. Discard it
  4. Something else?
port19x commented 2 years ago

good question

71zenith commented 2 years ago

PIped input seems useless to me. ani-cli's main feature is that it's interactive.

rakusan2 commented 2 years ago

My intention is to simply add an input method that by my understanding is common while also removing a bug. It is not to take away any interactivity or functionality

For Example, with the PR #637 I can run:

port19x commented 2 years ago

I do see the value in that

port19x commented 2 years ago

Can you clarify what bug this would fix?

rakusan2 commented 2 years ago

The bug is that if something gets piped in, the script prints > Invalid choice entered infinitely

rakusan2 commented 2 years ago

An idea as to how the piped input can be useful for you is in running test cases. This is easy to do as each read command takes only a single line from what is piped in.

An environment variable can be used to enable such a mode and only the following changes need to be made to the code:

port19x commented 2 years ago

This would indeed be a very useful thing and could enable semi-automated testing