Skip to content

Commit

Permalink
refact: kl-native (#226)
Browse files Browse the repository at this point in the history
- removed box commands
- added native vpn support
- added native shell support
- updated intercept command
- added lib commands to mange library
  • Loading branch information
abdheshnayak authored Dec 13, 2024
1 parent 17ea7f2 commit 4fb0463
Show file tree
Hide file tree
Showing 185 changed files with 7,817 additions and 6,958 deletions.
83 changes: 53 additions & 30 deletions clis/kl/loadsubs.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
package kl

import (

// "github.com/kloudlite/kl/cmd/box"

"os/exec"
"runtime"

"github.com/kloudlite/kl/cmd/auth"
"github.com/kloudlite/kl/cmd/box"
"github.com/kloudlite/kl/cmd/clone"
"github.com/kloudlite/kl/cmd/cluster"
"github.com/kloudlite/kl/cmd/connect"
"github.com/kloudlite/kl/cmd/env"
"github.com/kloudlite/kl/cmd/expose"
daemon_cmd "github.com/kloudlite/kl/cmd/daemon"
"github.com/kloudlite/kl/cmd/get"
"github.com/kloudlite/kl/cmd/initp"
"github.com/kloudlite/kl/cmd/intercept"
"github.com/kloudlite/kl/cmd/kubectl"
"github.com/kloudlite/kl/cmd/list"
"github.com/kloudlite/kl/cmd/packages"
"github.com/kloudlite/kl/cmd/runner"
"github.com/kloudlite/kl/cmd/packages/lib"
"github.com/kloudlite/kl/cmd/packages/pkg"
"github.com/kloudlite/kl/cmd/packages/shell"
"github.com/kloudlite/kl/cmd/runner/add"
set_base_url "github.com/kloudlite/kl/cmd/set-base-url"
"github.com/kloudlite/kl/cmd/status"
"github.com/kloudlite/kl/cmd/use"
"github.com/kloudlite/kl/cmd/vpn"
"github.com/kloudlite/kl/constants"
"github.com/kloudlite/kl/flags"
"github.com/spf13/cobra"
)
Expand All @@ -34,38 +37,58 @@ func init() {
rootCmd.AddCommand(DocsCmd)
}

rootCmd.AddCommand(UpdateCmd)
rootCmd.AddCommand(list.Cmd)
rootCmd.AddCommand(get.Cmd)
rootCmd.AddCommand(auth.Cmd)
rootCmd.AddCommand(box.BoxCmd)
rootCmd.AddCommand(UpdateCmd)
rootCmd.AddCommand(set_base_url.Cmd)
rootCmd.AddCommand(initp.InitCommand)

rootCmd.AddCommand(use.Cmd)
rootCmd.AddCommand(clone.Cmd)
rootCmd.AddCommand(env.Cmd)
rootCmd.AddCommand(runner.InitCommand)
rootCmd.AddCommand(runner.AttachCommand)
rootCmd.AddCommand(set_base_url.Cmd)
rootCmd.AddCommand(list.Cmd)
rootCmd.AddCommand(get.Cmd)
rootCmd.AddCommand(vpn.Cmd)
rootCmd.AddCommand(daemon_cmd.Cmd)

rootCmd.AddCommand(intercept.Cmd)
if runtime.GOOS == constants.RuntimeWindows {
return
}

rootCmd.AddCommand(cluster.Cmd)
rootCmd.AddCommand(expose.Cmd)
rootCmd.AddCommand(pkg.Cmd)
rootCmd.AddCommand(lib.Cmd)
rootCmd.AddCommand(shell.Cmd)

rootCmd.AddCommand(add.Command)

rootCmd.AddCommand(intercept.Cmd)
// rootCmd.AddCommand(expose.Cmd)

rootCmd.AddCommand(status.Cmd)
rootCmd.AddCommand(packages.Cmd)
rootCmd.AddCommand(packages.LibCmd)

rootCmd.AddCommand(connect.Command)
// Not Required for now
// rootCmd.AddCommand(env.Cmd)
// rootCmd.AddCommand(clone.Cmd)

if flags.IsDev() {
if _, err := exec.LookPath("k9s"); err == nil {
rootCmd.AddCommand(kubectl.K9sCmd)
}
if runtime.GOOS == constants.RuntimeDarwin {
return
}

// rootCmd.AddCommand(box.BoxCmd)

// rootCmd.AddCommand(runner.AttachCommand)
//
//
// rootCmd.AddCommand(cluster.Cmd)
//
// rootCmd.AddCommand(connect.Command)
// rootCmd.AddCommand(v2Shell.Command)
// rootCmd.AddCommand(v2Add.Command)
// rootCmd.AddCommand(v2Pkg.Command)
// rootCmd.AddCommand(v2Lib.Command)

if _, err := exec.LookPath("k9s"); err == nil {
rootCmd.AddCommand(kubectl.K9sCmd)
}

if _, err := exec.LookPath("kubectl"); err == nil {
rootCmd.AddCommand(kubectl.KubectlCmd)
}
if _, err := exec.LookPath("kubectl"); err == nil {
rootCmd.AddCommand(kubectl.KubectlCmd)
}
}
12 changes: 6 additions & 6 deletions clis/kl/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"syscall"
"time"

"github.com/kloudlite/kl/domain/fileclient"
"github.com/kloudlite/kl/domain/clients"
"github.com/kloudlite/kl/pkg/ui/text"

"github.com/kloudlite/kl/flags"
Expand All @@ -20,7 +20,6 @@ import (
var rootCmd = &cobra.Command{
Use: flags.CliName,
PersistentPreRun: func(cmd *cobra.Command, _ []string) {

// u := updater.NewUpdater()
// b, err := u.CheckForUpdates()
// if err != nil {
Expand Down Expand Up @@ -78,9 +77,11 @@ func Execute() {
}

func versionCheck() {
data, err := fileclient.GetExtraData()
fc := clients.File

data, err := fc.GetExtraData()
if err == nil {
if time.Since(data.LastUpdateCheck).Hours() > 12 {
if time.Since(data.GetLastUpdatedCheck()).Hours() > 12 {
u := updater.NewUpdater()
available, err := u.CheckForUpdates()
if err != nil {
Expand All @@ -100,8 +101,7 @@ func versionCheck() {
}

fn.Log(*s)
data.LastUpdateCheck = time.Now()
if err := fileclient.SaveExtraData(data); err != nil {
if err := data.SetLastUpdatedCheck(time.Now()); err != nil {
fn.Log(text.Yellow("Failed to save extra data"))
}
}
Expand Down
3 changes: 3 additions & 0 deletions clis/kl/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"runtime"
"strings"

"github.com/kloudlite/kl/constants"
"github.com/kloudlite/kl/flags"
Expand Down Expand Up @@ -51,6 +52,8 @@ func ExecUpdateCmd(version string) error {
var cmd *exec.Cmd
curlAvailable := isCommandAvailable("curl")
wgetAvailable := isCommandAvailable("wget")
*uurl = strings.Trim(*uurl, " ")
*uurl = strings.Trim(*uurl, "\n")
if curlAvailable {
cmd = exec.Command("bash", "-c", fmt.Sprintf("curl %s%s!?select=%s | bash", *uurl, version, flags.CliName))
} else if wgetAvailable {
Expand Down
3 changes: 0 additions & 3 deletions cmd/auth/auth.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package auth

import (
"github.com/kloudlite/kl/domain/fileclient"
"github.com/spf13/cobra"
)

Expand All @@ -12,8 +11,6 @@ var Cmd = &cobra.Command{
}

func init() {
fileclient.OnlyOutsideBox(loginCmd)
fileclient.OnlyOutsideBox(logoutCmd)
Cmd.AddCommand(loginCmd)
Cmd.AddCommand(logoutCmd)
Cmd.AddCommand(authStatusCmd)
Expand Down
48 changes: 8 additions & 40 deletions cmd/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package auth

import (
"fmt"

"github.com/kloudlite/kl/constants"
"github.com/kloudlite/kl/domain/apiclient"
"github.com/kloudlite/kl/domain/fileclient"
"github.com/kloudlite/kl/domain/clients"
fn "github.com/kloudlite/kl/pkg/functions"
"github.com/kloudlite/kl/pkg/ui/text"
"github.com/spf13/cobra"
Expand All @@ -14,16 +14,9 @@ var loginCmd = &cobra.Command{
Use: "login",
Short: "login to kloudlite",
Run: func(cmd *cobra.Command, _ []string) {
apic, err := apiclient.New()
if err != nil {
fn.PrintError(err)
return
}
_, err = fileclient.New()
if err != nil {
fn.PrintError(err)
return
}

apic := clients.Api

loginId, err := apic.CreateRemoteLogin()
if err != nil {
fn.PrintError(err)
Expand All @@ -36,30 +29,12 @@ var loginCmd = &cobra.Command{
fn.Println(text.Colored(text.Blue(link), 21))
fn.Log("\n")

//go func() {
// fn.Log("press enter to open link in browser")
// reader, err := bufio.NewReader(os.Stdin).ReadString('\n')
// if err != nil {
// fn.PrintError(err)
// return
// }
// if strings.Contains(reader, "\n") {
// err := fn.OpenUrl(link)
// if err != nil {
// fn.PrintError(err)
// return
// }
// } else {
// fn.Log("Invalid input\n")
// }
//}()

if err = apic.Login(loginId); err != nil {
fn.PrintError(err)
return
}

extraData, err := fileclient.GetExtraData()
extraData, err := apic.GetFClient().GetExtraData()
if err != nil {
fn.PrintError(err)
return
Expand All @@ -70,18 +45,11 @@ var loginCmd = &cobra.Command{
fn.PrintError(err)
return
}
extraData.DnsHostSuffix = HostDNSSuffix
err = fileclient.SaveExtraData(extraData)
if err != nil {

if err := extraData.SetDnsHostSuffix(HostDNSSuffix); err != nil {
fn.PrintError(err)
return
}

//if err = use.UseTeam(cmd); err != nil {
// fn.PrintError(err)
// return
//}

fn.Log("successfully logged in\n")
},
}
14 changes: 5 additions & 9 deletions cmd/auth/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
dockerclient "github.com/docker/docker/client"
"github.com/kloudlite/kl/cmd/box/boxpkg"
"github.com/kloudlite/kl/domain/fileclient"
"github.com/kloudlite/kl/constants"
"github.com/kloudlite/kl/domain/clients"
fn "github.com/kloudlite/kl/pkg/functions"
"github.com/kloudlite/kl/pkg/ui/spinner"
"github.com/spf13/cobra"
Expand All @@ -19,12 +19,8 @@ var logoutCmd = &cobra.Command{
Example: `# Logout from kloudlite
{cmd} auth logout`,
Run: func(cmd *cobra.Command, _ []string) {
fc, err := fileclient.New()
if err != nil {
fn.PrintError(err)
return
}
err = stopAllContainers(cmd)
fc := clients.File
err := stopAllContainers(cmd)
if err != nil {
fn.PrintError(err)
return
Expand All @@ -45,7 +41,7 @@ func stopAllContainers(cmd *cobra.Command) error {

crlist, err := cli.ContainerList(cmd.Context(), container.ListOptions{
Filters: filters.NewArgs(
filters.KeyValuePair{Key: "label", Value: fmt.Sprintf("%s=%s", boxpkg.CONT_MARK_KEY, "true")},
filters.KeyValuePair{Key: "label", Value: fmt.Sprintf("%s=%s", constants.KL_CONTAINER_MARK, "true")},
),
All: true,
})
Expand Down
9 changes: 3 additions & 6 deletions cmd/auth/status.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package auth

import (
"github.com/kloudlite/kl/domain/apiclient"
"github.com/kloudlite/kl/domain/clients"
fn "github.com/kloudlite/kl/pkg/functions"
"github.com/kloudlite/kl/pkg/ui/text"
"github.com/spf13/cobra"
Expand All @@ -11,11 +11,8 @@ var authStatusCmd = &cobra.Command{
Use: "status",
Short: "get the current user's name and email",
Run: func(_ *cobra.Command, _ []string) {
apic, err := apiclient.New()
if err != nil {
fn.PrintError(err)
return
}
apic := clients.Api

if u, err := apic.GetCurrentUser(); err != nil {
fn.PrintError(err)
return
Expand Down
14 changes: 0 additions & 14 deletions cmd/box/boxpkg/consts.go

This file was deleted.

Loading

0 comments on commit 4fb0463

Please sign in to comment.