1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#![allow(clippy::let_unit_value)]

use {anyhow::Error, fuchsia_async as fasync};

mod args;
mod channel;
mod check;
mod commit;
mod install;
mod monitor_state;
mod monitor_updates;
mod revert;

async fn handle_cmd(cmd: args::Command) -> Result<(), Error> {
    match cmd {
        args::Command::Channel(args::Channel { cmd }) => {
            crate::channel::handle_channel_control_cmd(cmd).await?;
        }
        args::Command::CheckNow(check_now) => {
            crate::check::handle_check_now_cmd(check_now).await?;
        }
        args::Command::MonitorUpdates(_) => {
            crate::monitor_updates::handle_monitor_updates_cmd().await?;
        }
        args::Command::ForceInstall(args) => {
            crate::install::handle_force_install(
                args.update_pkg_url,
                args.reboot,
                args.service_initiated,
            )
            .await?;
        }
        args::Command::WaitForCommit(_) => {
            crate::commit::handle_wait_for_commit().await?;
        }
        args::Command::Revert(_) => {
            crate::revert::handle_revert().await?;
        }
    }
    Ok(())
}

pub fn main() -> Result<(), Error> {
    let mut executor = fasync::LocalExecutor::new();
    let args::Update { cmd } = argh::from_env();
    executor.run_singlethreaded(handle_cmd(cmd))
}