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
use crate::cli::parser::ServiceArgs;
use crate::commands::base::{Command, CommandContext};
use anyhow::Result;
/// Implementation of the `service` command.
///
/// This struct holds the specific arguments parsed by `clap` and
/// implements the [Command] trait to execute Service command logic.
pub struct ServiceCommand {
/// Arguments specific to Service command.
args: ServiceArgs,
}
impl ServiceCommand {
pub fn new(args: ServiceArgs) -> Self {
Self { args }
}
}
impl Command for ServiceCommand {
/// Returns the unique identifier for this command.
fn name(&self) -> &'static str {
"service"
}
/// Executes the Service command logic.
///
/// With no `--service`, there is nothing new to load, so this just
/// re-serializes whatever service description is already loaded in the
/// session (useful in the interactive shell, where state persists
/// across commands).
fn execute(&self, ctx: &mut CommandContext) -> Result<()> {
let reader_mode = self.args.reader_mode.into();
let format = self.args.service_format.into();
let result_format = self.args.result_service_format.into();
if let Some(service) = &self.args.service {
let mut load_service_description = ctx
.rudof
.load_service_description(service)
.with_data_format(&format)
.with_reader_mode(&reader_mode);
if let Some(base) = &self.args.base_data.as_deref() {
load_service_description = load_service_description.with_base(base);
}
load_service_description.execute()?;
}
ctx.rudof
.serialize_service_description(&mut ctx.writer)
.with_result_service_format(&result_format)
.execute()?;
Ok(())
}
}