Skip to main content

run_init

Function run_init 

Source
pub async fn run_init<R, W, Fut>(
    reader: &mut R,
    writer: &mut W,
    config_path: &Path,
    profile_arg: Option<&str>,
    validate: impl Fn(String, String, String) -> Fut,
) -> Result<(), ApiError>
where R: BufRead, W: Write, Fut: Future<Output = Option<String>>,
Expand description

Interactive init flow with injectable IO and validator for testing.

validate receives (account_id, client_id, client_secret) and returns Some(display_name) on success or None on auth failure.

The flow adapts to context:

  • First-ever setup (no config file): defaults to “default” profile, shows OAuth setup URL, prompts credentials.
  • Config exists, no --profile flag: shows existing profiles and asks whether to update an existing one or add a new one.
  • --profile given: updates that profile if it exists, otherwise adds it.