-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpush.rs
93 lines (81 loc) · 2.12 KB
/
push.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use crate::Cli;
use tangram_client::{self as tg, Handle};
use tangram_either::Either;
/// Push a build or an object.
#[allow(clippy::struct_excessive_bools)]
#[derive(Clone, Debug, clap::Args)]
#[group(skip)]
pub struct Args {
#[arg(short, long)]
pub force: bool,
#[arg(long)]
pub logs: bool,
#[arg(long)]
pub recursive: bool,
#[arg(index = 1)]
pub reference: tg::Reference,
#[arg(short, long)]
pub remote: Option<String>,
#[arg(long)]
pub targets: bool,
}
impl Cli {
pub async fn command_push(&self, args: Args) -> tg::Result<()> {
let handle = self.handle().await?;
// Get the remote.
let remote = args.remote.unwrap_or_else(|| "default".to_owned());
// Get the reference.
let (referent, _) = self.get_reference(&args.reference).await?;
let item = match referent.item {
Either::Left(build) => Either::Left(build),
Either::Right(object) => {
let object = if let Some(subpath) = &referent.subpath {
let directory = object
.try_unwrap_directory()
.ok()
.ok_or_else(|| tg::error!("expected a directory"))?;
directory.get(&handle, subpath).await?.into()
} else {
object
};
Either::Right(object)
},
};
let item = match item {
Either::Left(build) => Either::Left(build.id().clone()),
Either::Right(object) => Either::Right(object.id(&handle).await?.clone()),
};
// Push the item.
match item.clone() {
Either::Left(build) => {
let args = crate::build::push::Args {
build,
logs: args.logs,
recursive: args.recursive,
remote: Some(remote.clone()),
targets: args.targets,
};
self.command_build_push(args).await?;
},
Either::Right(object) => {
let args = crate::object::push::Args {
object,
remote: Some(remote.clone()),
};
self.command_object_push(args).await?;
},
}
// If the reference has a tag, then put it.
if let tg::reference::Item::Tag(pattern) = args.reference.item() {
if let Ok(tag) = pattern.clone().try_into() {
let arg = tg::tag::put::Arg {
force: args.force,
item,
remote: Some(remote),
};
handle.put_tag(&tag, arg).await?;
}
}
Ok(())
}
}