runcc/config/input/
run.rs1use serde::{Deserialize, Serialize};
2use std::cmp;
3use std::collections::HashMap;
4
5use super::super::{run::*, CommandConfig, CommandConfigFromScriptOptions, KillBehavior};
6use super::CommandConfigsInput;
7
8#[non_exhaustive]
9#[derive(Deserialize, Serialize)]
10pub struct RunConfigInput {
11 pub commands: CommandConfigsInput,
12 pub max_label_length: Option<usize>,
13 pub envs: Option<HashMap<String, String>>,
14 #[serde(default)]
15 pub windows_call_cmd_with_env: super::WindowsCallCmdWithEnv,
16 #[serde(default)]
17 pub kill: KillBehavior,
18}
19
20impl Into<RunConfig> for RunConfigInput {
21 fn into(self) -> RunConfig {
22 let Self {
23 commands,
24 max_label_length,
25 envs,
26 windows_call_cmd_with_env,
27 kill,
28 } = self;
29
30 let commands: Vec<CommandConfig> = commands.into_configs(&CommandConfigFromScriptOptions {
31 windows_call_cmd_with_env,
32 });
33
34 let real_max_label_length = commands
35 .iter()
36 .map(|cmd| cmd.label_length())
37 .max()
38 .unwrap_or(0);
39
40 let max_label_length = match max_label_length {
41 Some(0) | None => real_max_label_length,
42 Some(v) => cmp::min(v, real_max_label_length),
43 };
44
45 RunConfig {
46 commands,
47 max_label_length,
48 envs,
49 kill,
50 }
51 }
52}