Skip to content

Commit 976ef69

Browse files
committed
Resolve the token from WPCOM_TOKEN or ~/.wpcom-token when not passed
So the token can be set once instead of pasted every launch, sim-signin.sh falls back to the WPCOM_TOKEN environment variable, then a ~/.wpcom-token file, when neither --wpcom-token nor a positional token is given. Precedence: flag > env var > file.
1 parent ae140b0 commit 976ef69

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎Scripts/sim-signin.sh‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ Examples:
2727
Scripts/sim-signin.sh --wpcom-token <token> # Jetpack, booted simulator
2828
Scripts/sim-signin.sh --app wordpress --wpcom-token <token> # WordPress
2929
Scripts/sim-signin.sh --reset --wpcom-token <token> # wipe existing state first
30+
31+
Set the token once and omit it from the command line. Resolution order:
32+
1. --wpcom-token (or positional)
33+
2. WPCOM_TOKEN environment variable
34+
3. ~/.wpcom-token file
3035
EOF
3136
}
3237

@@ -63,8 +68,17 @@ while [[ $# -gt 0 ]]; do
6368
esac
6469
done
6570

71+
# Fall back to a token set once elsewhere, so it needn't be passed every launch:
72+
# the WPCOM_TOKEN environment variable, then a ~/.wpcom-token file.
73+
if [[ -z "$token" ]]; then
74+
token="${WPCOM_TOKEN:-}"
75+
fi
76+
if [[ -z "$token" && -f "$HOME/.wpcom-token" ]]; then
77+
token="$(tr -d '[:space:]' < "$HOME/.wpcom-token")"
78+
fi
79+
6680
if [[ -z "$token" ]]; then
67-
echo "error: missing <bearer-token>" >&2
81+
echo "error: no token — pass --wpcom-token <token>, set WPCOM_TOKEN, or write ~/.wpcom-token" >&2
6882
usage >&2
6983
exit 1
7084
fi

‎docs/simulator-sign-in.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Scripts/sim-signin.sh --app wordpress --wpcom-token <token> # WordPress
1212
Scripts/sim-signin.sh --reset --wpcom-token <token> # wipe existing state first
1313
```
1414

15+
To set the token once and drop it from the command line, export `WPCOM_TOKEN` (e.g. in `~/.zshrc`) or write it to `~/.wpcom-token`; the script uses either when `--wpcom-token` is omitted.
16+
1517
Or launch directly with the bearer token. The app finishes sign-in automatically while it sits on the login screen — no taps required:
1618

1719
```bash

0 commit comments

Comments
 (0)