cli/command/
return_code.rs

1// SPDX-License-Identifier: GPL-3-0-or-later
2// Copyright (c) 2024-2025 Jarkko Sakkinen
3// Copyright (c) 2025 Opinsys Oy
4
5use super::CommandError;
6use crate::{cli::SubCommand, context::ContextCache, convert::from_str_to_tpm_rc, device::Device};
7use argh::FromArgs;
8use std::{cell::RefCell, rc::Rc};
9use tpm2_protocol::data::TpmRc;
10
11/// Prints a TPM return code in human-readable format.
12#[derive(FromArgs, Debug)]
13#[argh(subcommand, name = "return-code")]
14pub struct ReturnCode {
15    /// return code in hex or decimal
16    #[argh(positional, from_str_fn(from_str_to_tpm_rc))]
17    pub rc: TpmRc,
18}
19
20impl SubCommand for ReturnCode {
21    fn run(
22        &self,
23        _device: Option<Rc<RefCell<Device>>>,
24        context: &mut ContextCache,
25        _plain: bool,
26    ) -> Result<(), CommandError> {
27        writeln!(context.writer, "{}", self.rc)?;
28        Ok(())
29    }
30
31    fn is_local(&self) -> bool {
32        true
33    }
34}