Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
peczenyj committed Oct 4, 2024
1 parent f49a412 commit e981d27
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions cmd/gomarkdoc/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,27 +502,25 @@ func getLocalDir(path, fullModule string) string {
}

func getFullPackageName(opts commandOptions) (string, error) {
var fullPackageName string
if !opts.forceLocalDir {
return "", nil
}

if opts.forceLocalDir {
if opts.fullPackageName != "" {
fullPackageName = opts.fullPackageName
} else {
data, err := os.ReadFile("go.mod")
if err != nil {
return "", fmt.Errorf("unable to read module file: %w", err)
}
if opts.fullPackageName != "" {
return opts.fullPackageName, nil
}

f, err := modfile.Parse("go.mod", data, nil)
if err != nil {
return "", fmt.Errorf("unable to parse module file: %w", err)
}
data, err := os.ReadFile("go.mod")
if err != nil {
return "", fmt.Errorf("unable to read module file: %w", err)
}

fullPackageName = f.Module.Mod.String()
}
f, err := modfile.Parse("go.mod", data, nil)
if err != nil {
return "", fmt.Errorf("unable to parse module file: %w", err)
}

return fullPackageName, nil
return f.Module.Mod.String(), nil
}

func getSpecs(opts commandOptions, paths ...string) ([]*PackageSpec, error) {
Expand Down

0 comments on commit e981d27

Please sign in to comment.