component_debug/cli/
capability.rs

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2023 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.

use crate::capability::*;
use anyhow::Result;
use fidl_fuchsia_sys2 as fsys;

pub async fn capability_cmd<W: std::io::Write>(
    query: String,
    realm_query: fsys::RealmQueryProxy,
    mut writer: W,
) -> Result<()> {
    let segments = get_all_route_segments(query, &realm_query).await?;

    let mut decls = vec![];
    let mut exposes = vec![];
    let mut offers = vec![];
    let mut uses = vec![];

    for s in segments {
        match &s {
            RouteSegment::DeclareBy { .. } => decls.push(s),
            RouteSegment::ExposeBy { .. } => exposes.push(s),
            RouteSegment::OfferBy { .. } => offers.push(s),
            RouteSegment::UseBy { .. } => uses.push(s),
        }
    }

    if decls.is_empty() {
        writeln!(writer, "Declarations: None")?;
    } else {
        writeln!(writer, "Declarations:")?;
        for decl in decls {
            writeln!(writer, "  {}", decl)?;
        }
    }

    writeln!(writer, "")?;

    if exposes.is_empty() {
        writeln!(writer, "Exposes: None")?;
    } else {
        writeln!(writer, "Exposes:")?;
        for decl in exposes {
            writeln!(writer, "  {}", decl)?;
        }
    }

    writeln!(writer, "")?;

    if offers.is_empty() {
        writeln!(writer, "Offers: None")?;
    } else {
        writeln!(writer, "Offers:")?;
        for decl in offers {
            writeln!(writer, "  {}", decl)?;
        }
    }

    writeln!(writer, "")?;

    if uses.is_empty() {
        writeln!(writer, "Uses: None")?;
    } else {
        writeln!(writer, "Uses:")?;
        for decl in uses {
            writeln!(writer, "  {}", decl)?;
        }
    }

    Ok(())
}