Skip to content

Commit

Permalink
fPrintLinkTs
Browse files Browse the repository at this point in the history
  • Loading branch information
bbkane committed Dec 4, 2021
1 parent fdf75f7 commit a30dbf4
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/bbkane/warg/help"
"github.com/bbkane/warg/section"
"github.com/bbkane/warg/value"

"github.com/karrick/godirwalk"
)

Expand Down Expand Up @@ -85,6 +86,12 @@ func (t linkT) String() string {
)
}

func fPrintLinkTs(f *bufio.Writer, lTs []linkT) {
for _, e := range lTs {
fmt.Fprintf(f, "%s\n", e)
}
}

// NOTE: making these type aliases instead of type definitions
// so I can use the String() method of linkT, even though
// it means I can assign instances of each types to instances of
Expand Down Expand Up @@ -444,33 +451,25 @@ func unlink(pf flag.PassedFlags) error {

if len(fi.dirLinksToCreate) > 0 {
fPrintHeader(f, "Uncreated dir links:")
for _, e := range fi.dirLinksToCreate {
fmt.Fprintf(f, "%s\n", e)
}
fPrintLinkTs(f, fi.dirLinksToCreate)
fmt.Fprintln(f)
}

if len(fi.fileLinksToCreate) > 0 {
fPrintHeader(f, "Uncreated file links:")
for _, e := range fi.fileLinksToCreate {
fmt.Fprintf(f, "%s\n", e)
}
fPrintLinkTs(f, fi.fileLinksToCreate)
fmt.Fprintln(f)
}

if len(fi.existingDirLinks) > 0 {
fPrintHeader(f, "Dir links to delete:")
for _, e := range fi.existingDirLinks {
fmt.Fprintf(f, "%s\n", e)
}
fPrintLinkTs(f, fi.existingDirLinks)
fmt.Fprintln(f)
}

if len(fi.existingFileLinks) > 0 {
fPrintHeader(f, "File links to delete:")
for _, e := range fi.existingFileLinks {
fmt.Fprintf(f, "%s\n", e)
}
fPrintLinkTs(f, fi.existingFileLinks)
fmt.Fprintln(f)
}

Expand Down Expand Up @@ -572,32 +571,24 @@ func link(pf flag.PassedFlags) error {

if len(fi.dirLinksToCreate) > 0 {
fPrintHeader(f, "Dir links to create:")
for _, e := range fi.dirLinksToCreate {
fmt.Fprintf(f, "%s\n", e)
}
fPrintLinkTs(f, fi.dirLinksToCreate)
fmt.Fprintln(f)
}

if len(fi.fileLinksToCreate) > 0 {
fPrintHeader(f, "File links to create:")
for _, e := range fi.fileLinksToCreate {
fmt.Fprintf(f, "%s\n", e)
}
fPrintLinkTs(f, fi.fileLinksToCreate)
fmt.Fprintln(f)
}

if len(fi.existingDirLinks) > 0 {
fPrintHeader(f, "Pre-existing correct dir links:")
for _, e := range fi.existingDirLinks {
fmt.Fprintf(f, "%s\n", e)
}
fPrintLinkTs(f, fi.existingDirLinks)
fmt.Fprintln(f)
}
if len(fi.existingFileLinks) > 0 {
fPrintHeader(f, "Pre-existing correct file links:")
for _, e := range fi.existingFileLinks {
fmt.Fprintf(f, "%s\n", e)
}
fPrintLinkTs(f, fi.existingFileLinks)
fmt.Fprintln(f)
}

Expand Down

0 comments on commit a30dbf4

Please sign in to comment.