From d4365617c72fdb9238b93663f447c2bec258b732 Mon Sep 17 00:00:00 2001 From: oanatmaria Date: Tue, 3 Oct 2023 14:00:00 +0300 Subject: [PATCH] Add console cli cmd --- go.mod | 1 + go.sum | 5 +++++ pkg/cli/cmd/cli.go | 1 + pkg/cli/cmd/console.go | 22 ++++++++++++++++++++++ 4 files changed, 29 insertions(+) create mode 100644 pkg/cli/cmd/console.go diff --git a/go.mod b/go.mod index f3a03414..04c2baae 100644 --- a/go.mod +++ b/go.mod @@ -24,6 +24,7 @@ require ( github.com/aserto-dev/runtime v0.54.2 github.com/aserto-dev/self-decision-logger v0.0.4 github.com/aserto-dev/service-host v0.0.5 + github.com/cli/browser v1.2.0 github.com/fatih/color v1.15.0 github.com/fullstorydev/grpcurl v1.8.7 github.com/google/uuid v1.3.1 diff --git a/go.sum b/go.sum index 6a74c0d5..ecbc9840 100644 --- a/go.sum +++ b/go.sum @@ -81,6 +81,8 @@ github.com/aserto-dev/go-directory v0.21.8-0.20230913224642-68ab4803494f h1:0hnP github.com/aserto-dev/go-directory v0.21.8-0.20230913224642-68ab4803494f/go.mod h1:ZsHSXALiP6F49/+zKDZP6GIcAWyYX95lkSVxM+8Jwno= github.com/aserto-dev/go-directory-cli v0.20.14-0.20230913232053-927068a67595 h1:t/L3jN8AhLQsqbJq7AD/zFMNQDH3sT+lKiM7VoIfMk4= github.com/aserto-dev/go-directory-cli v0.20.14-0.20230913232053-927068a67595/go.mod h1:+tWMBAzEd+TW7m0PEhVYTX50h4Nju1au+J151yeEUdA= +github.com/aserto-dev/go-edge-ds v0.21.10-0.20230918210437-130da75a4874 h1:q+IqDuGTfH0GF6+rtGkqaxNsWZwa/Cb/ScOZyShq8R0= +github.com/aserto-dev/go-edge-ds v0.21.10-0.20230918210437-130da75a4874/go.mod h1:CupD7d2BmNksBgJO/wogA62TM5TBqiy1atVBRlddqeQ= github.com/aserto-dev/go-grpc v0.8.57 h1:CjQVxZ2HkBvJrfCtaDeq2kZSn2yLmRel5kHCVzqRMLs= github.com/aserto-dev/go-grpc v0.8.57/go.mod h1:2FcclMDheTsEvYCY72o+EwTaoO0ti3/it4G6xIlzNIM= github.com/aserto-dev/go-http-metrics v0.10.1-20221024-1 h1:nONd24V5nyJ0IIw8QE+OKv30YuHOTNbJ4FsvczLaM8o= @@ -117,6 +119,8 @@ github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= +github.com/cli/browser v1.2.0 h1:yvU7e9qf97kZqGFX6n2zJPHsmSObY9ske+iCvKelvXg= +github.com/cli/browser v1.2.0/go.mod h1:xFFnXLVcAyW9ni0cuo6NnrbCP75JxJ0RO7VtCBiH/oI= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= @@ -660,6 +664,7 @@ golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/pkg/cli/cmd/cli.go b/pkg/cli/cmd/cli.go index f3a54b04..e947c0df 100644 --- a/pkg/cli/cmd/cli.go +++ b/pkg/cli/cmd/cli.go @@ -30,6 +30,7 @@ type CLI struct { Update UpdateCmd `cmd:"" help:"update topaz container version"` Uninstall UninstallCmd `cmd:"" help:"uninstall topaz container"` Version VersionCmd `cmd:"" help:"version information"` + Console ConsoleCmd `cmd:"" help:"opens the console in the browser"` NoCheck bool `name:"no-check" env:"TOPAZ_NO_CHECK" help:"disable local container status check"` } diff --git a/pkg/cli/cmd/console.go b/pkg/cli/cmd/console.go new file mode 100644 index 00000000..578bbaa7 --- /dev/null +++ b/pkg/cli/cmd/console.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "strings" + + "github.com/aserto-dev/topaz/pkg/cli/cc" + "github.com/cli/browser" +) + +type ConsoleCmd struct { + ConsoleAdress string `arg:"" default:"https://localhost:8080/ui/directory" help:"gateway address of the console service"` +} + +func (cmd *ConsoleCmd) Run(c *cc.CommonCtx) error { + if !strings.HasSuffix(cmd.ConsoleAdress, "/ui/directory") { + cmd.ConsoleAdress = cmd.ConsoleAdress + "/ui/directory" + } + if !strings.HasPrefix(cmd.ConsoleAdress, "https://") { + cmd.ConsoleAdress = "https://" + cmd.ConsoleAdress + } + return browser.OpenURL(cmd.ConsoleAdress) +}