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
use crate::cli::parser::DCTapArgs;
use crate::commands::base::{Command, CommandContext};
use anyhow::Result;
/// Implementation of the `dctap` command.
///
/// This struct holds the specific arguments parsed by `clap` and
/// implements the [Command] trait to execute DCTap server logic.
pub struct DctapCommand {
/// Arguments specific to DCTap server.
args: DCTapArgs,
}
impl DctapCommand {
pub fn new(args: DCTapArgs) -> Self {
Self { args }
}
}
impl Command for DctapCommand {
/// Returns the unique identifier for this command.
fn name(&self) -> &'static str {
"dctap"
}
/// Executes the DCTap server logic.
///
/// With no `--source-file`, there is nothing new to load, so this just
/// re-serializes whatever DCTap is already loaded in the session
/// (useful in the interactive shell, where state persists across
/// commands).
fn execute(&self, ctx: &mut CommandContext) -> Result<()> {
let format = self.args.format.into();
let result_format = self.args.result_format.into();
if let Some(file) = &self.args.file {
ctx.rudof.load_dctap(file).with_dctap_format(&format).execute()?;
}
ctx.rudof
.serialize_dctap(&mut ctx.writer)
.with_result_dctap_format(&result_format)
.execute()?;
Ok(())
}
}