Skip to content

Commit

Permalink
Merge pull request #83 from nao1215/delete-intenal-file-package
Browse files Browse the repository at this point in the history
Delete internal file package. use gorky/file pacakage instead
  • Loading branch information
nao1215 authored Mar 21, 2023
2 parents fb1e11f + 040a24b commit 1817b8c
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 72 deletions.
4 changes: 2 additions & 2 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"os"

"github.com/nao1215/gorky/file"
"github.com/nao1215/gup/internal/config"
"github.com/nao1215/gup/internal/file"
"github.com/nao1215/gup/internal/goutil"
"github.com/nao1215/gup/internal/print"
"github.com/spf13/cobra"
Expand All @@ -32,7 +32,7 @@ installation according to the contents of gup.conf.`,
return cmd
}

func export(cmd *cobra.Command, args []string) int {
func export(cmd *cobra.Command, _ []string) int {
if err := goutil.CanUseGoCmd(); err != nil {
print.Err(fmt.Errorf("%s: %w", "you didn't install golang", err))
return 1
Expand Down
2 changes: 1 addition & 1 deletion cmd/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

"github.com/adrg/xdg"
"github.com/google/go-cmp/cmp"
"github.com/nao1215/gorky/file"
"github.com/nao1215/gup/internal/config"
"github.com/nao1215/gup/internal/file"
"github.com/nao1215/gup/internal/goutil"
"github.com/nao1215/gup/internal/print"
"github.com/spf13/cobra"
Expand Down
2 changes: 1 addition & 1 deletion cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"runtime"

"github.com/nao1215/gorky/file"
"github.com/nao1215/gup/internal/config"
"github.com/nao1215/gup/internal/file"
"github.com/nao1215/gup/internal/print"
"github.com/spf13/cobra"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"runtime"
"strings"

"github.com/nao1215/gup/internal/file"
"github.com/nao1215/gorky/file"
"github.com/nao1215/gup/internal/goutil"
"github.com/nao1215/gup/internal/print"
"github.com/spf13/cobra"
Expand Down
2 changes: 1 addition & 1 deletion cmd/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/nao1215/gup/internal/file"
"github.com/nao1215/gorky/file"
"github.com/nao1215/gup/internal/print"
"github.com/spf13/cobra"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/nao1215/gorky/file"
"github.com/nao1215/gup/internal/cmdinfo"
"github.com/nao1215/gup/internal/config"
"github.com/nao1215/gup/internal/file"
"github.com/nao1215/gup/internal/goutil"
"github.com/nao1215/gup/internal/print"
)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/gen2brain/beeep v0.0.0-20220909211152-5a9ec94374f6
github.com/google/go-cmp v0.5.9
github.com/mattn/go-colorable v0.1.13
github.com/nao1215/gorky v0.2.0
github.com/nao1215/gorky v0.2.1
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.6.1
golang.org/x/sync v0.1.0
Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/nao1215/gorky v0.2.0 h1:dGhccwANGFbA2wryX0fkRe3O7h+Pov63hNQxSmKypgA=
github.com/nao1215/gorky v0.2.0/go.mod h1:RHHEeEhkdrCuNEduNB2i4RCgkJWiAD6gK+AZq0Kyx44=
github.com/nao1215/gorky v0.2.1 h1:kxXYhCNBbtGru9CCSYx+QC0JZfZJ1csY3uLbb5n2WKA=
github.com/nao1215/gorky v0.2.1/go.mod h1:fJNLiXzn3YkteARC8xghfHjkt+C5xtHOaRgmVnJEMOs=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand All @@ -37,7 +37,7 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
Expand Down
2 changes: 1 addition & 1 deletion internal/assets/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"os"
"path/filepath"

"github.com/nao1215/gorky/file"
"github.com/nao1215/gup/internal/config"
"github.com/nao1215/gup/internal/file"
"github.com/nao1215/gup/internal/print"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/completion/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"runtime"
"strings"

"github.com/nao1215/gorky/file"
"github.com/nao1215/gup/internal/cmdinfo"
"github.com/nao1215/gup/internal/file"
"github.com/nao1215/gup/internal/print"
"github.com/spf13/cobra"
)
Expand Down
34 changes: 32 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
package config

import (
"bufio"
"errors"
"fmt"
"io"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/adrg/xdg"
"github.com/nao1215/gup/internal/cmdinfo"
"github.com/nao1215/gup/internal/file"
"github.com/nao1215/gup/internal/goutil"
)

Expand All @@ -31,7 +32,7 @@ func DirPath() string {

// ReadConfFile return contents of configuration-file (package information)
func ReadConfFile(path string) ([]goutil.Package, error) {
contents, err := file.ReadFileToList(path)
contents, err := readFileToList(path)
if err != nil {
return nil, fmt.Errorf("can't read %s: %w", path, err)
}
Expand Down Expand Up @@ -86,3 +87,32 @@ func deleteComment(line string) string {
r := regexp.MustCompile(`#./*`)
return r.ReplaceAllString(line, "")
}

// readFileToList convert file content to string list.
func readFileToList(path string) ([]string, error) {
var strList []string
f, err := os.Open(filepath.Clean(path))
if err != nil {
return nil, err
}
defer func() {
if closeErr := f.Close(); closeErr != nil {
// TODO: If use go 1.20, rewrite like this.
// err = errors.Join(err, closeErr)
err = closeErr // overwrite error
}
}()

r := bufio.NewReader(f)
for {
line, err := r.ReadString('\n')
if err != nil && err != io.EOF {
return nil, err
}
if err == io.EOF && len(line) == 0 {
break
}
strList = append(strList, line)
}
return strList, nil
}
57 changes: 0 additions & 57 deletions internal/file/file.go

This file was deleted.

0 comments on commit 1817b8c

Please sign in to comment.