refactor!: remove `--suffix` & revamp help

BREAKING-CHANGE: I couldn't decide on the
semantics of what this command should have
so, instead, I've opted to remove it.
pull/25/head
sgoudham 1 year ago committed by Hamothy
parent 6ee58693ee
commit 3335011f6d

@ -3,7 +3,7 @@ name = "git-view"
version = "1.0.0" version = "1.0.0"
edition = "2021" edition = "2021"
authors = ["Goudham Suresh <sgoudham@gmail.com>"] authors = ["Goudham Suresh <sgoudham@gmail.com>"]
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" license = "MIT"
readme = "README.md" readme = "README.md"
repository = "https://github.com/sgoudham/git-view" repository = "https://github.com/sgoudham/git-view"

@ -4,11 +4,11 @@
[![crates.io](https://img.shields.io/crates/v/git-view)](https://crates.io/crates/git-view) [![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) [![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 ## 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!!! > Me too!!!
@ -20,9 +20,8 @@ Are you _**also**_ frustrated from moving your hands away from the keyboard to v
## Features ## Features
- [x] View Branches, Commits & Issues - [x] View Branches, Commits & Issues
- [x] Custom Suffix
- [x] Custom Remote - [x] Custom Remote
- [x] View Current Directory - [x] Custom Directory
## Installation ## Installation
@ -80,10 +79,6 @@ $ git view --path CONTRIBUTING.md
$ git view --path CONTRIBUTING.md --branch testing $ git view --path CONTRIBUTING.md --branch testing
# https://github.com/TRACKED_REMOTE_USER/REPO/tree/PROVIDED_BRANCH/CONTRIBUTING.md # 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 $ git view --print
# prints https://github.com/TRACKED_REMOTE_USER/REPO/tree/CURRENT_BRANCH # prints https://github.com/TRACKED_REMOTE_USER/REPO/tree/CURRENT_BRANCH
``` ```
@ -93,24 +88,23 @@ $ git view --print
```shell ```shell
git-view 1.0.0 git-view 1.0.0
Goudham Suresh <sgoudham@gmail.com> Goudham Suresh <sgoudham@gmail.com>
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: USAGE:
git-view [OPTIONS] git-view [OPTIONS]
OPTIONS: OPTIONS:
-r, --remote <name> The remote to view git repository on -r, --remote <name> The remote to view on GitHub
[default: default remote] [default: default remote]
-b, --branch <name> The branch to view git repository on -b, --branch <name> The branch to view on GitHub
[default: current branch] [default: current branch]
-i, --issue <number> The issue number to view on the git repository -i, --issue <number> The GitHub issue number
[default: open issue from current branch] [default: number from current branch]
-c, --commit <hash> The commit to view git repository on -c, --commit <hash> The commit to view on GitHub
[default: current commit] [default: current commit]
-p, --path <path> The directory/file to view on the git repository -p, --path <path> The directory/file to view on GitHub
[default: current working directory] [default: current working directory]
-s, --suffix <suffix> A suffix to append onto the base git repository URL --print Don't open GitHub and print URL
--print Don't open browser and print the URL
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
``` ```

@ -1,6 +1,6 @@
use std::panic::set_hook; 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::Git;
use git_view::GitView; use git_view::GitView;
@ -19,7 +19,7 @@ fn main() {
.about(crate_description!()) .about(crate_description!())
.arg( .arg(
Arg::new("remote") 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') .short('r')
.long("remote") .long("remote")
.value_name("name") .value_name("name")
@ -28,7 +28,7 @@ fn main() {
) )
.arg( .arg(
Arg::new("branch") 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') .short('b')
.long("branch") .long("branch")
.value_name("name") .value_name("name")
@ -37,7 +37,7 @@ fn main() {
) )
.arg( .arg(
Arg::new("issue") 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') .short('i')
.long("issue") .long("issue")
.value_name("number") .value_name("number")
@ -48,7 +48,7 @@ fn main() {
) )
.arg( .arg(
Arg::new("commit") 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') .short('c')
.long("commit") .long("commit")
.value_name("hash") .value_name("hash")
@ -58,7 +58,9 @@ fn main() {
) )
.arg( .arg(
Arg::new("path") 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') .short('p')
.long("path") .long("path")
.default_missing_value("current-working-directory") .default_missing_value("current-working-directory")
@ -67,20 +69,11 @@ fn main() {
.value_hint(clap::ValueHint::AnyPath) .value_hint(clap::ValueHint::AnyPath)
.display_order(5), .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(
Arg::new("print") Arg::new("print")
.long_help("Don't open browser and print the URL") .long_help("Don't open GitHub and print URL")
.long("print") .long("print")
.display_order(7), .display_order(6),
); );
let matches = matches.get_matches(); let matches = matches.get_matches();
@ -88,7 +81,6 @@ fn main() {
matches.value_of("branch"), matches.value_of("branch"),
matches.value_of("remote"), matches.value_of("remote"),
matches.value_of("commit"), matches.value_of("commit"),
matches.value_of("suffix"),
matches.value_of("issue"), matches.value_of("issue"),
matches.value_of("path"), matches.value_of("path"),
matches.is_present("print"), matches.is_present("print"),

@ -13,7 +13,6 @@ pub struct GitView<'a> {
remote: Option<&'a str>, remote: Option<&'a str>,
branch: Option<&'a str>, branch: Option<&'a str>,
commit: Option<&'a str>, commit: Option<&'a str>,
suffix: Option<&'a str>,
issue: Option<&'a str>, issue: Option<&'a str>,
path: Option<&'a str>, path: Option<&'a str>,
is_print: bool, is_print: bool,
@ -24,7 +23,6 @@ impl<'a> GitView<'a> {
branch: Option<&'a str>, branch: Option<&'a str>,
remote: Option<&'a str>, remote: Option<&'a str>,
commit: Option<&'a str>, commit: Option<&'a str>,
suffix: Option<&'a str>,
issue: Option<&'a str>, issue: Option<&'a str>,
path: Option<&'a str>, path: Option<&'a str>,
is_print: bool, is_print: bool,
@ -33,7 +31,6 @@ impl<'a> GitView<'a> {
remote, remote,
branch, branch,
commit, commit,
suffix,
issue, issue,
path, path,
is_print, is_print,
@ -234,9 +231,7 @@ impl<'a> GitView<'a> {
return Ok(open_url); return Ok(open_url);
} }
println!("{escaped_remote_ref}");
open_url.push_str(format!("/tree/{}", escaped_remote_ref).as_str()); open_url.push_str(format!("/tree/{}", escaped_remote_ref).as_str());
self.handle_suffix_flag(&mut open_url);
Ok(open_url) Ok(open_url)
} }
@ -257,9 +252,6 @@ impl<'a> GitView<'a> {
open_url.push_str(format!("/issues/{}", issue).as_str()); 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(()) Ok(())
} }
@ -312,17 +304,8 @@ impl<'a> GitView<'a> {
open_url.push_str(format!("/{}", path).as_str()); open_url.push_str(format!("/{}", path).as_str());
} }
// suffix can still be appended after path
self.handle_suffix_flag(open_url);
Ok(()) 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> { fn capture_digits(remote_ref: &str) -> Option<&str> {
@ -386,7 +369,6 @@ mod lib_tests {
remote: Option<&'a str>, remote: Option<&'a str>,
branch: Option<&'a str>, branch: Option<&'a str>,
commit: Option<&'a str>, commit: Option<&'a str>,
suffix: Option<&'a str>,
issue: Option<&'a str>, issue: Option<&'a str>,
path: Option<&'a str>, path: Option<&'a str>,
is_print: bool, is_print: bool,
@ -408,11 +390,6 @@ mod lib_tests {
self 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 { pub(crate) fn with_issue(mut self, issue: &'a str) -> Self {
self.issue = Some(issue); self.issue = Some(issue);
self self
@ -428,7 +405,6 @@ mod lib_tests {
self.branch, self.branch,
self.remote, self.remote,
self.commit, self.commit,
self.suffix,
self.issue, self.issue,
self.path, self.path,
self.is_print, self.is_print,
@ -1004,19 +980,6 @@ mod lib_tests {
assert!(actual_final_url.is_ok()); assert!(actual_final_url.is_ok());
assert_eq!(actual_final_url.unwrap(), expected_final_url); 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 { mod capture_digits {

Loading…
Cancel
Save