Skip to content

Commit

Permalink
Added serializer option to connect command
Browse files Browse the repository at this point in the history
  • Loading branch information
wolf4ood committed Sep 30, 2020
1 parent 45d56c9 commit 925057b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 2 additions & 0 deletions gremlin-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ uuid = "0.8.1"
chrono = "0.4.15"
structopt = { version = "0.3", default-features = false }
prettytable-rs = "0.8.0"
anyhow = "1.0.32"




Expand Down
38 changes: 36 additions & 2 deletions gremlin-cli/src/actions/connect.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
use crate::{actions::Action, command::Command, context::GremlinContext};
use futures::FutureExt;
use gremlin_client::{aio::GremlinClient, ConnectionOptions, TlsOptions};

use gremlin_client::{aio::GremlinClient, ConnectionOptions, GraphSON, TlsOptions};
use std::str::FromStr;
use structopt::StructOpt;

use anyhow::{anyhow, Error};
use structopt::clap::AppSettings;

pub struct ConnectAction;

#[derive(Debug)]
pub enum Serializer {
GraphSONV1,
GraphSONV2,
GraphSONV3,
}

impl FromStr for Serializer {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"graphson_v1" => Ok(Serializer::GraphSONV1),
"graphson_v2" => Ok(Serializer::GraphSONV2),
"graphson_v3" => Ok(Serializer::GraphSONV3),
_ => Err(anyhow!("Serializer {} not valid", s)),
}
}
}

impl From<Serializer> for GraphSON {
fn from(serializer: Serializer) -> Self {
match serializer {
Serializer::GraphSONV1 => GraphSON::V1,
Serializer::GraphSONV2 => GraphSON::V2,
Serializer::GraphSONV3 => GraphSON::V3,
}
}
}
#[derive(Debug, StructOpt)]
#[structopt(name = "connect", no_version, global_settings = &[AppSettings::DisableVersion, AppSettings::NoBinaryName, AppSettings::ColoredHelp])]
struct Connect {
Expand All @@ -26,6 +56,9 @@ struct Connect {

#[structopt(long)]
password: Option<String>,

#[structopt(long, default_value = "graphson_v3")]
serializer: Serializer,
}

impl ConnectAction {
Expand Down Expand Up @@ -57,6 +90,7 @@ impl Action for ConnectAction {
.host(connect.host.as_str())
.port(connect.port)
.ssl(connect.ssl)
.serializer(connect.serializer.into())
.tls_options(TlsOptions {
accept_invalid_certs: connect.insecure,
});
Expand Down

0 comments on commit 925057b

Please sign in to comment.