VOL-4202 - always attempt to expand config path
Change-Id: Iadd26fc448f44cc1a7a0eefcf130c26e1391542c
diff --git a/VERSION b/VERSION
index 15d45d4..1df3b82 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.6.9
+1.6.10
diff --git a/internal/pkg/commands/command.go b/internal/pkg/commands/command.go
index 8cefc14..6e6d0d3 100644
--- a/internal/pkg/commands/command.go
+++ b/internal/pkg/commands/command.go
@@ -24,6 +24,7 @@
"io/ioutil"
"log"
"os"
+ "os/user"
"path/filepath"
"reflect"
"regexp"
@@ -295,16 +296,59 @@
}
}
-func ReadConfig() {
- if len(GlobalOptions.Config) == 0 {
+func homeDir() (string, error) {
+
+ // First attempt is using the current user information, if that
+ // fails we attempt to use the environment variables via a call
+ // to os.UserHomeDir()
+ cur, err := user.Current()
+ if err != nil {
home, err := os.UserHomeDir()
if err != nil {
- Warn.Printf("Unable to discover the user's home directory: %s", err)
- home = "~"
+ return "", errors.New("unable to get current user or determine home directory via environment")
+ }
+ return home, nil
+ }
+ if len(cur.HomeDir) == 0 {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ return "", errors.New("unable to get determine home directory via user information or environment")
+ }
+ return home, nil
+ }
+ return cur.HomeDir, nil
+}
+
+func ReadConfig() {
+ // assume that the config file was specified until it is
+ // determined it was not
+ if len(GlobalOptions.Config) == 0 {
+ home, err := homeDir()
+ if err != nil {
+ Error.Fatalf("Unable to create default configuration file path: %s", err.Error())
}
GlobalOptions.Config = filepath.Join(home, ".volt", "config")
}
+ // If the config file value is `~` or begins with `~/` then
+ // attempt to expand that to the user's home directory
+ if GlobalOptions.Config == "~" {
+ home, err := homeDir()
+ if err != nil {
+ Error.Fatalf("Unable to expand config file path '%s': %s",
+ GlobalOptions.Config, err)
+ }
+ GlobalOptions.Config = home
+ } else if strings.HasPrefix(GlobalOptions.Config, "~/") {
+ home, err := homeDir()
+ if err != nil {
+ Error.Fatalf("Unable to expand config file path '%s': %s",
+ GlobalOptions.Config, err)
+ }
+ GlobalOptions.Config = filepath.Join(home,
+ GlobalOptions.Config[2:])
+ }
+
if info, err := os.Stat(GlobalOptions.Config); err == nil && !info.IsDir() {
configFile, err := ioutil.ReadFile(GlobalOptions.Config)
if err != nil {
@@ -327,7 +371,6 @@
}
}
}
-
}
func NewConnection() (*grpc.ClientConn, error) {
diff --git a/voltctl.v3.config b/voltctl.v3.config
index d890fb7..a76d777 100644
--- a/voltctl.v3.config
+++ b/voltctl.v3.config
@@ -11,7 +11,7 @@
# 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.
-apiVersion: v2
+apiVersion: v3
stacks:
- name: default
server: localhost:55555