Skip to content

Commit fbe406f

Browse files
committed
cli: use async client
1 parent 1ca738a commit fbe406f

27 files changed

+371
-233
lines changed

Cargo.lock

Lines changed: 69 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ reqwest = { version = "0.11.11", default-features = false }
3232
serde = { version = "1.0.138", features = ["derive"] }
3333
serde_json = "1.0.82"
3434
structopt = { version = "0.3.26", default-features = false }
35+
tokio = { version = "1.19.2", features = ["rt"] }
3536
url = { version = "2.2.2", features = ["serde"] }
3637

3738
reinfer-client = { version = "0.12.0", path = "../api" }
39+
futures = "0.3.24"
3840

3941
[dev-dependencies]
4042
pretty_assertions = "1.2.1"

cli/src/commands/config.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub fn run(
117117
table.printstd();
118118
}
119119
ConfigArgs::ListContexts { .. } => {
120-
info!("No available contexts.");
120+
info!("No available contexts");
121121
}
122122
ConfigArgs::AddContext {
123123
name,
@@ -139,17 +139,17 @@ pub fn run(
139139
ConfigArgs::UseContext { name } => {
140140
if !config.set_current_context(name) {
141141
return Err(anyhow!(
142-
"No such context `{}` exists in `{}`.",
142+
"No such context `{}` exists in `{}`",
143143
name,
144144
config_path.as_ref().display(),
145145
));
146146
} else {
147147
config::write_reinfer_config(config_path, &config)?;
148-
info!("Switched to context `{}`.", name);
148+
info!("Switched to context `{}`", name);
149149
}
150150
}
151151
ConfigArgs::CurrentContext => config.get_current_context().map_or_else(
152-
|| info!("There is no default context in use."),
152+
|| info!("There is no default context in use"),
153153
|current_context| println!("{}", current_context.name),
154154
),
155155
ConfigArgs::GetToken { name } => match name.as_ref() {
@@ -158,21 +158,21 @@ pub fn run(
158158
"{}",
159159
config
160160
.get_current_context()
161-
.ok_or_else(|| anyhow!("There is no default context in use."))?
161+
.ok_or_else(|| anyhow!("There is no default context in use"))?
162162
.token
163163
.as_ref()
164-
.ok_or_else(|| anyhow!("The default context has no stored token."))?
164+
.ok_or_else(|| anyhow!("The default context has no stored token"))?
165165
);
166166
}
167167
Some(name) => {
168168
println!(
169169
"{}",
170170
config
171171
.get_context(name)
172-
.ok_or_else(|| anyhow!("No such context `{}`.", name))?
172+
.ok_or_else(|| anyhow!("No such context `{}`", name))?
173173
.token
174174
.as_ref()
175-
.ok_or_else(|| anyhow!("The context `{}` has no stored token.", name))?
175+
.ok_or_else(|| anyhow!("The context `{}` has no stored token", name))?
176176
);
177177
}
178178
},
@@ -181,13 +181,13 @@ pub fn run(
181181
if config.delete_context(name) {
182182
config::write_reinfer_config(&config_path, &config)?;
183183
info!(
184-
"Deleted context `{}` from `{}`.",
184+
"Deleted context `{}` from `{}`",
185185
name,
186186
config_path.as_ref().display()
187187
);
188188
} else {
189189
return Err(anyhow!(
190-
"No such context `{}` exists in `{}`.",
190+
"No such context `{}` exists in `{}`",
191191
name,
192192
config_path.as_ref().display()
193193
));
@@ -216,15 +216,15 @@ fn add_or_edit_context(
216216
if !name.is_empty() {
217217
break name;
218218
} else {
219-
error!("Context name cannot be empty.");
219+
error!("Context name cannot be empty");
220220
}
221221
};
222222

223223
let existing_context = config.get_context(&name);
224224
if existing_context.is_some() {
225-
info!("Context `{}` already exists, it will be modified.", name);
225+
info!("Context `{}` already exists, it will be modified", name);
226226
} else {
227-
info!("A new context `{}` will be created.", name);
227+
info!("A new context `{}` will be created", name);
228228
}
229229

230230
// Get API token (either argument or from stdin)
@@ -239,7 +239,7 @@ fn add_or_edit_context(
239239
));
240240
} else {
241241
warn!(
242-
"Be careful, API tokens are stored in cleartext in {}.",
242+
"Be careful, API tokens are stored in cleartext in {}",
243243
config_path.as_ref().display()
244244
);
245245
}
@@ -281,16 +281,16 @@ fn add_or_edit_context(
281281
let update_existing = existing_context.is_some();
282282
let is_new_context = !config.set_context(context);
283283
if is_new_context && config.num_contexts() == 1 {
284-
info!("Default context set to `{}`.", name);
284+
info!("Default context set to `{}`", name);
285285
config.set_current_context(&name);
286286
}
287287

288288
config::write_reinfer_config(config_path, &config)?;
289289

290290
if update_existing {
291-
info!("Context `{}` was updated.", name);
291+
info!("Context `{}` was updated", name);
292292
} else {
293-
info!("New context `{}` was created.", name);
293+
info!("New context `{}` was created", name);
294294
}
295295

296296
Ok(())

cli/src/commands/create/annotations.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ pub struct CreateAnnotationsArgs {
3838
no_progress: bool,
3939
}
4040

41-
pub fn create(client: &Client, args: &CreateAnnotationsArgs) -> Result<()> {
41+
pub async fn create(client: &Client, args: &CreateAnnotationsArgs) -> Result<()> {
4242
let source = client
4343
.get_source(args.source.clone())
44+
.await
4445
.with_context(|| format!("Unable to get source {}", args.source))?;
4546
let source_name = source.full_name();
4647

4748
let dataset = client
4849
.get_dataset(args.dataset.clone())
50+
.await
4951
.with_context(|| format!("Unable to get dataset {}", args.dataset))?;
5052
let dataset_name = dataset.full_name();
5153

@@ -75,7 +77,8 @@ pub fn create(client: &Client, args: &CreateAnnotationsArgs) -> Result<()> {
7577
} else {
7678
Some(progress_bar(file_metadata.len(), &statistics))
7779
};
78-
upload_annotations_from_reader(client, &source, file, &statistics, &dataset_name)?;
80+
upload_annotations_from_reader(client, &source, file, &statistics, &dataset_name)
81+
.await?;
7982
if let Some(mut progress) = progress {
8083
progress.done();
8184
}
@@ -94,7 +97,8 @@ pub fn create(client: &Client, args: &CreateAnnotationsArgs) -> Result<()> {
9497
BufReader::new(io::stdin()),
9598
&statistics,
9699
&dataset_name,
97-
)?;
100+
)
101+
.await?;
98102
statistics
99103
}
100104
};
@@ -107,7 +111,7 @@ pub fn create(client: &Client, args: &CreateAnnotationsArgs) -> Result<()> {
107111
}
108112

109113
#[allow(clippy::too_many_arguments)]
110-
fn upload_annotations_from_reader(
114+
async fn upload_annotations_from_reader(
111115
client: &Client,
112116
source: &Source,
113117
annotations: impl BufRead,
@@ -128,6 +132,7 @@ fn upload_annotations_from_reader(
128132
.as_deref(),
129133
new_comment.entities.as_ref(),
130134
)
135+
.await
131136
.with_context(|| {
132137
format!(
133138
"Could not update labelling for comment `{}`",

cli/src/commands/create/bucket.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct CreateBucketArgs {
2424
transform_tag: TransformTag,
2525
}
2626

27-
pub fn create(client: &Client, args: &CreateBucketArgs, printer: &Printer) -> Result<()> {
27+
pub async fn create(client: &Client, args: &CreateBucketArgs, printer: &Printer) -> Result<()> {
2828
let CreateBucketArgs {
2929
name,
3030
title,
@@ -41,6 +41,7 @@ pub fn create(client: &Client, args: &CreateBucketArgs, printer: &Printer) -> Re
4141
transform_tag,
4242
},
4343
)
44+
.await
4445
.context("Operation to create a bucket has failed")?;
4546
info!(
4647
"New bucket `{}` [id: {}] created successfully",

0 commit comments

Comments
 (0)