Skip to content

Commit 40dea21

Browse files
committed
wire the main REPL to commands that interact with the ApiClient
1 parent 1d0ec54 commit 40dea21

5 files changed

Lines changed: 223 additions & 182 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ version = "0.1.0"
44
authors = ["Dylan Halperin <dylan@dylemma.io>"]
55

66
[dependencies]
7-
chrono = "0.4"
87
clap = "2.26.2"
98
colored = "1.5.3"
109
hyper = "0.11"
11-
maplit = "0.1.4"
1210
url = "1.5.1"
1311
serde = "1.0"
1412
serde_json = "1.0"

src/client.rs

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,14 @@ use std::time::Duration;
1717
#[derive(Debug, Serialize)]
1818
pub struct ApiProjectFilter<'a> {
1919
#[serde(skip_serializing_if = "Option::is_none")]
20-
name: Option<&'a str>,
20+
pub name: Option<&'a str>,
2121

2222
#[serde(skip_serializing_if = "Option::is_none")]
23-
metadata: Option<HashMap<&'a str, &'a str>>
24-
}
25-
impl <'a> ApiProjectFilter<'a> {
26-
pub fn new(name: &'a str, metadata: HashMap<&'a str, &'a str>) -> ApiProjectFilter<'a> {
27-
ApiProjectFilter{
28-
name: Some(name),
29-
metadata: Some(metadata)
30-
}
31-
}
32-
#[allow(dead_code)]
33-
pub fn empty() -> ApiProjectFilter<'static> {
34-
ApiProjectFilter{ name: None, metadata: None }
35-
}
36-
#[allow(dead_code)]
37-
pub fn with_name(&self, name: &'a str) -> ApiProjectFilter<'a> {
38-
ApiProjectFilter {
39-
name: Some(name),
40-
metadata: self.metadata.clone()
41-
}
42-
}
43-
#[allow(dead_code)]
44-
pub fn with_metadata(&self, metadata: HashMap<&'a str, &'a str>) -> ApiProjectFilter<'a> {
45-
ApiProjectFilter {
46-
name: self.name,
47-
metadata: Some(metadata)
48-
}
49-
}
23+
pub metadata: Option<HashMap<&'a str, &'a str>>
5024
}
5125

5226
/// A project provided by the Code Dx API.
53-
#[derive(Debug, Deserialize)]
27+
#[derive(Debug, Deserialize, Serialize)]
5428
pub struct ApiProject {
5529
pub id: u32,
5630
pub name: String,
@@ -179,7 +153,7 @@ pub trait PollingStrategy<T> {
179153
/// Simple polling strategy that always waits a fixed amount of time between iterations.
180154
impl <T: Debug> PollingStrategy<T> for Duration {
181155
fn next_wait(&self, iteration_number: usize, state: &T) -> Option<Duration> {
182-
println!("in poll (iteration {}, state: {:?})", iteration_number, state);
156+
println!("# Polling job completion, iteration {}: status = {:?}", iteration_number, state);
183157
Some(*self)
184158
}
185159
}
@@ -242,6 +216,10 @@ impl ApiClient {
242216
ApiClient { config, client }
243217
}
244218

219+
pub fn get_config(&self) -> &ClientConfig {
220+
self.config.as_ref()
221+
}
222+
245223
pub fn get_job_status(&self, job_id: &str) -> ApiResult<JobStatus> {
246224
self.api_get(&["api", "jobs", job_id])
247225
.expect_success()

src/config.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1+
extern crate clap;
2+
extern crate reqwest;
3+
extern crate url;
4+
5+
/// gets us the header! macro
6+
//#[macro_use] extern crate hyper;
7+
18
use clap::{Arg, ArgMatches, App};
29
use reqwest::{RequestBuilder};
310
use url::Url;
411

512
/// Connection information for Code Dx.
613
#[derive(Debug)]
714
pub struct ClientConfig {
8-
base_url: Url,
9-
auth_info: ClientAuth,
10-
insecure: bool
15+
pub base_url: Url,
16+
pub auth_info: ClientAuth,
17+
pub insecure: bool,
18+
pub no_prompt: bool
1119
}
1220

1321
/// declares the `ApiKey` type which implements the Header trait
@@ -89,6 +97,11 @@ impl ClientConfig {
8997
.long("insecure")
9098
.takes_value(false)
9199
.help("ignore https certificate validation")
100+
)
101+
.arg(Arg::with_name("no-prompt")
102+
.long("no-prompt")
103+
.takes_value(false)
104+
.help("don't output REPL prompts to STDOUT")
92105
);
93106
let matches = get_matches(app);
94107

@@ -112,13 +125,15 @@ impl ClientConfig {
112125
};
113126

114127
let insecure = matches.is_present("insecure");
128+
let no_prompt = matches.is_present("no-prompt");
115129

116130
base_uri.and_then(|uri| {
117131
client_auth_info.map(|auth| {
118132
ClientConfig {
119133
base_url: uri,
120134
auth_info: auth,
121-
insecure
135+
insecure,
136+
no_prompt,
122137
}
123138
})
124139
})

0 commit comments

Comments
 (0)