Skip to content

Commit

Permalink
let go commands silent
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Mar 5, 2024
1 parent b69f13d commit cc40ddf
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
VERSION ?= $(shell ./scripts/get-CalVer.sh)
PLUGINS_BRANCH ?= master
VERSION ?= $(shell date +"%Y%m%d")
OUTPUT_DIR := _output

.PHONY: typegen
Expand Down
2 changes: 1 addition & 1 deletion cmd/ndc-go-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func main() {
Str("module", cli.Init.Module).
Str("output", cli.Init.Output).
Msg("generating the NDC boilerplate...")
if err := generateNewProject(cli.Init.Name, cli.Init.Module, cli.Init.Output); err != nil {
if err := generateNewProject(cli.Init.Name, cli.Init.Module, cli.Init.Output, false); err != nil {
log.Fatal().Err(err).Msg("failed to generate new project")
}
log.Info().Msg("generated successfully")
Expand Down
20 changes: 17 additions & 3 deletions cmd/ndc-go-sdk/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func init() {
}
}

func generateNewProject(name string, moduleName string, srcPath string) error {
func generateNewProject(name string, moduleName string, srcPath string, silent bool) error {
if srcPath == "" {
p, err := os.Getwd()
if err != nil {
Expand All @@ -55,13 +55,23 @@ func generateNewProject(name string, moduleName string, srcPath string) error {
}

if err := execGoModTidy(""); err != nil {
if silent {
return nil
}
return err
}

if err := execGoGetUpdate(".", "github.com/hasura/ndc-sdk-go"); err != nil {
if silent {
return nil
}
return err
}
return execGoFormat(".")
err := execGoFormat(".")
if err != nil && silent {
return nil
}
return err
}

func generateNewProjectFiles(name string, moduleName string, srcPath string) error {
Expand Down Expand Up @@ -125,7 +135,11 @@ func execCommand(basePath string, commandName string, args ...string) error {
cmd.Dir = basePath
}
out, err := cmd.Output()
log.Debug().Strs("args", args).Str("result", string(out)).Msg(commandName)
l := log.Debug()
if err != nil {
l = log.Error().Err(err)
}
l.Strs("args", args).Str("result", string(out)).Msg(commandName)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/ndc-go-sdk/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (

func TestGenerateNewProject(t *testing.T) {
tempDir := t.TempDir()
assert.NoError(t, generateNewProject("test", "hasura.dev/connector", tempDir))
assert.NoError(t, generateNewProject("test", "hasura.dev/connector", tempDir, true))
}
8 changes: 0 additions & 8 deletions scripts/get-CalVer.sh

This file was deleted.

0 comments on commit cc40ddf

Please sign in to comment.