Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chevdor committed Jan 11, 2023
1 parent 0094e72 commit 338036c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["chevdor <[email protected]>"]
edition = "2021"
name = "gh"
version = "0.2.0"
version = "0.2.4"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,16 @@ The url is fetched on your remotes.
- `gh` to simply open the first remote

- `gh upstream` to open your `upstream` remote

<!-- -->

Command line utility for the tera templating engine. You need to provide a template using the tera syntax as well as some data (various format are supported)

Usage: gh [REMOTE]

Arguments:
[REMOTE] Name of a remote

Options:
-h, --help Print help information
-V, --version Print version information
4 changes: 4 additions & 0 deletions README.adoc → README_src.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ The url is fetched on your remotes.

- `gh` to simply open the first remote
- `gh upstream` to open your `upstream` remote

----
include::doc/usage.adoc[]
----
10 changes: 10 additions & 0 deletions doc/usage.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Command line utility for the tera templating engine. You need to provide a template using the tera syntax as well as some data (various format are supported)

Usage: gh [REMOTE]

Arguments:
[REMOTE] Name of a remote

Options:
-h, --help Print help information
-V, --version Print version information
5 changes: 2 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ default:
# Generate the readme as .md
md:
#!/usr/bin/env bash
asciidoctor -b docbook -a leveloffset=+1 -o - README.adoc | pandoc --markdown-headings=atx --wrap=preserve -t markdown_strict -f docbook - > README.md
asciidoctor -b docbook -a leveloffset=+1 -o - README_src.adoc | pandoc --markdown-headings=atx --wrap=preserve -t markdown_strict -f docbook - > README.md
# Generate usage samples
_usage:
cargo run -q -- --help > doc/usage.adoc

# Generate documentation
doc:_usage
cargo doc -p tera-cli --all-features --no-deps

cargo doc --all-features --no-deps

# Run rustfmt
_fmt:
Expand Down
18 changes: 9 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ fn run_command(cmd: &str) -> Result<String, String> {
fn get_url(remote: &str) -> Result<String, String> {
debug!("get url for: {}", remote);

let cmd = format!("git config remote.{}.url", remote);
debug!("{}", cmd);
let cmd = format!("git config remote.{remote}.url");
debug!("{cmd}");
let url = run_command(&cmd)?;

// we remove the ".git" to make the regexp simpler
let cleaned = url.trim_end().replace(".git", "");
debug!("cleaned: {}", cleaned);
debug!("cleaned: {cleaned}");

let re = Regex::new(r"(git@|https?://)(.*?)(:|/)(.*)").unwrap();
let caps = re.captures(&cleaned).unwrap();

let site = caps.get(2).map(|m| m.as_str()).expect("Failed parsing site, please report this issue");
let repo = caps.get(4).map(|m| m.as_str()).expect("Failed parsing the repo, please report this issue");

debug!("site: {}", site);
debug!("repo: {}", repo);
debug!("site: {site}");
debug!("repo: {repo}");

Ok(format!("https://{site}/{repo}", site = site, repo = repo))
Ok(format!("https://{site}/{repo}"))
}

fn main() -> Result<(), String> {
Expand All @@ -62,10 +62,10 @@ fn main() -> Result<(), String> {
let remote = String::from(remote);
let remote = remote.trim_end();

let url = get_url(remote).unwrap_or_else(|_| panic!("Failed getting url for '{}'", remote));
let url = get_url(remote).unwrap_or_else(|_| panic!("Failed getting url for '{remote}'"));

debug!("Opening {} => {}", git_remote, url);
print!("{}", url);
debug!("Opening {git_remote} => {url}");
print!("{url}");
match webbrowser::open(&url) {
Ok(_) => Ok(()),
_ => Err("Problem while opening browser".to_string()),
Expand Down

0 comments on commit 338036c

Please sign in to comment.