solana_tools_lite_cli/flows/presenter/
gen_presenter.rs1use crate::flows::presenter::{emit_line, pretty_print_json, Presentable};
4use crate::shell::error::CliError;
5use solana_tools_lite::models::results::GenResult;
6use std::fmt;
7
8impl Presentable for GenResult {
9 fn present(
10 &self,
11 json: bool,
12 show_secret: bool,
13 to_stderr: bool,
14 ) -> Result<(), CliError> {
15 let display = GenDisplay {
16 result: self,
17 show_secret,
18 };
19 match (json, show_secret) {
20 (true, true) => pretty_print_json(self, to_stderr)?,
21 (false, true) | (false, false) | (true, false) => {
22 emit_line(&display.to_string(), to_stderr)
23 }
24 }
25 Ok(())
26 }
27}
28
29struct GenDisplay<'a> {
30 result: &'a GenResult,
31 show_secret: bool,
32}
33
34impl<'a> fmt::Display for GenDisplay<'a> {
35 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36 if self.show_secret {
37 write!(
38 f,
39 "Mnemonic: {}\nPublic Key: {}\nSecret Key: {}\nSeed Hex: {}",
40 self.result.mnemonic,
41 self.result.public_key,
42 self.result.secret_key,
43 self.result.seed_hex
44 )
45 } else {
46 write!(f, "Public Key: {}", self.result.public_key)
47 }
48 }
49}