1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
45use clap::{Args, Subcommand};
6use fxa_client::FirefoxAccount;
78use crate::{persist_fxa_state, Result};
910#[derive(Args)]
11pub struct DeviceArgs {
12#[command(subcommand)]
13command: Option<Command>,
14}
1516#[derive(Subcommand)]
17enum Command {
18 List,
19 SetName { name: String },
20}
2122pub fn run(account: &FirefoxAccount, args: DeviceArgs) -> Result<()> {
23match args.command.unwrap_or(Command::List) {
24 Command::List => list(account),
25 Command::SetName { name } => set_name(account, name),
26 }
27}
2829fn list(account: &FirefoxAccount) -> Result<()> {
30for device in account.get_devices(false)? {
31println!("{}: {}", device.id, device.display_name);
32 }
33Ok(())
34}
3536fn set_name(account: &FirefoxAccount, name: String) -> Result<()> {
37 account.set_device_name(&name)?;
38println!("Display name set to {name}");
39 persist_fxa_state(account)?;
40Ok(())
41}