Skip to content

Commit

Permalink
added --test flag to publish to test server instead of prod
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Nov 21, 2023
1 parent 098c16e commit b4bbd64
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
17 changes: 13 additions & 4 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use clap::{arg, Command};
use nanopub::{profile::get_default_profile_path, Nanopub, NpProfile};
use nanopub::{get_np_server, profile::get_default_profile_path, Nanopub, NpProfile};
use std::{error::Error, fs, path::Path};
// use tokio;

// https://github.com/clap-rs/clap/blob/master/examples/git.rs
// cargo run -- sign tests/resources/nanopub_test_blank.trig -k tests/resources/id_rsa
Expand Down Expand Up @@ -40,6 +39,9 @@ async fn main() -> Result<(), Box<dyn Error>> {
arg!(-p --profile <PROFILE> "The path to a profile.yml file. Default: ~/.nanopub/profile.yml")
.default_value("")
)
.arg(
arg!(-t --test "To publish to the test server instead of a production server.")
)
.arg_required_else_help(true),
).subcommand(
Command::new("check")
Expand Down Expand Up @@ -88,6 +90,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
let np_file = sub.get_one::<String>("NANOPUB_FILE").expect("required");
let key_file = sub.get_one::<String>("key").unwrap();
let profile_file = sub.get_one::<String>("profile").unwrap();
let test_server = sub.get_flag("test");

// Read RDF from file, and get profile from YAML file or key
let np_rdf = fs::read_to_string(np_file)?;
Expand All @@ -99,8 +102,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
} else {
NpProfile::from_file(&get_default_profile_path())?
};
println!("📬️ Publishing {}", np_file);
let _ = Nanopub::publish(&np_rdf, &profile, None).await;
if test_server {
println!("🧪 Publishing {np_file} to test server");
let _ = Nanopub::publish(&np_rdf, &profile, None).await;
} else {
let server = get_np_server(true);
println!("📬️ Publishing {np_file} to {server}");
let _ = Nanopub::publish(&np_rdf, &profile, Some(server)).await;
}
}
Some(("check", sub)) => {
let np_file = sub.get_one::<String>("NANOPUB_FILE").expect("required");
Expand Down
2 changes: 1 addition & 1 deletion js/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ crate-type = ["cdylib"]
nanopub = { version = "0.0.9", path = "../lib" }
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
serde-wasm-bindgen = "0.3"
serde-wasm-bindgen = "0.6"
js-sys = "0.3"
console_error_panic_hook = "0.1"
serde = { version = "1.0" }
Expand Down
9 changes: 6 additions & 3 deletions lib/src/nanopub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,19 @@ impl Nanopub {
// )?;
// }

// If ORCID provided, add to pubinfo graph
// If ORCID provided and not already provided, add to pubinfo graph
if !profile.orcid_id.is_empty()
&& dataset
.quads_matching(
[
&np_info.uri,
&Iri::new_unchecked(np_info.ns.get("")?.to_string()),
],
[get_ns("dct").get("creator")?],
// TODO: also skip if pav:createdBy is present?
[
get_ns("dct").get("creator")?,
get_ns("prov").get("wasAttributedTo")?,
get_ns("pav").get("createdBy")?,
],
Any,
[Some(&np_info.pubinfo)],
)
Expand Down
2 changes: 2 additions & 0 deletions lib/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub fn get_ns(ns: &str) -> Namespace<String> {
"npx" => Namespace::new("http://purl.org/nanopub/x/".to_string()).unwrap(),
"np" => Namespace::new("http://www.nanopub.org/nschema#".to_string()).unwrap(),
"dct" => Namespace::new("http://purl.org/dc/terms/".to_string()).unwrap(),
"prov" => Namespace::new("http://www.w3.org/ns/prov#".to_string()).unwrap(),
"pav" => Namespace::new("http://purl.org/pav/".to_string()).unwrap(),
_ => panic!("Unknown namespace"), // or return an error
}
}
Expand Down

0 comments on commit b4bbd64

Please sign in to comment.