diff --git a/Cargo.toml b/Cargo.toml index 8fb0b8e..5761cc5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "git-view" version = "1.0.0" edition = "2021" authors = ["Goudham Suresh "] -description = "A git sub-command to view your git repository in the web browser" +description = "A git sub-command to view your git repository on GitHub" license = "MIT" readme = "README.md" repository = "https://github.com/sgoudham/git-view" diff --git a/README.md b/README.md index 385e2e2..2ed0a0b 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ [![crates.io](https://img.shields.io/crates/v/git-view)](https://crates.io/crates/git-view) [![downloads](https://img.shields.io/crates/d/git-view)](https://crates.io/crates/git-view) -> A git sub-command to view your git repository in the web browser! +> A git sub-command to view your git repository on GitHub! ## About -Are you _**also**_ frustrated from moving your hands away from the keyboard to view your git repository in the browser? +Are you _**also**_ frustrated from moving your hands away from the keyboard to view your git repository on GitHub? > Me too!!! @@ -20,9 +20,8 @@ Are you _**also**_ frustrated from moving your hands away from the keyboard to v ## Features - [x] View Branches, Commits & Issues -- [x] Custom Suffix - [x] Custom Remote -- [x] View Current Directory +- [x] Custom Directory ## Installation @@ -80,10 +79,6 @@ $ git view --path CONTRIBUTING.md $ git view --path CONTRIBUTING.md --branch testing # https://github.com/TRACKED_REMOTE_USER/REPO/tree/PROVIDED_BRANCH/CONTRIBUTING.md -$ git view --suffix releases -# Given branch 'TICKET-123' or some other variation -# https://github.com/TRACKED_REMOTE_USER/REPO/releases - $ git view --print # prints https://github.com/TRACKED_REMOTE_USER/REPO/tree/CURRENT_BRANCH ``` @@ -93,26 +88,25 @@ $ git view --print ```shell git-view 1.0.0 Goudham Suresh -A git sub-command to view your git repository in the web browser +A git sub-command to view your git repository on GitHub USAGE: git-view [OPTIONS] OPTIONS: - -r, --remote The remote to view git repository on - [default: default remote] - -b, --branch The branch to view git repository on - [default: current branch] - -i, --issue The issue number to view on the git repository - [default: open issue from current branch] - -c, --commit The commit to view git repository on - [default: current commit] - -p, --path The directory/file to view on the git repository - [default: current working directory] - -s, --suffix A suffix to append onto the base git repository URL - --print Don't open browser and print the URL - -h, --help Print help information - -V, --version Print version information + -r, --remote The remote to view on GitHub + [default: default remote] + -b, --branch The branch to view on GitHub + [default: current branch] + -i, --issue The GitHub issue number + [default: number from current branch] + -c, --commit The commit to view on GitHub + [default: current commit] + -p, --path The directory/file to view on GitHub + [default: current working directory] + --print Don't open GitHub and print URL + -h, --help Print help information + -V, --version Print version information ``` ## Contributing diff --git a/src/bin/git-view.rs b/src/bin/git-view.rs index 29b2bc2..c04fc97 100644 --- a/src/bin/git-view.rs +++ b/src/bin/git-view.rs @@ -1,6 +1,6 @@ use std::panic::set_hook; -use clap::{command, crate_description, crate_authors, crate_version, Arg, Command, ErrorKind}; +use clap::{command, crate_authors, crate_description, crate_version, Arg, Command, ErrorKind}; use git_view::Git; use git_view::GitView; @@ -19,7 +19,7 @@ fn main() { .about(crate_description!()) .arg( Arg::new("remote") - .long_help("The remote to view git repository on\n[default: default remote]") + .long_help("The remote to view on GitHub\n[default: default remote]") .short('r') .long("remote") .value_name("name") @@ -28,7 +28,7 @@ fn main() { ) .arg( Arg::new("branch") - .long_help("The branch to view git repository on\n[default: current branch]") + .long_help("The branch to view on GitHub\n[default: current branch]") .short('b') .long("branch") .value_name("name") @@ -37,7 +37,7 @@ fn main() { ) .arg( Arg::new("issue") - .long_help("The issue number to view on the git repository\n[default: open issue from current branch]") + .long_help("The GitHub issue number\n[default: number from current branch]") .short('i') .long("issue") .value_name("number") @@ -48,7 +48,7 @@ fn main() { ) .arg( Arg::new("commit") - .long_help("The commit to view git repository on\n[default: current commit]") + .long_help("The commit to view on GitHub\n[default: current commit]") .short('c') .long("commit") .value_name("hash") @@ -58,7 +58,9 @@ fn main() { ) .arg( Arg::new("path") - .long_help("The directory/file to view on the git repository\n[default: current working directory]") + .long_help( + "The directory/file to view on GitHub\n[default: current working directory]", + ) .short('p') .long("path") .default_missing_value("current-working-directory") @@ -67,20 +69,11 @@ fn main() { .value_hint(clap::ValueHint::AnyPath) .display_order(5), ) - .arg( - Arg::new("suffix") - .long_help("A suffix to append onto the base git repository URL") - .short('s') - .long("suffix") - .value_name("suffix") - .takes_value(true) - .display_order(6), - ) .arg( Arg::new("print") - .long_help("Don't open browser and print the URL") + .long_help("Don't open GitHub and print URL") .long("print") - .display_order(7), + .display_order(6), ); let matches = matches.get_matches(); @@ -88,7 +81,6 @@ fn main() { matches.value_of("branch"), matches.value_of("remote"), matches.value_of("commit"), - matches.value_of("suffix"), matches.value_of("issue"), matches.value_of("path"), matches.is_present("print"), diff --git a/src/lib.rs b/src/lib.rs index 0e60404..90246e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,6 @@ pub struct GitView<'a> { remote: Option<&'a str>, branch: Option<&'a str>, commit: Option<&'a str>, - suffix: Option<&'a str>, issue: Option<&'a str>, path: Option<&'a str>, is_print: bool, @@ -24,7 +23,6 @@ impl<'a> GitView<'a> { branch: Option<&'a str>, remote: Option<&'a str>, commit: Option<&'a str>, - suffix: Option<&'a str>, issue: Option<&'a str>, path: Option<&'a str>, is_print: bool, @@ -33,7 +31,6 @@ impl<'a> GitView<'a> { remote, branch, commit, - suffix, issue, path, is_print, @@ -234,9 +231,7 @@ impl<'a> GitView<'a> { return Ok(open_url); } - println!("{escaped_remote_ref}"); open_url.push_str(format!("/tree/{}", escaped_remote_ref).as_str()); - self.handle_suffix_flag(&mut open_url); Ok(open_url) } @@ -257,9 +252,6 @@ impl<'a> GitView<'a> { open_url.push_str(format!("/issues/{}", issue).as_str()); } - // no reason why suffix can't be appended after issue - self.handle_suffix_flag(open_url); - Ok(()) } @@ -312,17 +304,8 @@ impl<'a> GitView<'a> { open_url.push_str(format!("/{}", path).as_str()); } - // suffix can still be appended after path - self.handle_suffix_flag(open_url); - Ok(()) } - - fn handle_suffix_flag(&self, open_url: &mut String) { - if let Some(suffix) = self.suffix { - open_url.push_str(format!("/{}", suffix).as_str()); - } - } } fn capture_digits(remote_ref: &str) -> Option<&str> { @@ -386,7 +369,6 @@ mod lib_tests { remote: Option<&'a str>, branch: Option<&'a str>, commit: Option<&'a str>, - suffix: Option<&'a str>, issue: Option<&'a str>, path: Option<&'a str>, is_print: bool, @@ -408,11 +390,6 @@ mod lib_tests { self } - pub(crate) fn with_suffix(mut self, suffix: &'a str) -> Self { - self.suffix = Some(suffix); - self - } - pub(crate) fn with_issue(mut self, issue: &'a str) -> Self { self.issue = Some(issue); self @@ -428,7 +405,6 @@ mod lib_tests { self.branch, self.remote, self.commit, - self.suffix, self.issue, self.path, self.is_print, @@ -1004,19 +980,6 @@ mod lib_tests { assert!(actual_final_url.is_ok()); assert_eq!(actual_final_url.unwrap(), expected_final_url); } - - #[test_case("main", "https://github.com/sgoudham/git-view/tree/main/releases" ; "with_branch_main")] - #[test_case("dev", "https://github.com/sgoudham/git-view/tree/dev/releases" ; "with_branch_dev")] - fn with_suffix(remote_ref: &str, expected_final_url: &str) { - let handler = GitView::builder().with_suffix("releases").build(); - let url = Url::new("https", "github.com", "sgoudham/git-view"); - let mock = MockGitTrait::default(); - - let actual_final_url = handler.generate_final_url(remote_ref, &url, &mock); - - assert!(actual_final_url.is_ok()); - assert_eq!(actual_final_url.unwrap(), expected_final_url); - } } mod capture_digits {