-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
execution_state.rs
38 lines (31 loc) · 998 Bytes
/
execution_state.rs
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
use serde::Serialize;
use crate::{cli::Args, commands::CommandBase};
#[derive(Debug, Serialize)]
pub struct ExecutionState<'a> {
pub remote_config: RemoteConfig<'a>,
pub cli_args: &'a Args,
}
#[derive(Debug, Serialize, Default)]
pub struct RemoteConfig<'a> {
pub token: Option<&'a str>,
pub team_id: Option<&'a str>,
pub team_slug: Option<&'a str>,
pub api_url: &'a str,
}
impl<'a> TryFrom<&'a CommandBase> for ExecutionState<'a> {
type Error = anyhow::Error;
fn try_from(base: &'a CommandBase) -> Result<Self, Self::Error> {
let repo_config = base.repo_config()?;
let user_config = base.user_config()?;
let remote_config = RemoteConfig {
token: user_config.token(),
team_id: repo_config.team_id(),
team_slug: repo_config.team_slug(),
api_url: repo_config.api_url(),
};
Ok(ExecutionState {
remote_config,
cli_args: base.args(),
})
}
}