mirror of
https://github.com/charmbracelet/glow.git
synced 2026-08-09 09:49:09 +02:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
e31dc2c890
4 changed files with 50 additions and 42 deletions
25
github.go
25
github.go
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
|
@ -29,19 +30,21 @@ func findGitHubREADME(s string) (*source, error) {
|
|||
}
|
||||
u.Host = "raw.githubusercontent.com"
|
||||
|
||||
for _, r := range readmeNames {
|
||||
v := u
|
||||
v.Path += "/master/" + r
|
||||
for _, b := range readmeBranches {
|
||||
for _, r := range readmeNames {
|
||||
v := *u
|
||||
v.Path += fmt.Sprintf("/%s/%s", b, r)
|
||||
|
||||
// nolint:bodyclose
|
||||
// it is closed on the caller
|
||||
resp, err := http.Get(v.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// nolint:bodyclose
|
||||
// it is closed on the caller
|
||||
resp, err := http.Get(v.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
return &source{resp.Body, v.String()}, nil
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
return &source{resp.Body, v.String()}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
25
gitlab.go
25
gitlab.go
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
|
@ -28,19 +29,21 @@ func findGitLabREADME(s string) (*source, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
for _, r := range readmeNames {
|
||||
v := u
|
||||
v.Path += "/raw/master/" + r
|
||||
for _, b := range readmeBranches {
|
||||
for _, r := range readmeNames {
|
||||
v := *u
|
||||
v.Path += fmt.Sprintf("/raw/%s/%s", b, r)
|
||||
|
||||
// nolint:bodyclose
|
||||
// it is closed on the caller
|
||||
resp, err := http.Get(v.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// nolint:bodyclose
|
||||
// it is closed on the caller
|
||||
resp, err := http.Get(v.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
return &source{resp.Body, v.String()}, nil
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
return &source{resp.Body, v.String()}, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
19
glow_test.go
19
glow_test.go
|
|
@ -14,15 +14,16 @@ func TestGlowSources(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, v := range tt {
|
||||
buf := &bytes.Buffer{}
|
||||
err := executeArg(rootCmd, v, buf)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Error during execution (args: %s): %v", v, err)
|
||||
}
|
||||
if buf.Len() == 0 {
|
||||
t.Errorf("Output buffer should not be empty (args: %s)", v)
|
||||
}
|
||||
t.Run(v, func(t *testing.T) {
|
||||
buf := &bytes.Buffer{}
|
||||
err := executeArg(rootCmd, v, buf)
|
||||
if err != nil {
|
||||
t.Errorf("Error during execution (args: %s): %v", v, err)
|
||||
}
|
||||
if buf.Len() == 0 {
|
||||
t.Errorf("Output buffer should not be empty (args: %s)", v)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
15
main.go
15
main.go
|
|
@ -28,13 +28,14 @@ var (
|
|||
// CommitSHA as provided by goreleaser.
|
||||
CommitSHA = ""
|
||||
|
||||
readmeNames = []string{"README.md", "README"}
|
||||
configFile string
|
||||
pager bool
|
||||
style string
|
||||
width uint
|
||||
showAllFiles bool
|
||||
mouse bool
|
||||
readmeNames = []string{"README.md", "README", "Readme.md", "Readme", "readme.md", "readme"}
|
||||
readmeBranches = []string{"main", "master"}
|
||||
configFile string
|
||||
pager bool
|
||||
style string
|
||||
width uint
|
||||
showAllFiles bool
|
||||
mouse bool
|
||||
|
||||
rootCmd = &cobra.Command{
|
||||
Use: "glow [SOURCE|DIR]",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue