use std::io::IsTerminal;
pub const TOKEN: &str = "\
## Get an OAuth token
1. Create an application at https://oauth.yandex.ru/client/new — pick
**For API access or debugging**, and grant `tracker:write` for full access
or `tracker:read` to stay read-only.
2. Copy the application's **ClientID** from its page.
3. Open `https://oauth.yandex.ru/authorize?response_type=token&client_id=<ClientID>`
and sign in. The token comes back in the address bar you land on.
**Stay on one domain for both steps.** `oauth.yandex.com` works too, but it is a
separate origin with its own cookies, so your browser may be signed in there as
somebody else — or as nobody. An application created under one account and
authorised under another produces a token for the wrong person, and the first
sign of it is `auth status` naming a stranger.
It looks like `y0__xAbc...`, roughly 60-90 characters.
Docs: https://yandex.ru/support/tracker/en/api-ref/access
";
pub const ORG: &str = "\
## Find your organisation id
Open https://tracker.yandex.ru/admin/orgs — it lists every organisation you are
in, with its id, and says which kind each one is.
| Kind | Id looks like | Flag |
|:-|:-|:-|
| Yandex 360 for Business | `1234567` | `--org-kind yandex360` |
| Yandex Cloud Organization | `bpfaidqca8vd0m5jl3fp` | `--org-kind cloud` |
Not sure which you have? Omit `--org-kind`: login tries both and reports which
one answered. The two use different headers, and the wrong one returns **403** —
which reads like a rights problem rather than a configuration mistake.
Docs: https://yandex.ru/support/tracker/en/api-ref/access
";
const INTRO: &str = "\
Store a token for an account, and set up a profile to use it with.
```
ytcli auth login
ytcli auth login --account work --org-id 1234567 --profile work
ytcli auth login --account work --org-id 1234567 --dry-run
```
Run it with no arguments in a terminal and it walks you through each step,
taking the token as a hidden password. Pass whatever you already know as flags
and only the rest is asked for. Outside a terminal the flags are all there is,
and the token is read from stdin.
";
#[must_use]
pub fn block(markdown: &str) -> String {
if !std::io::stderr().is_terminal() {
return markdown.to_owned();
}
crate::render::markdown::render(markdown, width())
}
#[must_use]
pub fn full() -> String {
block(&format!("{TOKEN}\n{ORG}"))
}
#[must_use]
pub fn login_help() -> String {
crate::cli::help::md(&format!("{INTRO}\n{TOKEN}\n{ORG}"))
}
fn width() -> usize {
crate::cli::terminal_width().clamp(40, 92)
}