twitch-tui icon indicating copy to clipboard operation
twitch-tui copied to clipboard

fix: ignored TWT_TOKEN env variable

Open Yokann opened this issue 1 year ago • 7 comments

Hi !

Discovered this tool yesterday. I wondered why I can't pass TWT_TOKEN env variable to the CLI. It seems the variable is ignored.

I made this fix. It should deserve a test, but I don't know Rust so much.

Yokann avatar May 05 '24 20:05 Yokann

Codecov Report

Attention: Patch coverage is 0% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 19.26%. Comparing base (882e816) to head (d368c95). Report is 1 commits behind head on main.

Files Patch % Lines
src/handlers/config.rs 0.00% 1 Missing :warning:
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #592   +/-   ##
=======================================
  Coverage   19.26%   19.26%           
=======================================
  Files          41       41           
  Lines        5086     5086           
=======================================
  Hits          980      980           
  Misses       4106     4106           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar May 05 '24 20:05 codecov[bot]

Hi! Thanks for the PR. Don't worry about the failing CI on formatting, I'll be testing this just on functionality.

Xithrius avatar May 05 '24 22:05 Xithrius

Hi, If I tried to pass the variable as environment variable, I get this error. So I looked into the checking part.

Twitch config section is missing one or more of the following: username, channel, token.

I don't think the error is relative to a shell, as I got the same result from bash or zsh on Arch.

Here is the part of my script I am trying to run. The $ACCESSTOKEN is valid, tested directly in the twt config file.

streamlink -Q "--twitch-api-header=Authorization=Bearer $ACCESSTOKEN" https://www.twitch.tv/$selected_channel &
TWT_TOKEN="oauth:$ACCESSTOKEN" twt -c $selected_channel

Let me do some recheck. It's weird.

Yokann avatar May 07 '24 13:05 Yokann

I also tried export TWT_TOKEN=*****. It doesn't change anything.

Yokann avatar May 07 '24 13:05 Yokann

What version of twitch-tui are you on? I tried the same command as yours with my token, seemed to work fine.

Xithrius avatar May 10 '24 03:05 Xithrius

I'm using twitch-tui 2.6.7 and rust 1.78.0. I did a fresh install on a different machine (Macbook) and I've got the same issue.

Fun story, and that's why I thought my PR fix the issue, when I run from the source, it works totally fine

TWT_TOKEN=*** cargo run

but if I run it with the binary, the environment variable is ignored. :mindblowing:

TWT_TOKEN=*** ./target/debug/twt

Yokann avatar May 10 '24 10:05 Yokann

Do the changes in this PR fix the issue you're experiencing?

Xithrius avatar May 10 '24 19:05 Xithrius

I updated the PR and changed the way the code get the variable, and everything seems fine now. Maybe an issue with the option_env macro.

Yokann avatar May 12 '24 16:05 Yokann

Ah, yeah that might just fix it. I'll test it very soon. I have a feeling it's to do with option_env's way of checking for the variable:

Optionally inspects an environment variable at compile time.

Xithrius avatar May 12 '24 20:05 Xithrius

Available in https://github.com/Xithrius/twitch-tui/releases/tag/v2.6.8

Xithrius avatar May 12 '24 20:05 Xithrius