Skip to content

Commit

Permalink
Merge pull request #10 from tuan78/fix/cmd-installation
Browse files Browse the repository at this point in the history
fix: issue of cmd installation
  • Loading branch information
tuan78 authored Aug 16, 2022
2 parents ee1108b + 4d454b6 commit d62db57
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
4 changes: 1 addition & 3 deletions benchmarks/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ module github.com/tuan78/jsonconv/benchmarks

go 1.18

replace github.com/tuan78/jsonconv => ../

require github.com/tuan78/jsonconv v1.0.1
require github.com/tuan78/jsonconv v1.0.2
2 changes: 2 additions & 0 deletions benchmarks/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/tuan78/jsonconv v1.0.2 h1:tdmVOQDrVrZZ+ZivgNuW8mYr1f7lsOajd+1BVm4QHVc=
github.com/tuan78/jsonconv v1.0.2/go.mod h1:FFDL8xmSERH5fFmySGaR4ku/2RY0inkMZmhpBo8r9zc=
2 changes: 1 addition & 1 deletion cmd/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: all
all: build
all: test

.PHONY: build
build:
Expand Down
4 changes: 1 addition & 3 deletions cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ module github.com/tuan78/jsonconv/cmd

go 1.18

replace github.com/tuan78/jsonconv => ../

require (
github.com/spf13/cobra v1.5.0
github.com/spf13/pflag v1.0.5
github.com/tuan78/jsonconv v1.0.1
github.com/tuan78/jsonconv v1.0.2
)

require github.com/inconshreveable/mousetrap v1.0.0 // indirect
2 changes: 2 additions & 0 deletions cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
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/tuan78/jsonconv v1.0.2 h1:tdmVOQDrVrZZ+ZivgNuW8mYr1f7lsOajd+1BVm4QHVc=
github.com/tuan78/jsonconv v1.0.2/go.mod h1:FFDL8xmSERH5fFmySGaR4ku/2RY0inkMZmhpBo8r9zc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
5 changes: 3 additions & 2 deletions cmd/jsonconv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"github.com/tuan78/jsonconv/cmd"
)

var exitFn = os.Exit

func main() {
// Execute command.
if err := cmd.NewRootCmd().Execute(); err != nil {
fmt.Fprintf(os.Stderr, "Command execution failed, err: %v\n", err)
os.Exit(1)
exitFn(1)
}
}
21 changes: 21 additions & 0 deletions cmd/jsonconv/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"os"
"testing"
)

func TestMainFn_GoodArgs(t *testing.T) {
os.Args = []string{"jsonconv", "--help"}
main()
}

func TestMainFn_BadArgs(t *testing.T) {
exitCode := 0
exitFn = func(code int) { exitCode = 1 }
os.Args = []string{"jsonconv", "bad-args"}
main()
if exitCode == 0 {
t.Errorf("it should exit with code 1 for bad args")
}
}

0 comments on commit d62db57

Please sign in to comment.