VOL-1971 - make v2 the default API version

Change-Id: Ib0b29187d40cd77f78fc162151f8c49f7af9ca55
diff --git a/internal/pkg/commands/command.go b/internal/pkg/commands/command.go
index 43ead45..4693539 100644
--- a/internal/pkg/commands/command.go
+++ b/internal/pkg/commands/command.go
@@ -72,7 +72,7 @@
 	CharReplacer = strings.NewReplacer("\\t", "\t", "\\n", "\n")
 
 	GlobalConfig = GlobalConfigSpec{
-		ApiVersion: "v1",
+		ApiVersion: "v2",
 		Server:     "localhost",
 		Tls: TlsConfigSpec{
 			UseTls: false,
@@ -83,8 +83,9 @@
 	}
 
 	GlobalOptions struct {
-		Config     string `short:"c" long:"config" env:"VOLTCONFIG" value-name:"FILE" default:"" description:"Location of client config file"`
-		Server     string `short:"s" long:"server" default:"" value-name:"SERVER:PORT" description:"IP/Host and port of VOLTHA"`
+		Config string `short:"c" long:"config" env:"VOLTCONFIG" value-name:"FILE" default:"" description:"Location of client config file"`
+		Server string `short:"s" long:"server" default:"" value-name:"SERVER:PORT" description:"IP/Host and port of VOLTHA"`
+		// Do not set the default for the API version here, else it will override the value read in the config
 		ApiVersion string `short:"a" long:"apiversion" description:"API version" value-name:"VERSION" choice:"v1" choice:"v2"`
 		Debug      bool   `short:"d" long:"debug" description:"Enable debug mode"`
 		UseTLS     bool   `long:"tls" description:"Use TLS"`
diff --git a/internal/pkg/commands/command_test.go b/internal/pkg/commands/command_test.go
new file mode 100644
index 0000000..f44e312
--- /dev/null
+++ b/internal/pkg/commands/command_test.go
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2019-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package commands
+
+import (
+	flags "github.com/jessevdk/go-flags"
+	"github.com/stretchr/testify/assert"
+	"os"
+	"path"
+	"testing"
+)
+
+func TestDefaultVersion(t *testing.T) {
+	os.Setenv("VOLTCONFIG", "__DOES_NOT_EXIST__")
+
+	parser := flags.NewNamedParser(path.Base(os.Args[0]), flags.Default|flags.PassAfterNonOption)
+	_, err := parser.AddGroup("Global Options", "", &GlobalOptions)
+	assert.Nil(t, err, "unexpected error adding group")
+	RegisterConfigCommands(parser)
+	_, err = parser.ParseArgs([]string{"config"})
+	assert.Nil(t, err, "unexpected error paring arguments")
+	ProcessGlobalOptions()
+
+	assert.Equal(t, "v2", GlobalConfig.ApiVersion, "wrong default version for API version")
+}