add `browse` subcommand

main
_ 2021-08-29 20:00:12 +00:00
parent 626583645b
commit 1daac51dd7
2 changed files with 26 additions and 1 deletions

View File

@ -0,0 +1,3 @@
The first build of Lookup to implement the `browse` subcommand.
A debug build for Linux x64.

View File

@ -19,8 +19,16 @@ async fn main () -> anyhow::Result <()> {
let matches = App::new ("ReactorScram/Lookup") let matches = App::new ("ReactorScram/Lookup")
.author ("ReactorScram (Trisha)") .author ("ReactorScram (Trisha)")
.about ("Looks up information about a file, based on its hash") .about ("Looks up information about a file, based on its hash")
.subcommand (SubCommand::with_name ("browse")
.about ("Opens a read-only Lookup file, from Trisha's repo, in a web browser, using `xdg-open`")
.arg (
Arg::with_name ("INPUT")
.help ("Sets the input file to use")
.required (true)
)
)
.subcommand (SubCommand::with_name ("edit") .subcommand (SubCommand::with_name ("edit")
.about ("Opens the Lookup file with $EDITOR") .about ("Opens a local Lookup file with $EDITOR")
.arg ( .arg (
Arg::with_name ("INPUT") Arg::with_name ("INPUT")
.help ("Sets the input file to use") .help ("Sets the input file to use")
@ -33,6 +41,20 @@ async fn main () -> anyhow::Result <()> {
) )
.get_matches (); .get_matches ();
if let Some (matches) = matches.subcommand_matches ("browse") {
let public_repo = "https://six-five-six-four.com/git/reactor/lookup/src/branch/main/lookup_repo/";
let input_path = Path::new (matches.value_of ("INPUT").unwrap ());
let b3_hash = hash (input_path)?;
let local_path = PathBuf::from ("lookup_repo").join (repo_path (&b3_hash));
let url = format! ("{}/{:?}", public_repo, local_path);
process::Command::new ("xdg-open")
.arg (url)
.status ().context ("while spawning browser")?;
return Ok (());
}
if let Some (matches) = matches.subcommand_matches ("edit") { if let Some (matches) = matches.subcommand_matches ("edit") {
let input_path = Path::new (matches.value_of ("INPUT").unwrap ()); let input_path = Path::new (matches.value_of ("INPUT").unwrap ());