Skip to content

Commit

Permalink
Merge pull request #58 from fraenky8/bump-go-module-v2
Browse files Browse the repository at this point in the history
Bump go module v2
  • Loading branch information
fraenky8 authored Oct 12, 2024
2 parents a1a4581 + 1b4a026 commit a02adf7
Show file tree
Hide file tree
Showing 19 changed files with 77 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ issues:

linters-settings:
goimports:
local-prefixes: github.com/fraenky8/tables-to-go
local-prefixes: github.com/fraenky8/tables-to-go/v2

gosec:
config:
Expand Down
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
.PHONY: all build

TAG=$(shell git describe --abbrev=0 --tags 2>&1)
TS=$(shell date '+%b %d %Y %T')

all: help

# Self documenting makefile. Double hashes signify help comments.
help: ## Show this help
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'

install: ## Installs tables-to-go. Same behavior like `go install -mod=vendor .`
go install -mod=vendor .
install: ## Installs tables-to-go. Requires `git` to be installed.
@go install -mod=vendor -ldflags \
"-X 'main.buildTimestamp=$(TS)' -X 'main.versionTag=$(TAG)'" \
.

sqlite3: ## Installs tables-to-go with sqlite3 driver and the \
## User Authentication feature enabled. \
## For more information see the documentation of the driver at \
## - https://github.com/mattn/go-sqlite3#compilation \
## - https://github.com/mattn/go-sqlite3#user-authentication
CGO_ENABLED=1 go install -mod=vendor -tags="sqlite3 sqlite_userauth" .
CGO_ENABLED=1 go install -mod=vendor -tags="sqlite3 sqlite_userauth" -ldflags \
"-X 'main.buildTimestamp=$(TS)' -X 'main.versionTag=$(TAG)'" \
.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This project provides a make file but can also simply be installed with the
go-install command:

```
go install github.com/fraenky8/tables-to-go@master
go install github.com/fraenky8/tables-to-go@latest
```

To enable SQLite3 support, clone the repo manually and run the make file:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/fraenky8/tables-to-go
module github.com/fraenky8/tables-to-go/v2

go 1.23

Expand Down
8 changes: 4 additions & 4 deletions internal/cli/tables-to-go-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"golang.org/x/text/cases"
"golang.org/x/text/language"

"github.com/fraenky8/tables-to-go/pkg/database"
"github.com/fraenky8/tables-to-go/pkg/output"
"github.com/fraenky8/tables-to-go/pkg/settings"
"github.com/fraenky8/tables-to-go/pkg/tagger"
"github.com/fraenky8/tables-to-go/v2/pkg/database"
"github.com/fraenky8/tables-to-go/v2/pkg/output"
"github.com/fraenky8/tables-to-go/v2/pkg/settings"
"github.com/fraenky8/tables-to-go/v2/pkg/tagger"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/tables-to-go-cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"

"github.com/fraenky8/tables-to-go/pkg/database"
"github.com/fraenky8/tables-to-go/pkg/settings"
"github.com/fraenky8/tables-to-go/v2/pkg/database"
"github.com/fraenky8/tables-to-go/v2/pkg/settings"
)

type mockDB struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/jmoiron/sqlx"

"github.com/fraenky8/tables-to-go/pkg/settings"
"github.com/fraenky8/tables-to-go/v2/pkg/settings"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

"github.com/fraenky8/tables-to-go/pkg/settings"
"github.com/fraenky8/tables-to-go/v2/pkg/settings"

// MySQL database driver
_ "github.com/go-sql-driver/mysql"
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/fraenky8/tables-to-go/pkg/settings"
"github.com/fraenky8/tables-to-go/v2/pkg/settings"
)

func TestMySQL_DSN(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

"github.com/fraenky8/tables-to-go/pkg/settings"
"github.com/fraenky8/tables-to-go/v2/pkg/settings"

// postgres database driver
_ "github.com/lib/pq"
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/postgresql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/fraenky8/tables-to-go/pkg/settings"
"github.com/fraenky8/tables-to-go/v2/pkg/settings"
)

func TestPostgresql_DSN(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/url"
"strings"

"github.com/fraenky8/tables-to-go/pkg/settings"
"github.com/fraenky8/tables-to-go/v2/pkg/settings"
)

// SQLite implements the Database interface with help of GeneralDatabase.
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/fraenky8/tables-to-go/pkg/settings"
"github.com/fraenky8/tables-to-go/v2/pkg/settings"
)

func TestSQLite_DSN(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/tagger/db.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tagger

import (
"github.com/fraenky8/tables-to-go/pkg/database"
"github.com/fraenky8/tables-to-go/v2/pkg/database"
)

// Db is the standard "db"-tag.
Expand Down
2 changes: 1 addition & 1 deletion pkg/tagger/mastermind.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tagger

import (
"github.com/fraenky8/tables-to-go/pkg/database"
"github.com/fraenky8/tables-to-go/v2/pkg/database"
)

// Mastermind represents the Masterminds/structable "stbl"-tag.
Expand Down
4 changes: 2 additions & 2 deletions pkg/tagger/mastermind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/stretchr/testify/assert"

"github.com/fraenky8/tables-to-go/pkg/database"
"github.com/fraenky8/tables-to-go/pkg/settings"
"github.com/fraenky8/tables-to-go/v2/pkg/database"
"github.com/fraenky8/tables-to-go/v2/pkg/settings"
)

func TestMastermind_GenerateTag(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/tagger/tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"strings"
"sync"

"github.com/fraenky8/tables-to-go/pkg/database"
"github.com/fraenky8/tables-to-go/pkg/settings"
"github.com/fraenky8/tables-to-go/v2/pkg/database"
"github.com/fraenky8/tables-to-go/v2/pkg/settings"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions pkg/tagger/tagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/stretchr/testify/assert"

"github.com/fraenky8/tables-to-go/pkg/database"
"github.com/fraenky8/tables-to-go/pkg/settings"
"github.com/fraenky8/tables-to-go/v2/pkg/database"
"github.com/fraenky8/tables-to-go/v2/pkg/settings"
)

func TestTaggers_GenerateTags(t *testing.T) {
Expand Down
48 changes: 43 additions & 5 deletions tables-to-go.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ import (
"flag"
"fmt"
"os"
"runtime"
"runtime/debug"

"github.com/fraenky8/tables-to-go/internal/cli"
"github.com/fraenky8/tables-to-go/pkg/database"
"github.com/fraenky8/tables-to-go/pkg/output"
"github.com/fraenky8/tables-to-go/pkg/settings"
"github.com/fraenky8/tables-to-go/v2/internal/cli"
"github.com/fraenky8/tables-to-go/v2/pkg/database"
"github.com/fraenky8/tables-to-go/v2/pkg/output"
"github.com/fraenky8/tables-to-go/v2/pkg/settings"
)

var (
revision = "master"
versionTag = ""
buildTimestamp = ""
)

// CmdArgs represents the supported command line args
type CmdArgs struct {
Help bool
Help bool
Version bool
*settings.Settings
}

Expand All @@ -28,6 +37,7 @@ func NewCmdArgs() (args *CmdArgs) {
flag.BoolVar(&args.Help, "help", false, "shows help and usage")
flag.BoolVar(&args.Verbose, "v", args.Verbose, "verbose output")
flag.BoolVar(&args.VVerbose, "vv", args.VVerbose, "more verbose output")
flag.BoolVar(&args.Version, "version", args.Version, "show version and build information")
flag.BoolVar(&args.Force, "f", args.Force, "force; skip tables that encounter errors")

flag.Var(&args.DbType, "t", fmt.Sprintf("type of database to use, currently supported: %v", settings.SprintfSupportedDbTypes()))
Expand Down Expand Up @@ -75,6 +85,11 @@ func main() {
os.Exit(0)
}

if cmdArgs.Version {
printVersion()
os.Exit(0)
}

if err := cmdArgs.Verify(); err != nil {
fmt.Print(err)
os.Exit(1)
Expand All @@ -94,3 +109,26 @@ func main() {
os.Exit(1)
}
}

func printVersion() {
info, ok := debug.ReadBuildInfo()
if ok {
if versionTag == "" {
versionTag = info.Main.Version
}
for _, s := range info.Settings {
if s.Key == "vcs.revision" {
revision = s.Value[:8]
}
}
}

fmt.Printf("tables-to-go/%s-%s %s/%s built with %s", versionTag, revision,
runtime.GOOS, runtime.GOARCH, runtime.Version())

//goland:noinspection GoBoolExpressions
if buildTimestamp != "" {
fmt.Printf(" on %s", buildTimestamp)
}
fmt.Println()
}

0 comments on commit a02adf7

Please sign in to comment.