Skip to content

Commit cf0b3ee

Browse files
committed
feat: functioning incremental pushes and pulls
1 parent 7e23195 commit cf0b3ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+818
-3329
lines changed

packages/cli/src/lib.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,12 @@ enum Command {
127127

128128
Download(self::blob::download::Args),
129129

130-
#[command(hide = true)]
131-
Export(self::object::export::Args),
132-
133130
Format(self::package::format::Args),
134131

135132
Get(self::get::Args),
136133

137134
Health(self::health::Args),
138135

139-
#[command(hide = true)]
140-
Import(self::object::import::Args),
141-
142136
Init(self::package::init::Args),
143137

144138
#[command(alias = "ls")]
@@ -456,7 +450,7 @@ impl Cli {
456450
build_indexer: None,
457451
database,
458452
messenger: tangram_server::config::Messenger::default(),
459-
object_indexer: None,
453+
object_indexer: Some(tangram_server::config::ObjectIndexer::default()),
460454
path,
461455
store: None,
462456
url,
@@ -844,11 +838,9 @@ impl Cli {
844838
Command::Clean(args) => self.command_clean(args).boxed(),
845839
Command::Document(args) => self.command_package_document(args).boxed(),
846840
Command::Download(args) => self.command_blob_download(args).boxed(),
847-
Command::Export(args) => self.command_object_export(args).boxed(),
848841
Command::Format(args) => self.command_package_format(args).boxed(),
849842
Command::Get(args) => self.command_get(args).boxed(),
850843
Command::Health(args) => self.command_health(args).boxed(),
851-
Command::Import(args) => self.command_object_import(args).boxed(),
852844
Command::Init(args) => self.command_package_init(args).boxed(),
853845
Command::List(args) => self.command_tag_list(args).boxed(),
854846
Command::Log(args) => self.command_build_log(args).boxed(),
@@ -1062,7 +1054,7 @@ impl Cli {
10621054
None
10631055
};
10641056
let default = crate::config::Tracing {
1065-
filter: "tangram=info,tangram_client=info,tangram_database=info,tangram_server=info,tangram_vfs=info".to_owned(),
1057+
filter: "tangram_cli=info,tangram_client=info,tangram_database=info,tangram_server=info,tangram_vfs=info".to_owned(),
10661058
format: Some(crate::config::TracingFormat::Pretty),
10671059
};
10681060
let output_layer = config

packages/cli/src/object.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use crate::Cli;
22
use tangram_client as tg;
33

4-
pub mod export;
54
pub mod get;
6-
pub mod import;
75
pub mod metadata;
86
pub mod pull;
97
pub mod push;
@@ -19,9 +17,7 @@ pub struct Args {
1917

2018
#[derive(Clone, Debug, clap::Subcommand)]
2119
pub enum Command {
22-
Export(self::export::Args),
2320
Get(self::get::Args),
24-
Import(self::import::Args),
2521
Metadata(self::metadata::Args),
2622
Pull(self::pull::Args),
2723
Push(self::push::Args),
@@ -31,15 +27,9 @@ pub enum Command {
3127
impl Cli {
3228
pub async fn command_object(&self, args: Args) -> tg::Result<()> {
3329
match args.command {
34-
Command::Export(args) => {
35-
self.command_object_export(args).await?;
36-
},
3730
Command::Get(args) => {
3831
self.command_object_get(args).await?;
3932
},
40-
Command::Import(args) => {
41-
self.command_object_import(args).await?;
42-
},
4333
Command::Metadata(args) => {
4434
self.command_object_metadata(args).await?;
4535
},

packages/cli/src/object/export.rs

-77
This file was deleted.

packages/cli/src/object/import.rs

-53
This file was deleted.

packages/cli/src/progress.rs

+81-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use crate::Cli;
1+
use crate::{viewer::clip, Cli};
22
use crossterm::{self as ct, style::Stylize as _};
3-
use futures::{stream::TryStreamExt as _, Stream};
3+
use futures::{Stream, StreamExt as _};
44
use indexmap::IndexMap;
55
use num::ToPrimitive as _;
66
use std::{
7+
fmt::Write as _,
78
io::{IsTerminal as _, Write as _},
89
pin::pin,
910
};
@@ -15,7 +16,6 @@ impl Cli {
1516
&self,
1617
stream: impl Stream<Item = tg::Result<tg::progress::Event<T>>>,
1718
) -> tg::Result<T> {
18-
let mut indicators = IndexMap::new();
1919
let mut tty = std::io::stderr();
2020
let mut stream = pin!(stream);
2121

@@ -27,8 +27,14 @@ impl Cli {
2727
.ok_or_else(|| tg::error!("stream ended without output"));
2828
}
2929

30+
let mut indicators = IndexMap::new();
3031
let mut lines = None;
31-
while let Some(event) = stream.try_next().await? {
32+
while let Some(result) = stream.next().await {
33+
// Get the size of the tty.
34+
let size = ct::terminal::size().map_or((64, 64), |(columns, rows)| {
35+
(columns.to_usize().unwrap(), rows.to_usize().unwrap())
36+
});
37+
3238
// Clear the indicators.
3339
if let Some(lines) = lines {
3440
ct::queue!(
@@ -39,6 +45,11 @@ impl Cli {
3945
.unwrap();
4046
}
4147

48+
let event = match result {
49+
Ok(event) => event,
50+
Err(error) => return Err(error),
51+
};
52+
4253
match event {
4354
tg::progress::Event::Log(log) => {
4455
if let Some(level) = log.level {
@@ -78,8 +89,73 @@ impl Cli {
7889
}
7990

8091
// Render the indicators.
92+
let title_length = indicators
93+
.values()
94+
.map(|indicator| indicator.title.len())
95+
.max();
96+
let now = std::time::SystemTime::now()
97+
.duration_since(std::time::UNIX_EPOCH)
98+
.unwrap()
99+
.as_millis();
81100
for indicator in indicators.values() {
82-
writeln!(tty, "{indicator}").unwrap();
101+
const LENGTH: u64 = 20;
102+
const SPINNER: [char; 10] = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
103+
let position = (now / (1000 / 10)) % 10;
104+
let position = position.to_usize().unwrap();
105+
let spinner = crossterm::style::Stylize::blue(SPINNER[position]);
106+
let mut line = String::new();
107+
write!(line, "{spinner} ").unwrap();
108+
write!(
109+
tty,
110+
"{:title_length$} ",
111+
indicator.title,
112+
title_length = title_length.unwrap(),
113+
)
114+
.unwrap();
115+
if let (Some(current), Some(total)) = (indicator.current, indicator.total) {
116+
write!(line, " [").unwrap();
117+
let last = current * LENGTH / total;
118+
for _ in 0..last {
119+
write!(line, "=").unwrap();
120+
}
121+
if current < total {
122+
write!(line, ">").unwrap();
123+
} else {
124+
write!(line, "=").unwrap();
125+
}
126+
for _ in last..LENGTH {
127+
write!(line, " ").unwrap();
128+
}
129+
write!(line, "]").unwrap();
130+
}
131+
if let Some(current) = indicator.current {
132+
match indicator.format {
133+
tg::progress::IndicatorFormat::Normal => {
134+
write!(line, " {current}").unwrap();
135+
},
136+
tg::progress::IndicatorFormat::Bytes => {
137+
let current = byte_unit::Byte::from_u64(current)
138+
.get_appropriate_unit(byte_unit::UnitType::Decimal);
139+
write!(line, " {current:#.1}").unwrap();
140+
},
141+
}
142+
if let Some(total) = indicator.total {
143+
match indicator.format {
144+
tg::progress::IndicatorFormat::Normal => {
145+
write!(line, " of {total}").unwrap();
146+
},
147+
tg::progress::IndicatorFormat::Bytes => {
148+
let total = byte_unit::Byte::from_u64(total)
149+
.get_appropriate_unit(byte_unit::UnitType::Decimal);
150+
write!(line, " of {total:#.1}").unwrap();
151+
},
152+
}
153+
let percent = 100.0 * current.to_f64().unwrap() / total.to_f64().unwrap();
154+
write!(line, " {percent:.2}%").unwrap();
155+
}
156+
}
157+
let line = clip(&line, size.0);
158+
writeln!(tty, "{line}").unwrap();
83159
}
84160
lines = Some(indicators.len().to_u16().unwrap());
85161

packages/cli/src/viewer.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,15 @@ fn render_block_and_get_area(title: &str, focused: bool, area: Rect, buf: &mut B
349349
.unwrap_or(area)
350350
}
351351

352-
fn clip(string: &str, mut width: usize) -> &str {
353-
let mut boundary = 0;
352+
pub(crate) fn clip(string: &str, mut width: usize) -> &str {
353+
let mut len = 0;
354354
let mut chars = string.chars();
355355
while width > 0 {
356356
let Some(char) = chars.next() else {
357357
break;
358358
};
359-
boundary += char.len_utf8();
359+
len += char.len_utf8();
360360
width = width.saturating_sub(char.width().unwrap_or(0));
361361
}
362-
&string[0..boundary]
362+
&string[0..len]
363363
}

0 commit comments

Comments
 (0)