1use mlua::UserData;
2
3use crate::{
4 git::url::RemoteGitUrl,
5 lua_rockspec::{DisplayAsLuaKV, DisplayLuaKV, DisplayLuaValue},
6};
7
8pub mod shorthand;
9pub mod url;
10pub mod utils;
11
12#[derive(Debug, PartialEq, Clone)]
13pub struct GitSource {
14 pub url: RemoteGitUrl,
15 pub checkout_ref: Option<String>,
16}
17
18impl UserData for GitSource {
19 fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
20 methods.add_method("url", |_, this, _: ()| Ok(this.url.to_string()));
21 methods.add_method("checkout_ref", |_, this, _: ()| {
22 Ok(this.checkout_ref.clone())
23 });
24 }
25}
26
27impl DisplayAsLuaKV for GitSource {
28 fn display_lua(&self) -> DisplayLuaKV {
29 let mut source_tbl = Vec::new();
30 source_tbl.push(DisplayLuaKV {
31 key: "url".to_string(),
32 value: DisplayLuaValue::String(format!("{}", self.url)),
33 });
34 if let Some(checkout_ref) = &self.checkout_ref {
35 source_tbl.push(DisplayLuaKV {
36 key: "tag".to_string(),
39 value: DisplayLuaValue::String(checkout_ref.to_string()),
40 });
41 }
42 DisplayLuaKV {
43 key: "source".to_string(),
44 value: DisplayLuaValue::Table(source_tbl),
45 }
46 }
47}