diff --git a/.golangci.yml b/.golangci.yml index 822901f..2156cfa 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -14,7 +14,6 @@ linters: - containedctx - contextcheck - exhaustive - - goerr113 - wastedassign - nonamedreturns - nlreturn diff --git a/cmd/commands/init.go b/cmd/commands/init.go new file mode 100644 index 0000000..5d3670e --- /dev/null +++ b/cmd/commands/init.go @@ -0,0 +1,39 @@ +package commands + +import ( + "fmt" + "os" + + cobra "github.com/spf13/cobra" + "github.com/zurvan-lab/TimeTrace/config" +) + +func InitCommand(parentCmd *cobra.Command) { + init := &cobra.Command{ + Use: "init", + Short: "Init makes a default config file for you to run time-trace.", + } + parentCmd.AddCommand(init) + + path := init.Flags().StringP("path", "p", "./config.yml", "config file path") + + init.Run = func(cmd *cobra.Command, args []string) { + _, err := os.Stat(*path) + if !os.IsNotExist(err) { + ExitOnError(cmd, fmt.Errorf("a config file already exist on %s path", *path)) + } + + cfg := config.DefaultConfig() + + ymlCfg, err := cfg.ToYAML() + if err != nil { + ExitOnError(cmd, err) + } + + if err = os.WriteFile(*path, ymlCfg, 0o600); err != nil { + ExitOnError(cmd, err) + } + + cmd.Printf("Config created at %s successfully!\n", *path) + } +} diff --git a/cmd/commands/ping.go b/cmd/commands/ping.go index 8c9522b..beb6a83 100644 --- a/cmd/commands/ping.go +++ b/cmd/commands/ping.go @@ -35,8 +35,7 @@ func PingCommand(parentCmd *cobra.Command) { cmd.Println("PONG, everything is ok.") os.Exit(0) } else { - cmd.Printf("something is wrong: %v", response) - os.Exit(1) + ExitOnError(cmd, fmt.Errorf("something went wrong: %v", response)) } } } diff --git a/cmd/main.go b/cmd/main.go index 323f881..85d7481 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -15,6 +15,7 @@ func main() { commands.RunCommand(rootCmd) commands.REPLCommand(rootCmd) commands.PingCommand(rootCmd) + commands.InitCommand(rootCmd) err := rootCmd.Execute() if err != nil { diff --git a/core/TQL/parser/parser_test.go b/core/TQL/parser/parser_test.go index 1dd7145..6aff7ac 100644 --- a/core/TQL/parser/parser_test.go +++ b/core/TQL/parser/parser_test.go @@ -1,8 +1,9 @@ package core import ( - "github.com/stretchr/testify/assert" "testing" + + "github.com/stretchr/testify/assert" ) func TestParseQuery(t *testing.T) { diff --git a/core/database/database_test.go b/core/database/database_test.go index e9b9d0f..068788a 100644 --- a/core/database/database_test.go +++ b/core/database/database_test.go @@ -165,6 +165,7 @@ func TestDataBase(t *testing.T) { time := time.Now() timeStr := strconv.Itoa(int(time.Unix())) + for i := 0; i < 50; i++ { db.PushElement([]string{"testSet", "subSetOne", "testValue", timeStr}) } diff --git a/go.sum b/go.sum index 019a500..2900cf3 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,6 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= -github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -24,8 +22,6 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= 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/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/version.go b/version.go index 38c92c0..e60cede 100644 --- a/version.go +++ b/version.go @@ -4,10 +4,10 @@ import "fmt" // These constants follow the semantic versioning 2.0.0 spec (http://semver.org/) type Version struct { - Meta string `json:"meta" xml:"meta"` - Major uint8 `json:"major" xml:"major"` - Minor uint8 `json:"minor" xml:"minor"` - Patch uint8 `json:"patch" xml:"patch"` + Meta string + Major uint8 + Minor uint8 + Patch uint8 } var version = Version{