Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 6 #10

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 48 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[package]
name = "trustgraph-rust-cli"
author ="Author"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "3.2.22", features = ["derive"] }
clap = { version = "4.0.15", features = ["derive"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
114 changes: 114 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
use serde::{Serialize, Deserialize};



use clap::{Parser, Subcommand, ValueEnum};



#[derive(Debug, Parser)]
#[command(name = "trust")]
#[clap(author, version, about = "TrustGraph CLI", long_about = None)]
pub struct Cli {
// #[arg(value_enum)]
// pub config: Option<ConfigSettings>,
#[command(subcommand)]
pub command: Option<Commands>,
}

// #[derive(Debug, Args)]
// enum ConfigSettings {

// }

#[derive(Debug, Subcommand)]
pub enum Commands {

#[command(arg_required_else_help = true)]
Claim {
/// DID or URL of claim target
#[arg(short ='t', long, required = true)]
target: String,
/// DID or URL of claim creator
#[arg(short, long, required = true)]
creator: Option<String>,
/// Rating tags (at least 1 tag is required)
#[arg(long, required = true, num_args(1..2))]
tags: Option<String>,
/// Rating description
#[arg(short, long)]
description: Option<String>,
/// Extra data (can be used multiple times)
// #[arg(short, long, action = clap::ArgAction::Count)]
// extra: Option<String>,
/// Rating weight in the range 0..1
#[arg(short, long)]
value: Option<f32>,
/// Signing algorithm
// #[arg(short, long, default_value = Some(String::from("EcdsaKoblitzSignature2016")))] // TODO: fix formatting error
// algorithm: Option<String>,
/// Private key
#[arg(short, long, required = true)]
private_key: Option<String>,
/// OpenTrustClaim | Reputon | TrustAtom | TrustClaim
#[arg(long, value_enum)]
target_format: Option<TargetFormat>,
/// Stdout | File | IPFS
#[arg(short, long, value_enum)]
write: Option<WriteTo>,
},

#[command(arg_required_else_help = true)]
Graph {
#[command(subcommand)]
subcommand: Option<GraphCommands>,

/// Perspective (identity) through which trust network is seen
#[arg(short, long)]
perspective: String,
/// DID or URL of claim creator
#[arg(short, long)]
creator: Option<String>,
/// DID or URL of claim target
#[arg(short = 't', long)]
target: Option<String>,
/// Filter by tags
#[arg(long, num_args(1..2))]
tags: Option<String>,
/// Crawls trust ratings to specified depth
#[arg(short, long)]
depth: Option<i8>,
/// Min trust rating 0..1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1 to 1

#[arg(long)]
min_value: Option<f32>,
/// Max trust rating 0..1
#[arg(long)]
max_value: Option<f32>,

},

}

#[derive(Debug, Clone, Subcommand, ValueEnum)]
pub enum GraphCommands {
/// Summarize claims / build analysis
Summarize,
/// Trust level relative to depth, eg: [1, 0.5 0.33]
Falloff,
}


#[derive(Debug, Clone, Serialize, Deserialize, ValueEnum)]
pub enum TargetFormat {
OpenTrustClaim,
Reputon,
TrustAtom,
TrustClaim,
}

#[derive(Debug, Clone, Serialize, Deserialize, ValueEnum)]
pub enum WriteTo {
Stdout,
File,
Ipfs,
}
93 changes: 78 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use serde_json::json;
// use clap::error::ErrorKind;
use clap::Parser;

/// Simple program to greet a person
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
mod cli;
use cli::{Cli, Commands};


/* TODO next:
Expand All @@ -21,20 +22,82 @@ use clap::Parser;

*/

struct Args {
/// Name of the person to greet
#[clap(short, long, value_parser)]
name: String,

/// Number of times to greet
#[clap(short, long, value_parser, default_value_t = 1)]
count: u8,
}

fn main() {
let args = Args::parse();
let args = Cli::parse();

match &args.command {
Some(Commands::Claim {
target,
creator,
tags,
description,
// extra,
value,
// algorithm,
private_key,
target_format,
write,
}) => {

// let json = json!({

// "@context": "https://raw.githubusercontent.com/trustgraph/trustgraph-schema/gh-pages/TrustClaim.jsonld",
// "type": target_format,
// "issuer": creator,
// "issued": "2017-03-04T02:05:07-08:00",
// "claim": {
// "@context": "https://schema.org/",
// "type": "Review",
// "itemReviewed": target,
// "author": creator,
// "keywords": tags,
// "reviewRating": {
// "@context": "https://schema.org/",
// "type": "Rating",
// "bestRating": 1,
// "worstRating": 0,
// "ratingValue": value,
// "description": description
// }
// },
// "signature": {
// "type": "EcdsaKoblitzSignature2016".to_string(),
// "http://purl.org/dc/terms/created": {
// "type": "http://www.w3.org/2001/XMLSchema#dateTime",
// "@value": "2017-03-04T10:05:07Z"
// },
// "http://purl.org/dc/terms/creator": {
// "id": "EcdsaKoblitz-public-key:020d79074ef137d4f338c2e6bef2a49c618109eccf1cd01ccc3286634789baef4b"
// },
// "sec:domain": "example.com",
// "signature:Value": "IEd/NpCGX7cRe4wc1xh3o4X/y37pY4tOdt8WbYnaGw/Gbr2Oz7GqtkbYE8dxfxjFFYCrISPJGbBNFyaiVBAb6bs="
// }

// });
},
Some(Commands::Graph {
subcommand,
perspective,
creator,
target,
tags,
depth,
min_value,
max_value,
}) => {
// TODO: Graph command methods
},
None => {} // Default method or throw error?
}


for _ in 0..args.count {
println!("Hello {}!", args.name)
}
}


#[test]
fn verify_cli() {
use clap::CommandFactory;
Cli::command().debug_assert()
}