Skip to content

Commit

Permalink
Cargo fmt fixes
Browse files Browse the repository at this point in the history
Signed-off-by: binoychitale <binoychitale@gmail.com>
  • Loading branch information
binoychitale committed Jan 29, 2021
1 parent 4f0fe2e commit dc27244
Showing 1 changed file with 127 additions and 80 deletions.
207 changes: 127 additions & 80 deletions client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::error::Error;

use clap::{App, Arg, SubCommand, AppSettings};
use clap::{App, AppSettings, Arg, SubCommand};
use failure::Fail;
use indradb::{
EdgeKey, EdgePropertyQuery, EdgeQuery, SpecificEdgeQuery, SpecificVertexQuery, VertexPropertyQuery, VertexQuery,
};
use indradb_proto as proto;
use std::convert::TryInto;
use failure::Fail;
use indradb::{VertexQuery, SpecificVertexQuery, VertexPropertyQuery, EdgeQuery, SpecificEdgeQuery, EdgePropertyQuery, EdgeKey};

#[tokio::main]
pub async fn main() -> Result<(), Box<dyn Error>> {
Expand All @@ -14,9 +16,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
let outbound_id_arg = Arg::with_name("outbound_id")
.help("the outbound vertex ID")
.required(true);
let edge_type_arg = Arg::with_name("type")
.help("the edge type")
.required(true);
let edge_type_arg = Arg::with_name("type").help("the edge type").required(true);
let inbound_id_arg = Arg::with_name("inbound_id")
.help("the inbound vertex ID")
.required(true);
Expand Down Expand Up @@ -103,7 +103,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
.long("type")
.value_name("type")
.takes_value(true),
)
),
),
)
.subcommand(
Expand Down Expand Up @@ -143,7 +143,7 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
.subcommand(
SubCommand::with_name("edge")
.about("deletes edges by query")
.args(&edge_query_arg)
.args(&edge_query_arg),
)
.subcommand(
SubCommand::with_name("vertex-property")
Expand All @@ -161,7 +161,9 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
.get_matches();

let address = matches.value_of("address").unwrap();
let mut client = proto::Client::new(String::from(address).try_into().unwrap()).await.map_err(|err| err.compat())?;
let mut client = proto::Client::new(String::from(address).try_into().unwrap())
.await
.map_err(|err| err.compat())?;

if let Some(_) = matches.subcommand_matches("ping") {
client.ping().await.map_err(|err| err.compat())?;
Expand All @@ -175,21 +177,27 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
None => indradb::util::generate_uuid_v1(),
};
let vertex = indradb::Vertex::with_id(uuid, vertex_type);
let res = client.transaction()
.await.map_err(|err| err.compat())?
let res = client
.transaction()
.await
.map_err(|err| err.compat())?
.create_vertex(&vertex)
.await.map_err(|err| err.compat())?;
.await
.map_err(|err| err.compat())?;
if !res {
return Err(indradb::Error::UuidTaken.compat())?;
}

println!("{:?}", vertex);
} else if let Some(matches) = matches.subcommand_matches("edge") {
let edge_key = build_edge_key(matches)?;
let res = client.transaction()
.await.map_err(|err| err.compat())?
let res = client
.transaction()
.await
.map_err(|err| err.compat())?
.create_edge(&edge_key)
.await.map_err(|err| err.compat())?;
.await
.map_err(|err| err.compat())?;
if !res {
return Err(indradb::Error::VertexInvalid.compat())?;
}
Expand All @@ -199,146 +207,185 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
let vertex_query = build_vertex_query(matches)?;
let property_name = matches.value_of("name").unwrap();
let property_value = serde_json::from_str(matches.value_of("value").unwrap())?;
client.transaction()
.await.map_err(|err| err.compat())?
client
.transaction()
.await
.map_err(|err| err.compat())?
.set_vertex_properties(VertexPropertyQuery::new(vertex_query, property_name), &property_value)
.await.map_err(|err| err.compat())?;

.await
.map_err(|err| err.compat())?;
} else if let Some(matches) = matches.subcommand_matches("edge-property") {
let property_name = matches.value_of("name").unwrap();
let property_value = serde_json::from_str(matches.value_of("value").unwrap())?;
let edge_query = build_edge_query(build_edge_key(matches)?)?;
client.transaction()
.await.map_err(|err| err.compat())?
client
.transaction()
.await
.map_err(|err| err.compat())?
.set_edge_properties(EdgePropertyQuery::new(edge_query, property_name), &property_value)
.await.map_err(|err| err.compat())?;
.await
.map_err(|err| err.compat())?;
}
} else if let Some(matches) = matches.subcommand_matches("count") {
if let Some(_) = matches.subcommand_matches("vertex") {
let vertex_count = client.transaction()
.await.map_err(|err| err.compat())?
.get_vertex_count()
.await.map_err(|err| err.compat())?;
let vertex_count = client
.transaction()
.await
.map_err(|err| err.compat())?
.get_vertex_count()
.await
.map_err(|err| err.compat())?;
println!("{}", vertex_count);
} else if let Some(matches) = matches.subcommand_matches("edge") {
let vertex_id = uuid::Uuid::parse_str(matches.value_of("id").unwrap()).map_err(|err| err.compat())?;
let edge_direction = match matches.value_of("inbound") {
Some(_) => indradb::EdgeDirection::Inbound,
Some(_) => indradb::EdgeDirection::Inbound,
None => indradb::EdgeDirection::Outbound,
};
let edge_type = match matches.value_of("type") {
Some(edge_type) => Some(indradb::Type::new(edge_type).map_err(|err| err.compat())?),
Some(edge_type) => Some(indradb::Type::new(edge_type).map_err(|err| err.compat())?),
None => None,
};
let res = client.transaction()
.await.map_err(|err| err.compat())?
let res = client
.transaction()
.await
.map_err(|err| err.compat())?
.get_edge_count(vertex_id, edge_type.as_ref(), edge_direction)
.await.map_err(|err| err.compat())?;
.await
.map_err(|err| err.compat())?;

println!("{}", res);
}
} else if let Some(matches) = matches.subcommand_matches("get") {
if let Some(matches) = matches.subcommand_matches("vertex") {
let vertex_query = build_vertex_query(matches)?;
let vertices = client.transaction()
.await.map_err(|err| err.compat())?
let vertices = client
.transaction()
.await
.map_err(|err| err.compat())?
.get_vertices(vertex_query)
.await.map_err(|err| err.compat())?;
.await
.map_err(|err| err.compat())?;

println!("{:?}", vertices);
} else if let Some(matches) = matches.subcommand_matches("edge") {
let edge_query = build_edge_query(build_edge_key(matches)?)?;
let edges = client.transaction()
.await.map_err(|err| err.compat())?
let edges = client
.transaction()
.await
.map_err(|err| err.compat())?
.get_edges(edge_query)
.await.map_err(|err| err.compat())?;
.await
.map_err(|err| err.compat())?;

println!("{:?}", edges);
} else if let Some(matches) = matches.subcommand_matches("vertex-property") {
let property_name = matches.value_of("name");
match property_name {
Some(property_name) => {
let vertex_property = client.transaction()
.await.map_err(|err| err.compat())?
Some(property_name) => {
let vertex_property = client
.transaction()
.await
.map_err(|err| err.compat())?
.get_vertex_properties(VertexPropertyQuery::new(build_vertex_query(matches)?, property_name))
.await.map_err(|err| err.compat())?;
.await
.map_err(|err| err.compat())?;

println!("{:?}", vertex_property);
},
}
None => {
let vertex_properties = client.transaction()
.await.map_err(|err| err.compat())?
let vertex_properties = client
.transaction()
.await
.map_err(|err| err.compat())?
.get_all_vertex_properties(build_vertex_query(matches)?)
.await.map_err(|err| err.compat())?;

.await
.map_err(|err| err.compat())?;

println!("{:?}", vertex_properties);
}
}
} else if let Some(matches) = matches.subcommand_matches("edge-property") {
let property_name = matches.value_of("name");
let edge_query = build_edge_query(build_edge_key(matches)?)?;
match property_name {
Some(property_name) => {
let edge_property = client.transaction()
.await.map_err(|err| err.compat())?
Some(property_name) => {
let edge_property = client
.transaction()
.await
.map_err(|err| err.compat())?
.get_edge_properties(EdgePropertyQuery::new(edge_query, property_name))
.await.map_err(|err| err.compat())?;
.await
.map_err(|err| err.compat())?;

println!("{:?}", edge_property);
},
}
None => {
let edge_property = client.transaction()
.await.map_err(|err| err.compat())?
let edge_property = client
.transaction()
.await
.map_err(|err| err.compat())?
.get_all_edge_properties(edge_query)
.await.map_err(|err| err.compat())?;
.await
.map_err(|err| err.compat())?;

println!("{:?}", edge_property);
}
}

}
} else if let Some(matches) = matches.subcommand_matches("delete") {
if let Some(matches) = matches.subcommand_matches("vertex") {
client.transaction()
.await.map_err(|err| err.compat())?
if let Some(matches) = matches.subcommand_matches("vertex") {
client
.transaction()
.await
.map_err(|err| err.compat())?
.delete_vertices(build_vertex_query(matches)?)
.await.map_err(|err| err.compat())?;

} else if let Some(matches) = matches.subcommand_matches("edge") {

client.transaction()
.await.map_err(|err| err.compat())?
.await
.map_err(|err| err.compat())?;
} else if let Some(matches) = matches.subcommand_matches("edge") {
client
.transaction()
.await
.map_err(|err| err.compat())?
.delete_edges(build_edge_query(build_edge_key(matches)?)?)
.await.map_err(|err| err.compat())?;

.await
.map_err(|err| err.compat())?;
} else if let Some(matches) = matches.subcommand_matches("vertex-property") {
let property_name = matches.value_of("name").unwrap();

client.transaction()
.await.map_err(|err| err.compat())?
client
.transaction()
.await
.map_err(|err| err.compat())?
.delete_vertex_properties(VertexPropertyQuery::new(build_vertex_query(matches)?, property_name))
.await.map_err(|err| err.compat())?;

.await
.map_err(|err| err.compat())?;
} else if let Some(matches) = matches.subcommand_matches("edge-property") {
let property_name = matches.value_of("name").unwrap();

client.transaction()
.await.map_err(|err| err.compat())?
.delete_edge_properties(EdgePropertyQuery::new(build_edge_query(build_edge_key(matches)?)?, property_name))
.await.map_err(|err| err.compat())?;

client
.transaction()
.await
.map_err(|err| err.compat())?
.delete_edge_properties(EdgePropertyQuery::new(
build_edge_query(build_edge_key(matches)?)?,
property_name,
))
.await
.map_err(|err| err.compat())?;
}
}

Ok(())
}

fn build_vertex_query(matches: &clap::ArgMatches) -> Result<VertexQuery, Box<dyn Error>>{
fn build_vertex_query(matches: &clap::ArgMatches) -> Result<VertexQuery, Box<dyn Error>> {
let vertex_id = uuid::Uuid::parse_str(matches.value_of("uuid").unwrap()).map_err(|err| err.compat())?;

Ok(VertexQuery::Specific(SpecificVertexQuery::single(vertex_id)))
}

fn build_edge_key(matches: &clap::ArgMatches) -> Result<EdgeKey, Box<dyn Error>>{
fn build_edge_key(matches: &clap::ArgMatches) -> Result<EdgeKey, Box<dyn Error>> {
let edge_type = indradb::Type::new(matches.value_of("type").unwrap()).map_err(|err| err.compat())?;
let outbound_id = uuid::Uuid::parse_str(matches.value_of("outbound_id").unwrap())?;
let inbound_id = uuid::Uuid::parse_str(matches.value_of("inbound_id").unwrap())?;
Expand All @@ -347,6 +394,6 @@ fn build_edge_key(matches: &clap::ArgMatches) -> Result<EdgeKey, Box<dyn Error>>
Ok(edge_key)
}

fn build_edge_query(edge_key: EdgeKey) -> Result<EdgeQuery, Box<dyn Error>>{
fn build_edge_query(edge_key: EdgeKey) -> Result<EdgeQuery, Box<dyn Error>> {
Ok(EdgeQuery::Specific(SpecificEdgeQuery::single(edge_key)))
}
}

0 comments on commit dc27244

Please sign in to comment.