Skip to content

Commit

Permalink
Merge pull request #64 from nao1215/dependabot/github_actions/gorelea…
Browse files Browse the repository at this point in the history
…ser/goreleaser-action-6

Bump goreleaser/goreleaser-action from 5 to 6
  • Loading branch information
nao1215 authored Jun 7, 2024
2 parents 4e1ef5d + dac4893 commit af5ede3
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
go-version-file: "go.mod"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
Expand Down
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ issues:
linters:
disable-all: true
enable:
- errcheck
- gosimple
- govet
- ineffassign
Expand Down
26 changes: 12 additions & 14 deletions config/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,26 @@ func NewArg(args []string) (*Arg, error) {

// newOutput retur *Output
func newOutput(filePath string, of outputFlag) *Output {
mode := model.PrintModeTable
output := &Output{
FilePath: filePath,
}
switch {
case of.excel:
mode = model.PrintModeCSV
output.Mode = model.PrintModeExcel
case of.csv:
mode = model.PrintModeCSV
output.Mode = model.PrintModeCSV
case of.tsv:
mode = model.PrintModeTSV
output.Mode = model.PrintModeTSV
case of.ltsv:
mode = model.PrintModeLTSV
output.Mode = model.PrintModeLTSV
case of.json:
mode = model.PrintModeJSON
output.Mode = model.PrintModeJSON
case of.markdown:
mode = model.PrintModeMarkdownTable
output.Mode = model.PrintModeMarkdownTable
default:
mode = model.PrintModeTable
}

return &Output{
FilePath: filePath,
Mode: mode,
output.Mode = model.PrintModeTable
}
return output
}

// NeedsOutputToFile whether the data needs to be output to the file
Expand Down Expand Up @@ -155,7 +153,7 @@ func usage(flag pflag.FlagSet) string {
}

func version() {
fmt.Fprintf(Stdout, "sqly %s\n", GetVersion())
fmt.Fprintf(Stdout, "sqly %s\n", GetVersion()) //nolint:errcheck // ignore error
}

// GetVersion return sqly command version.
Expand Down
14 changes: 7 additions & 7 deletions domain/model/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,17 @@ func (t *Table) printMarkdownTable(out io.Writer) {

// printCSV print all record with header; output format is csv
func (t *Table) printCSV(out io.Writer) {
fmt.Fprintln(out, strings.Join(t.Header, ","))
fmt.Fprintln(out, strings.Join(t.Header, ",")) //nolint:errcheck // ignore error
for _, v := range t.Records {
fmt.Fprintln(out, strings.Join(v, ","))
fmt.Fprintln(out, strings.Join(v, ",")) //nolint:errcheck // ignore error
}
}

// printTSV print all record with header; output format is tsv
func (t *Table) printTSV(out io.Writer) {
fmt.Fprintln(out, strings.Join(t.Header, "\t"))
fmt.Fprintln(out, strings.Join(t.Header, "\t")) //nolint:errcheck // ignore error
for _, v := range t.Records {
fmt.Fprintln(out, strings.Join(v, "\t"))
fmt.Fprintln(out, strings.Join(v, "\t")) //nolint:errcheck // ignore error
}
}

Expand All @@ -185,7 +185,7 @@ func (t *Table) printLTSV(out io.Writer) {
for i, data := range v {
r = append(r, t.Header[i]+":"+data)
}
fmt.Fprintln(out, strings.Join(r, "\t"))
fmt.Fprintln(out, strings.Join(r, "\t")) //nolint:errcheck // ignore error
}
}

Expand All @@ -202,10 +202,10 @@ func (t *Table) printJSON(out io.Writer) {
}
b, err := json.MarshalIndent(data, "", " ")
if err != nil {
fmt.Fprintf(os.Stderr, "json marshal error: "+err.Error())
fmt.Fprintf(os.Stderr, "json marshal error: "+err.Error()) //nolint:errcheck // ignore error
return
}
fmt.Fprintln(out, string(b))
fmt.Fprintln(out, string(b)) //nolint:errcheck // ignore error
}

// printExcel print all record in excel format.
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/persistence/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func NewJSONRepository() repository.JSONRepository {
}

func (r *jsonRepository) List(jsonFilePath string) (*model.JSON, error) {
bytes, err := os.ReadFile(jsonFilePath)
bytes, err := os.ReadFile(filepath.Clean(jsonFilePath))
if err != nil {
return nil, err
}
Expand Down
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ func main() {
func run(args []string) int {
shell, cleanup, err := di.NewShell(args)
if err != nil {
fmt.Fprintf(os.Stderr, "%s: %v\n", "failed to initialize sqly shell", err)
fmt.Fprintf(
os.Stderr,
"%s: %v\n",
"failed to initialize sqly shell",
err)
return 1
}
defer cleanup()
Expand Down
2 changes: 1 addition & 1 deletion shell/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (c CommandList) hasCmdPrefix(s string) bool {
// sortCommandNameKey returns an array of sorted keys (command names)
// to sort the command list map
func (c CommandList) sortCommandNameKey() []string {
var keys []string
keys := make([]string, 0, len(c))
for key := range c {
keys = append(keys, key)
}
Expand Down
12 changes: 6 additions & 6 deletions shell/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
// dumpCommand dump specified table to csv file
func (c CommandList) dumpCommand(s *Shell, argv []string) error {
if len(argv) != 2 {
fmt.Fprintln(config.Stdout, "[Usage]")
fmt.Fprintln(config.Stdout, " .dump TABLE_NAME FILE_PATH")
fmt.Fprintln(config.Stdout, "[Note]")
fmt.Fprintln(config.Stdout, " Output will be in the format specified in .mode.")
fmt.Fprintln(config.Stdout, " table mode is not available in .dump. If mode is table, .dump output CSV file.")
fmt.Fprintln(config.Stdout, "[Usage]") //nolint:errcheck // ignore error
fmt.Fprintln(config.Stdout, " .dump TABLE_NAME FILE_PATH") //nolint:errcheck // ignore error
fmt.Fprintln(config.Stdout, "[Note]") //nolint:errcheck // ignore error
fmt.Fprintln(config.Stdout, " Output will be in the format specified in .mode.") //nolint:errcheck // ignore error
fmt.Fprintln(config.Stdout, " table mode is not available in .dump. If mode is table, .dump output CSV file.") //nolint:errcheck // ignore error
return nil
}

Expand All @@ -27,7 +27,7 @@ func (c CommandList) dumpCommand(s *Shell, argv []string) error {
if err := dumpToFile(s, argv[1], table); err != nil {
return err
}
fmt.Fprintf(config.Stdout, "dump `%s` table to %s (mode=%s)\n",
fmt.Fprintf(config.Stdout, "dump `%s` table to %s (mode=%s)\n", //nolint:errcheck // ignore error
color.CyanString(argv[0]), color.HiCyanString(argv[1]), dumpMode(s.argument.Output.Mode))

return nil
Expand Down
2 changes: 1 addition & 1 deletion shell/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func (c CommandList) helpCommand(s *Shell, argv []string) error {
for _, cmdName := range c.sortCommandNameKey() {
fmt.Fprintf(config.Stdout, "%20s: %s\n",
color.CyanString(cmdName), c[cmdName].description)
color.CyanString(cmdName), c[cmdName].description) //nolint:errcheck // ignore error
}
return nil
}
2 changes: 1 addition & 1 deletion shell/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func (c CommandList) modeCommand(s *Shell, argv []string) error {
if len(argv) == 0 {
fmt.Fprintln(config.Stdout, "[Usage]")
fmt.Fprintf(config.Stdout, " .mode OUTPUT_MODE ※ current mode=%s\n", s.argument.Output.Mode.String())
fmt.Fprintf(config.Stdout, " .mode OUTPUT_MODE ※ current mode=%s\n", s.argument.Output.Mode.String()) //nolint:errcheck // ignore error
fmt.Fprintln(config.Stdout, "[Output mode list]")
fmt.Fprintln(config.Stdout, " table")
fmt.Fprintln(config.Stdout, " markdown")
Expand Down
12 changes: 6 additions & 6 deletions shell/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestShell_Run(t *testing.T) {
}

// TODO:
got, err := os.ReadFile(file)
got, err := os.ReadFile(filepath.Clean(file))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -542,7 +542,7 @@ func TestShell_exec(t *testing.T) {
t.Fatal(err)
}

got, err := os.ReadFile(file)
got, err := os.ReadFile(filepath.Clean(file))
if err != nil {
t.Fatal(err)
}
Expand All @@ -569,7 +569,7 @@ func TestShell_exec(t *testing.T) {
t.Fatal(err)
}

got, err := os.ReadFile(file)
got, err := os.ReadFile(filepath.Clean(file))
if err != nil {
t.Fatal(err)
}
Expand All @@ -596,7 +596,7 @@ func TestShell_exec(t *testing.T) {
t.Fatal(err)
}

got, err := os.ReadFile(file)
got, err := os.ReadFile(filepath.Clean(file))
if err != nil {
t.Fatal(err)
}
Expand All @@ -623,7 +623,7 @@ func TestShell_exec(t *testing.T) {
t.Fatal(err)
}

got, err := os.ReadFile(file)
got, err := os.ReadFile(filepath.Clean(file))
if err != nil {
t.Fatal(err)
}
Expand All @@ -650,7 +650,7 @@ func TestShell_exec(t *testing.T) {
t.Fatal(err)
}

got, err := os.ReadFile(file)
got, err := os.ReadFile(filepath.Clean(file))
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 3 additions & 2 deletions usecase/ltsv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package usecase

import (
"os"
"path/filepath"

"github.com/nao1215/sqly/domain/model"
"github.com/nao1215/sqly/domain/repository"
Expand All @@ -19,7 +20,7 @@ func NewLTSVInteractor(r repository.LTSVRepository) *LTSVInteractor {

// List get LTSV data.
func (li *LTSVInteractor) List(ltsvFilePath string) (*model.LTSV, error) {
f, err := os.Open(ltsvFilePath)
f, err := os.Open(filepath.Clean(ltsvFilePath))
if err != nil {
return nil, err
}
Expand All @@ -34,7 +35,7 @@ func (li *LTSVInteractor) List(ltsvFilePath string) (*model.LTSV, error) {

// Dump write contents of DB table to LTSV file
func (li *LTSVInteractor) Dump(ltsvFilePath string, table *model.Table) error {
f, err := os.OpenFile(ltsvFilePath, os.O_RDWR|os.O_CREATE, 0664)
f, err := os.OpenFile(filepath.Clean(ltsvFilePath), os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion usecase/sqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (si *SQLite3Interactor) ExecSQL(ctx context.Context, statement string) (*mo
case si.sql.isInsert(argv[0]) || si.sql.isUpdate(argv[0]) || si.sql.isDelete(argv[0]):
affectedRows, err := si.Repository.Exec(ctx, statement)
if err != nil {
return nil, 0, fmt.Errorf("execute statement error: %v: %s", err, color.CyanString(statement))
return nil, 0, fmt.Errorf("execute statement error: %w: %s", err, color.CyanString(statement))
}
return nil, affectedRows, nil
default:
Expand Down
2 changes: 1 addition & 1 deletion usecase/tsv.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (ti *TSVInteractor) List(tsvFilePath string) (*model.TSV, error) {

// Dump write contents of DB table to TSV file
func (ti *TSVInteractor) Dump(tsvFilePath string, table *model.Table) error {
f, err := os.OpenFile(tsvFilePath, os.O_RDWR|os.O_CREATE, 0664)
f, err := os.OpenFile(filepath.Clean(tsvFilePath), os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return err
}
Expand Down

0 comments on commit af5ede3

Please sign in to comment.