From 0ce81acbf49f9a56f702f132fb097fd98e15e1c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Mon, 23 Mar 2020 21:49:19 +0100 Subject: [PATCH 1/2] Centralize the handling of browser.OpenURL So we can catch when xdg-open not installed --- cmd/minikube/cmd/config/open.go | 3 +-- cmd/minikube/cmd/dashboard.go | 2 +- cmd/minikube/cmd/service.go | 2 +- pkg/minikube/browser/browser.go | 35 +++++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 pkg/minikube/browser/browser.go diff --git a/cmd/minikube/cmd/config/open.go b/cmd/minikube/cmd/config/open.go index c4c8b5416dba..dc4fd0fb7ada 100644 --- a/cmd/minikube/cmd/config/open.go +++ b/cmd/minikube/cmd/config/open.go @@ -21,11 +21,10 @@ import ( "os" "text/template" - "github.com/pkg/browser" - "github.com/spf13/cobra" "github.com/spf13/viper" "k8s.io/minikube/pkg/minikube/assets" + "k8s.io/minikube/pkg/minikube/browser" "k8s.io/minikube/pkg/minikube/config" pkg_config "k8s.io/minikube/pkg/minikube/config" "k8s.io/minikube/pkg/minikube/driver" diff --git a/cmd/minikube/cmd/dashboard.go b/cmd/minikube/cmd/dashboard.go index b5fd848eb303..b65c53eb84ea 100644 --- a/cmd/minikube/cmd/dashboard.go +++ b/cmd/minikube/cmd/dashboard.go @@ -29,12 +29,12 @@ import ( "github.com/docker/machine/libmachine/mcnerror" "github.com/golang/glog" - "github.com/pkg/browser" "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/viper" pkgaddons "k8s.io/minikube/pkg/addons" "k8s.io/minikube/pkg/minikube/assets" + "k8s.io/minikube/pkg/minikube/browser" "k8s.io/minikube/pkg/minikube/config" pkg_config "k8s.io/minikube/pkg/minikube/config" "k8s.io/minikube/pkg/minikube/driver" diff --git a/cmd/minikube/cmd/service.go b/cmd/minikube/cmd/service.go index 08c0fb87d54a..ae14afda08f7 100644 --- a/cmd/minikube/cmd/service.go +++ b/cmd/minikube/cmd/service.go @@ -30,11 +30,11 @@ import ( "time" "github.com/golang/glog" - "github.com/pkg/browser" "github.com/spf13/cobra" "github.com/spf13/viper" "k8s.io/minikube/pkg/drivers/kic/oci" + "k8s.io/minikube/pkg/minikube/browser" "k8s.io/minikube/pkg/minikube/config" pkg_config "k8s.io/minikube/pkg/minikube/config" "k8s.io/minikube/pkg/minikube/driver" diff --git a/pkg/minikube/browser/browser.go b/pkg/minikube/browser/browser.go new file mode 100644 index 000000000000..dd6a4799dbca --- /dev/null +++ b/pkg/minikube/browser/browser.go @@ -0,0 +1,35 @@ +/* +Copyright 2020 The Kubernetes Authors All rights reserved. + +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 browser + +import ( + "os/exec" + "runtime" + + "github.com/pkg/browser" +) + +// OpenURL opens a new browser window pointing to URL. +func OpenURL(url string) error { + if runtime.GOOS == "linux" { + _, err := exec.LookPath("xdg-open") + if err != nil { + return err + } + } + return browser.OpenURL(url) +} From 54bbdde812e264e9bf31812363a89aa5a6fe4d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Mon, 23 Mar 2020 22:11:22 +0100 Subject: [PATCH 2/2] Print the URL, instead of return an error Let the terminal user open it themselves --- pkg/minikube/browser/browser.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/minikube/browser/browser.go b/pkg/minikube/browser/browser.go index dd6a4799dbca..890e068844e3 100644 --- a/pkg/minikube/browser/browser.go +++ b/pkg/minikube/browser/browser.go @@ -21,6 +21,7 @@ import ( "runtime" "github.com/pkg/browser" + "k8s.io/minikube/pkg/minikube/out" ) // OpenURL opens a new browser window pointing to URL. @@ -28,7 +29,8 @@ func OpenURL(url string) error { if runtime.GOOS == "linux" { _, err := exec.LookPath("xdg-open") if err != nil { - return err + out.T(out.URL, url) + return nil } } return browser.OpenURL(url)