Skip to content

Commit

Permalink
extract checkargs
Browse files Browse the repository at this point in the history
  • Loading branch information
pdelewski committed Dec 29, 2022
1 parent 4d11482 commit 24451d9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
8 changes: 8 additions & 0 deletions instrgen/driver/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ func TestCommands(t *testing.T) {
require.NoError(t, err)
}

func TestArgs(t *testing.T) {
err := checkArgs(nil)
require.Error(t, err)
args := []string{"driver", "--inject", "", "./..."}
err = checkArgs(args)
require.NoError(t, err)
}

func TestUnknown(t *testing.T) {
err := executeCommand("unknown", "a", "b")
require.Error(t, err)
Expand Down
16 changes: 12 additions & 4 deletions instrgen/driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,21 @@ func executeCommand(command string, projectPath string, packagePattern string) e
return errors.New("unknown command")
}

func checkArgs(args []string) error {
if len(args) != 4 {
_ = usage()
return errors.New("wrong arguments")
}
return nil
}

func main() {
fmt.Println("autotel compiler")
if len(os.Args) != 4 {
_ = usage()
os.Exit(-1)
err := checkArgs(os.Args)
if err != nil {
return
}
err := executeCommand(os.Args[1], os.Args[2], os.Args[3])
err = executeCommand(os.Args[1], os.Args[2], os.Args[3])
if err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 2 additions & 4 deletions instrgen/driver/testdata/interface/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ go 1.18

replace go.opentelemetry.io/contrib/instrgen => ../../..

require (
go.opentelemetry.io/contrib/instrgen v0.0.0-20221228173227-92e0588b124b
go.opentelemetry.io/otel v1.11.2
)
require go.opentelemetry.io/contrib/instrgen v0.0.0-20221228173227-92e0588b124b

require (
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
go.opentelemetry.io/otel v1.11.2 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.11.2 // indirect
go.opentelemetry.io/otel/sdk v1.11.2 // indirect
go.opentelemetry.io/otel/trace v1.11.2 // indirect
Expand Down

0 comments on commit 24451d9

Please sign in to comment.