Skip to main content

things3_cloud/commands/
set_auth.rs

1use crate::app::Cli;
2use crate::auth::write_auth;
3use crate::commands::Command;
4use anyhow::Result;
5use clap::Args;
6use std::io::{self, Write};
7
8#[derive(Debug, Default, Args)]
9#[command(about = "Configure Things Cloud credentials")]
10pub struct SetAuthArgs {}
11
12impl Command for SetAuthArgs {
13    fn run_with_ctx(
14        &self,
15        _cli: &Cli,
16        out: &mut dyn std::io::Write,
17        _ctx: &mut dyn crate::cmd_ctx::CmdCtx,
18    ) -> Result<()> {
19        print!("Things Cloud email: ");
20        io::stdout().flush()?;
21        let mut email = String::new();
22        io::stdin().read_line(&mut email)?;
23
24        print!("Things Cloud password: ");
25        io::stdout().flush()?;
26        let mut password = String::new();
27        io::stdin().read_line(&mut password)?;
28
29        let path = write_auth(email.trim(), password.trim_end())?;
30        writeln!(out, "Saved auth to {}", path.display())?;
31        Ok(())
32    }
33}