Why Nostr? What is Njump?
2024-07-03 00:49:10

npub13p…dd04x on Nostr: commit e15ca61d77a167cf10d25109a5d365deba3bb504 Author: randymcmillan ...

commit e15ca61d77a167cf10d25109a5d365deba3bb504
Author: randymcmillan <[email protected]>
Date: Thu May 16 14:51:00 2024 -0400

src/bin/gnostr.rs:begin command parse/pass through

cargo add gnostr-bins

diff --git a/Cargo.lock b/Cargo.lock
index ff7afd953..135a7011c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -7479,6 +7479,7 @@ dependencies = [
"futures-util",
"git2",
"gix 0.61.0",
+ "gnostr-bins",
"gossip-relay-picker",
"heed",
"hex",
diff --git a/jj/Cargo.toml b/jj/Cargo.toml
index 82a27c86f..948972bc9 100644
--- a/jj/Cargo.toml
+++ b/jj/Cargo.toml
@@ -13,22 +13,42 @@ repository = { workspace = true }
documentation = { workspace = true }
keywords = { workspace = true }

+
+## command pass through
[[bin]]
name = "jj"
path = "src/main.rs"

+## git gnostr-jj
[[bin]]
-name = "gnostr-jj"
+name = "git-gnostr-jj"
path = "src/main.rs"

+## gnostr
+## command handler
[[bin]]
name = "gnostr"
path = "../src/bin/gnostr.rs"

+## git gnostr pass through
+[[bin]]
+name = "git-gnostr"
+path = "../src/bin/gnostr.rs"
+
[[bin]]
-name = "gnostr-jj-gui"
+name = "gnostr-gui"
path = "../gui/src/main.rs"

+## git gnostr-gui
+[[bin]]
+name = "git-gnostr-gui"
+path = "../gui/src/main.rs"
+
+## ## git-legit
+## [[bin]]
+## name = "git-legit"
+## path = "../bins/src/bin/gnostr-legit.rs"
+

[[bin]]
name = "fake-editor"
@@ -140,6 +160,7 @@ tungstenite = { version = "0.19", default-features = false }
url = "2.4"
vecmap-rs = "0.1"
zeroize = "1.6"
+gnostr-bins = { version = "0.0.39", path = "../bins" }



diff --git a/src/bin/gnostr.rs b/src/bin/gnostr.rs
index 970d9c56a..0f3dcf0ab 100644
--- a/src/bin/gnostr.rs
+++ b/src/bin/gnostr.rs
@@ -16,6 +16,136 @@ use jj_cli::cli_util::CliRunner;
use std::process::*;
use std::process::ExitCode;

+use std::env;
+
+use futures::executor::block_on;
+use gnostr_bins::{get_stripped_urls, get_watch_list, get_watch_list_json, print_watch_list};
+
+pub fn handle_command(mut args: env::Args) -> Result<bool, Box<dyn std::error::Error>> {
+ let _ = args.next(); // program name
+ let command = args.next().unwrap(); // must be there or we would not have been called
+
+ #[cfg(debug_assertions)]
+ println!("\n*** gnostr-gui is running in command mode ***");
+ #[cfg(debug_assertions)]
+ println!("*** COMMAND = {} ***\n", command);
+
+ match &*command {
+
+ //sec nostr private ley
+ "sec" => gnostr_sec(),
+ "--sec" => gnostr_sec(),
+
+ //gnostr-gui
+ "gui" => gnostr_gui(),
+ "--gui" => gnostr_gui(),
+
+ //gnostr-tui
+ "tui" => gnostr_tui(),
+ "--tui" => gnostr_tui(),
+
+ //json
+ "-j" => json(),
+ "--json" => json(),
+ "json" => json(),
+ //print
+ "-p" => print(),
+ "--print" => print(),
+ "print" => print(),
+ //get
+ "-g" => get(),
+ "--get" => get(),
+ "get" => get(),
+ //stripped
+ "-s" => stripped(),
+ "--stripped" => stripped(),
+ "stripped" => stripped(),
+
+ //version
+ "-V" => version(),
+ //support help2man
+ "-v" => version(),
+ "--version" => version(),
+ "version" => version(),
+ //help
+ "-h" => help(),
+ "--help" => help(),
+ "help" => help(),
+ //other
+ other => println!("Unknown command {}", other),
+ }
+ Ok(true)
+}
+fn gnostr_sec() {
+ print!("sec called");
+}
+fn gnostr_gui() {
+ print!("gui called");
+}
+fn gnostr_tui() {
+ print!("tui called");
+}
+fn default() {
+ json();
+ use std::process;
+ process::exit(0);
+}
+fn json() {
+ let future = get_watch_list_json();
+ let _ = block_on(future);
+}
+fn print() {
+ let future = print_watch_list();
+ let _ = block_on(future);
+}
+fn get() {
+ let future = get_watch_list();
+ let _ = block_on(future);
+}
+//TODO: return length in watch_list?
+fn stripped() {
+ let future = get_stripped_urls();
+ let length = block_on(future);
+ //print!("{}",format!("{:?}",length.unwrap()));
+ print!("{}", format!("{:?}", length.expect("REASON").len()));
+}
+fn help() {
+ use std::process;
+
+ let package_name = env!("CARGO_PKG_NAME");
+ let crate_name = env!("CARGO_CRATE_NAME");
+ let version = env!("CARGO_PKG_VERSION");
+ print!("\n1:{} v{}\n\n", package_name.replace("jj-cli", "gnostr"), version);
+ print!("\n{} v{}\n\n", crate_name.replace("git_", ""), version);
+ print!("3:{} get\n", crate_name.replace("git_", ""));
+ print!("4: <csv_relay_list>\n");
+ print!("5:{} json\n", crate_name.replace("git_", ""));
+ print!("6: <json_relay_list>\n");
+ print!("7:{} stripped\n", crate_name.replace("git_", "-"));
+ print!("8: <string_relay_list> <int_length_last>\n");
+ process::exit(0);
+}
+fn version() {
+ use std::process;
+
+ print!("");
+
+ let version = env!("CARGO_PKG_VERSION");
+ let crate_name = env!("CARGO_CRATE_NAME");
+ //let name = env!("CARGO_PKG_NAME");
+ //let author = env!("CARGO_PKG_AUTHORS");
+
+ //println!("Program Name: {}", name);
+ //println!("Program Version: {}", version);
+ println!("{} v{}", crate_name.replace("git_gnostr", "gnostr"), version);
+ //println!("Program Version: {}", version);
+ //println!("Program Author: {}", author);
+
+ process::exit(0);
+}
+
+
+
fn gnostr_git() -> std::process::ExitCode {
//CliRunner::init().version(env!("JJ_VERSION")).run()

@@ -29,7 +159,27 @@ fn gnostr_git() -> std::process::ExitCode {
exit
}
fn main() {
- print!("main");
+ use std::process;
+ print!("main\n");
+ print!("gnostr\n");
+ print!("git-gnostr\n");
+ // If we were handed a command, execute the command and return
+ let args = env::args();
+ if args.len() > 1 {
+ let _ = handle_command(env::args());
+ } else {
+ default();
+ }
+ //if args.len() > 1 {
+ // for arg in args {
+ // if arg == "json" {json();process::exit(0)}
+ // if arg == "get" {get();process::exit(0)}
+ // if arg == "print" {print();process::exit(0)} else {
+ // let _ = handle_command(env::args()); process::exit(0);
+ // }
+ // }
+ //}
+
let _exit_code: std::process::ExitCode= gnostr_git();
_exit_code;
}
Author Public Key
npub13pxuuev4l0zvvv7ce3ysapszmcfhjm4p6445up2n295r2ex9qpyswdd04x