Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd): support link resolution with partial filesystems #19

Merged
merged 1 commit into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gomarkdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ header: |+
repository:
url: https://github.com/princjef/gomarkdoc
defaultBranch: master
directory: .
path: /
10 changes: 5 additions & 5 deletions cmd/gomarkdoc/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func buildCommand() *cobra.Command {
opts.footerFile = viper.GetString("footerFile")
opts.repository.Remote = viper.GetString("repository.url")
opts.repository.DefaultBranch = viper.GetString("repository.defaultBranch")
opts.repository.RootDir = viper.GetString("repository.directory")
opts.repository.PathFromRoot = viper.GetString("repository.path")

if opts.check && opts.output == "" {
log.Fatal("check mode cannot be run without an output set")
Expand Down Expand Up @@ -198,10 +198,10 @@ func buildCommand() *cobra.Command {
"Manual override for the git repository URL used in place of automatic detection.",
)
command.Flags().StringVar(
&opts.repository.RootDir,
"repository.directory",
&opts.repository.PathFromRoot,
"repository.path",
"",
"Manual override for the root directory of the git repository use in place of automatic detection.",
"Manual override for the path from the root of the git repository used in place of automatic detection.",
)
command.Flags().BoolVar(
&opts.version,
Expand All @@ -223,7 +223,7 @@ func buildCommand() *cobra.Command {
_ = viper.BindPFlag("footerFile", command.Flags().Lookup("footer-file"))
_ = viper.BindPFlag("repository.url", command.Flags().Lookup("repository.url"))
_ = viper.BindPFlag("repository.defaultBranch", command.Flags().Lookup("repository.default-branch"))
_ = viper.BindPFlag("repository.directory", command.Flags().Lookup("repository.directory"))
_ = viper.BindPFlag("repository.path", command.Flags().Lookup("repository.path"))

return command
}
Expand Down
26 changes: 13 additions & 13 deletions format/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ AzureDevOpsMarkdown provides a Format which is compatible with Azure DevOps's sy
type AzureDevOpsMarkdown struct{}
```

### func \(\*AzureDevOpsMarkdown\) [Accordion](<https://github.com/princjef/gomarkdoc/blob/master/format/devops.go#L102>)
### func \(\*AzureDevOpsMarkdown\) [Accordion](<https://github.com/princjef/gomarkdoc/blob/master/format/devops.go#L111>)

```go
func (f *AzureDevOpsMarkdown) Accordion(title, body string) (string, error)
```

Accordion generates a collapsible content\. The accordion's visible title while collapsed is the provided title and the expanded content is the body\.

### func \(\*AzureDevOpsMarkdown\) [AccordionHeader](<https://github.com/princjef/gomarkdoc/blob/master/format/devops.go#L113>)
### func \(\*AzureDevOpsMarkdown\) [AccordionHeader](<https://github.com/princjef/gomarkdoc/blob/master/format/devops.go#L122>)

```go
func (f *AzureDevOpsMarkdown) AccordionHeader(title string) (string, error)
Expand All @@ -87,7 +87,7 @@ The AccordionHeader is expected to be used in conjunction with AccordionTerminat
accordion := format.AccordionHeader("Accordion Title") + "Accordion Body" + format.AccordionTerminator()
```

### func \(\*AzureDevOpsMarkdown\) [AccordionTerminator](<https://github.com/princjef/gomarkdoc/blob/master/format/devops.go#L120>)
### func \(\*AzureDevOpsMarkdown\) [AccordionTerminator](<https://github.com/princjef/gomarkdoc/blob/master/format/devops.go#L129>)

```go
func (f *AzureDevOpsMarkdown) AccordionTerminator() (string, error)
Expand Down Expand Up @@ -119,7 +119,7 @@ func (f *AzureDevOpsMarkdown) CodeHref(loc lang.Location) (string, error)

CodeHref generates an href to the provided code entry\.

### func \(\*AzureDevOpsMarkdown\) [Escape](<https://github.com/princjef/gomarkdoc/blob/master/format/devops.go#L130>)
### func \(\*AzureDevOpsMarkdown\) [Escape](<https://github.com/princjef/gomarkdoc/blob/master/format/devops.go#L139>)

```go
func (f *AzureDevOpsMarkdown) Escape(text string) string
Expand All @@ -135,15 +135,15 @@ func (f *AzureDevOpsMarkdown) Header(level int, text string) (string, error)

Header converts the provided text into a header of the provided level\. The level is expected to be at least 1\.

### func \(\*AzureDevOpsMarkdown\) [Link](<https://github.com/princjef/gomarkdoc/blob/master/format/devops.go#L89>)
### func \(\*AzureDevOpsMarkdown\) [Link](<https://github.com/princjef/gomarkdoc/blob/master/format/devops.go#L98>)

```go
func (f *AzureDevOpsMarkdown) Link(text, href string) (string, error)
```

Link generates a link with the given text and href values\.

### func \(\*AzureDevOpsMarkdown\) [ListEntry](<https://github.com/princjef/gomarkdoc/blob/master/format/devops.go#L96>)
### func \(\*AzureDevOpsMarkdown\) [ListEntry](<https://github.com/princjef/gomarkdoc/blob/master/format/devops.go#L105>)

```go
func (f *AzureDevOpsMarkdown) ListEntry(depth int, text string) (string, error)
Expand All @@ -159,7 +159,7 @@ func (f *AzureDevOpsMarkdown) LocalHref(headerText string) (string, error)

LocalHref generates an href for navigating to a header with the given headerText located within the same document as the href itself\. Link generation follows the guidelines here: https://docs\.microsoft\.com/en\-us/azure/devops/project/wiki/markdown\-guidance?view=azure\-devops\#anchor\-links

### func \(\*AzureDevOpsMarkdown\) [Paragraph](<https://github.com/princjef/gomarkdoc/blob/master/format/devops.go#L125>)
### func \(\*AzureDevOpsMarkdown\) [Paragraph](<https://github.com/princjef/gomarkdoc/blob/master/format/devops.go#L134>)

```go
func (f *AzureDevOpsMarkdown) Paragraph(text string) (string, error)
Expand Down Expand Up @@ -248,15 +248,15 @@ GitHubFlavoredMarkdown provides a Format which is compatible with GitHub Flavore
type GitHubFlavoredMarkdown struct{}
```

### func \(\*GitHubFlavoredMarkdown\) [Accordion](<https://github.com/princjef/gomarkdoc/blob/master/format/github.go#L105>)
### func \(\*GitHubFlavoredMarkdown\) [Accordion](<https://github.com/princjef/gomarkdoc/blob/master/format/github.go#L114>)

```go
func (f *GitHubFlavoredMarkdown) Accordion(title, body string) (string, error)
```

Accordion generates a collapsible content\. The accordion's visible title while collapsed is the provided title and the expanded content is the body\.

### func \(\*GitHubFlavoredMarkdown\) [AccordionHeader](<https://github.com/princjef/gomarkdoc/blob/master/format/github.go#L116>)
### func \(\*GitHubFlavoredMarkdown\) [AccordionHeader](<https://github.com/princjef/gomarkdoc/blob/master/format/github.go#L125>)

```go
func (f *GitHubFlavoredMarkdown) AccordionHeader(title string) (string, error)
Expand All @@ -270,7 +270,7 @@ The AccordionHeader is expected to be used in conjunction with AccordionTerminat
accordion := format.AccordionHeader("Accordion Title") + "Accordion Body" + format.AccordionTerminator()
```

### func \(\*GitHubFlavoredMarkdown\) [AccordionTerminator](<https://github.com/princjef/gomarkdoc/blob/master/format/github.go#L123>)
### func \(\*GitHubFlavoredMarkdown\) [AccordionTerminator](<https://github.com/princjef/gomarkdoc/blob/master/format/github.go#L132>)

```go
func (f *GitHubFlavoredMarkdown) AccordionTerminator() (string, error)
Expand Down Expand Up @@ -302,7 +302,7 @@ func (f *GitHubFlavoredMarkdown) CodeHref(loc lang.Location) (string, error)

CodeHref generates an href to the provided code entry\.

### func \(\*GitHubFlavoredMarkdown\) [Escape](<https://github.com/princjef/gomarkdoc/blob/master/format/github.go#L133>)
### func \(\*GitHubFlavoredMarkdown\) [Escape](<https://github.com/princjef/gomarkdoc/blob/master/format/github.go#L142>)

```go
func (f *GitHubFlavoredMarkdown) Escape(text string) string
Expand All @@ -326,7 +326,7 @@ func (f *GitHubFlavoredMarkdown) Link(text, href string) (string, error)

Link generates a link with the given text and href values\.

### func \(\*GitHubFlavoredMarkdown\) [ListEntry](<https://github.com/princjef/gomarkdoc/blob/master/format/github.go#L99>)
### func \(\*GitHubFlavoredMarkdown\) [ListEntry](<https://github.com/princjef/gomarkdoc/blob/master/format/github.go#L108>)

```go
func (f *GitHubFlavoredMarkdown) ListEntry(depth int, text string) (string, error)
Expand All @@ -342,7 +342,7 @@ func (f *GitHubFlavoredMarkdown) LocalHref(headerText string) (string, error)

LocalHref generates an href for navigating to a header with the given headerText located within the same document as the href itself\.

### func \(\*GitHubFlavoredMarkdown\) [Paragraph](<https://github.com/princjef/gomarkdoc/blob/master/format/github.go#L128>)
### func \(\*GitHubFlavoredMarkdown\) [Paragraph](<https://github.com/princjef/gomarkdoc/blob/master/format/github.go#L137>)

```go
func (f *GitHubFlavoredMarkdown) Paragraph(text string) (string, error)
Expand Down
17 changes: 13 additions & 4 deletions format/devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,21 @@ func (f *AzureDevOpsMarkdown) CodeHref(loc lang.Location) (string, error) {
return "", nil
}

fullPath, err := filepath.Abs(loc.Filepath)
if err != nil {
return "", err
var (
relative string
err error
)
if filepath.IsAbs(loc.Filepath) {
relative, err = filepath.Rel(loc.WorkDir, loc.Filepath)
if err != nil {
return "", err
}
} else {
relative = loc.Filepath
}

p, err := filepath.Rel(loc.Repo.RootDir, fullPath)
full := filepath.Join(loc.Repo.PathFromRoot, relative)
p, err := filepath.Rel(string(filepath.Separator), full)
if err != nil {
return "", err
}
Expand Down
15 changes: 7 additions & 8 deletions format/devops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,20 @@ func TestLocalHref(t *testing.T) {
func TestCodeHref(t *testing.T) {
is := is.New(t)

repoDir, err := filepath.Abs(".")
wd, err := filepath.Abs(".")
is.NoErr(err)

locPath, err := filepath.Abs(".")
is.NoErr(err)
locPath = filepath.Join(locPath, "subdir", "file.go")
locPath := filepath.Join(wd, "subdir", "file.go")

var f format.AzureDevOpsMarkdown
res, err := f.CodeHref(lang.Location{
Start: lang.Position{Line: 12, Col: 1},
End: lang.Position{Line: 14, Col: 43},
Filepath: locPath,
WorkDir: wd,
Repo: &lang.Repo{
Remote: "https://dev.azure.com/org/project/_git/repo",
DefaultBranch: "master",
RootDir: repoDir,
PathFromRoot: "/",
},
})
is.NoErr(err)
Expand All @@ -144,15 +142,16 @@ func TestCodeHref(t *testing.T) {
func TestCodeHref_noRepo(t *testing.T) {
is := is.New(t)

locPath, err := filepath.Abs(".")
wd, err := filepath.Abs(".")
is.NoErr(err)
locPath = filepath.Join(locPath, "subdir", "file.go")
locPath := filepath.Join(wd, "subdir", "file.go")

var f format.AzureDevOpsMarkdown
res, err := f.CodeHref(lang.Location{
Start: lang.Position{Line: 12, Col: 1},
End: lang.Position{Line: 14, Col: 43},
Filepath: locPath,
WorkDir: wd,
Repo: nil,
})
is.NoErr(err)
Expand Down
17 changes: 13 additions & 4 deletions format/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,21 @@ func (f *GitHubFlavoredMarkdown) CodeHref(loc lang.Location) (string, error) {
return "", nil
}

fullPath, err := filepath.Abs(loc.Filepath)
if err != nil {
return "", err
var (
relative string
err error
)
if filepath.IsAbs(loc.Filepath) {
relative, err = filepath.Rel(loc.WorkDir, loc.Filepath)
if err != nil {
return "", err
}
} else {
relative = loc.Filepath
}

p, err := filepath.Rel(loc.Repo.RootDir, fullPath)
full := filepath.Join(loc.Repo.PathFromRoot, relative)
p, err := filepath.Rel(string(filepath.Separator), full)
if err != nil {
return "", err
}
Expand Down
Loading