Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 34 additions & 17 deletions cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ func GetOptions() *Options {
Port: defaultVxlanPort,
DeletionPrefix: "vx-",
},
ToolsCodeServer: &ToolsCodeServerOptions{
Image: "ghcr.io/kaelemc/clab-code-server:main",
Name: "clab-code-server",
LogLevel: "debug",
OutputFormat: "table",
},
Version: &VersionOptions{
Short: false,
JSON: false,
Expand All @@ -110,23 +116,24 @@ func GetOptions() *Options {
}

type Options struct {
Global *GlobalOptions
Filter *FilterOptions
Deploy *DeployOptions
Destroy *DestroyOptions
Config *ConfigOptions
Exec *ExecOptions
Inspect *InspectOptions
Graph *GraphOptions
ToolsAPI *ToolsApiOptions
ToolsCert *ToolsCertOptions
ToolsTxOffload *ToolsDisableTxOffloadOptions
ToolsGoTTY *ToolsGoTTYOptions
ToolsNetem *ToolsNetemOptions
ToolsSSHX *ToolsSSHXOptions
ToolsVeth *ToolsVethOptions
ToolsVxlan *ToolsVxlanOptions
Version *VersionOptions
Global *GlobalOptions
Filter *FilterOptions
Deploy *DeployOptions
Destroy *DestroyOptions
Config *ConfigOptions
Exec *ExecOptions
Inspect *InspectOptions
Graph *GraphOptions
ToolsAPI *ToolsApiOptions
ToolsCert *ToolsCertOptions
ToolsTxOffload *ToolsDisableTxOffloadOptions
ToolsGoTTY *ToolsGoTTYOptions
ToolsNetem *ToolsNetemOptions
ToolsSSHX *ToolsSSHXOptions
ToolsVeth *ToolsVethOptions
ToolsVxlan *ToolsVxlanOptions
ToolsCodeServer *ToolsCodeServerOptions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

welcome to the cmd package shenanigans @kaelemc <3 :D

Version *VersionOptions
}

func (o *Options) ToClabOptions() []clabcore.ClabOption {
Expand Down Expand Up @@ -427,6 +434,16 @@ type ToolsVxlanOptions struct {
DeletionPrefix string
}

type ToolsCodeServerOptions struct {
Image string
Name string
Port uint
LogLevel string
OutputFormat string
LabsDirectory string
Owner string
}

type VersionOptions struct {
Short bool
JSON bool
Expand Down
17 changes: 17 additions & 0 deletions cmd/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package cmd

import (
"os"
"path/filepath"
"strings"

Expand All @@ -22,6 +23,7 @@ func toolsSubcommandRegisterFuncs() []func(*Options) (*cobra.Command, error) {
sshxCmd,
vethCmd,
vxlanCmd,
codeServerCmd,
}
}

Expand Down Expand Up @@ -81,3 +83,18 @@ func createLabelsMap(topo, labName, containerName, owner, toolType string) map[s

return labels
}

// getclabBinaryPath determine the binary path of the running executable.
func getclabBinaryPath() (string, error) {
exePath, err := os.Executable()
if err != nil {
return "", err
}

absPath, err := filepath.EvalSymlinks(exePath)
if err != nil {
return "", err
}

return absPath, nil
}
13 changes: 1 addition & 12 deletions cmd/tools_api_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package cmd
import (
"fmt"
"os"
"path/filepath"

"github.com/charmbracelet/log"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -93,16 +92,6 @@ func (*APIServerNode) GetEndpoints() []clablinks.Endpoint {
return nil
}

// getclabBinaryPath determine the binary path of the running executable.
func getclabBinaryPath() (string, error) {
exePath, err := os.Executable()
if err != nil {
return "", err
}

return filepath.EvalSymlinks(exePath)
}

// createLabels creates container labels.
func createAPIServerLabels(
containerName,
Expand Down Expand Up @@ -239,7 +228,7 @@ func apiServerStart(cobraCmd *cobra.Command, o *Options) error { //nolint: funle

// Create container labels
if o.ToolsAPI.LabsDirectory == "" {
o.ToolsAPI.LabsDirectory = "~/.clab"
o.ToolsAPI.LabsDirectory = defaultLabsDir
}

owner := getOwnerName(o)
Expand Down
2 changes: 1 addition & 1 deletion cmd/tools_api_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func apiServerStatus(cobraCmd *cobra.Command, o *Options) error {
}

// Get labs dir from labels or use default
labsDir := "~/.clab" // default
labsDir := defaultLabsDir // default
if dirsVal, ok := containers[idx].Labels["clab-labs-dir"]; ok {
labsDir = dirsVal
}
Expand Down
Loading