Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: 🔵 Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.24.x
go-version: 1.25.x

- name: ⏬ Install Dependencies
run: go get .
Expand Down
15 changes: 0 additions & 15 deletions cmd/config/config.go

This file was deleted.

105 changes: 0 additions & 105 deletions cmd/config/copy/copy.go

This file was deleted.

4 changes: 2 additions & 2 deletions cmd/info/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func showEnvironment(writer io.Writer) {
fmt.Fprintln(writer, styles.HeaderStyle().Render("Environment Variables"))
fmt.Fprintln(writer, styles.Header().Render("Environment Variables"))

var envVars [][]string
for key, value := range env.GetAll() {
Expand All @@ -22,7 +22,7 @@ func showEnvironment(writer io.Writer) {
}

if len(envVars) == 0 {
fmt.Fprintln(writer, styles.WarningStyle().Render(" No environment variables found"))
fmt.Fprintln(writer, styles.Warning().Render(" No environment variables found"))
return
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/info/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func fetchExtensions() [][]string {
}

func showExtensions(writer io.Writer) {
fmt.Fprintln(writer, styles.HeaderStyle().Render("Extensions"))
fmt.Fprintln(writer, styles.Header().Render("Extensions"))
fmt.Fprintln(writer)

t := styles.Table("Name", "Version").
Expand Down
2 changes: 1 addition & 1 deletion cmd/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func readJson(content map[string]any, key string) string {
func showVersion(writer io.Writer) {
content := readJsonFile()

fmt.Fprintln(writer, styles.HeaderStyle().Render("Versions"))
fmt.Fprintln(writer, styles.Header().Render("Versions"))
fmt.Fprintln(writer)

t := styles.Table("", "Value").
Expand Down
2 changes: 1 addition & 1 deletion cmd/info/uptime.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func humanizeDuration(duration time.Duration) string {
func showUptime(writer io.Writer) {
started, running, _ := readStartup()

fmt.Fprintln(writer, styles.HeaderStyle().Render("Uptime"))
fmt.Fprintln(writer, styles.Header().Render("Uptime"))
fmt.Fprintln(writer)

t := styles.Table("", "Value").
Expand Down
6 changes: 3 additions & 3 deletions cmd/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ func execute(cmd *cobra.Command, args []string) {
level, _ := cmd.Flags().GetString("level")

if level != "" && level != "info" && level != "warn" && level != "error" && level != "debug" {
fmt.Fprintln(cmd.ErrOrStderr(), styles.ErrorStyle().Render("Invalid log level. Must be one of: debug, info, warn, error"))
fmt.Fprintln(cmd.ErrOrStderr(), styles.Error().Render("Invalid log level. Must be one of: debug, info, warn, error"))
os.Exit(1)
}

reader, err := logger.NewReader(tail, level)
if err != nil {
fmt.Fprintln(cmd.ErrOrStderr(), styles.ErrorStyle().Render(fmt.Sprintf("Error: %s", err)))
fmt.Fprintln(cmd.ErrOrStderr(), styles.Error().Render(fmt.Sprintf("Error: %s", err)))
os.Exit(1)
}

Expand All @@ -39,7 +39,7 @@ func execute(cmd *cobra.Command, args []string) {
}

if err != nil {
fmt.Fprintln(cmd.ErrOrStderr(), styles.ErrorStyle().Render(fmt.Sprintf("Error reading logs: %s", err)))
fmt.Fprintln(cmd.ErrOrStderr(), styles.Error().Render(fmt.Sprintf("Error reading logs: %s", err)))
os.Exit(1)
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"os"

"github.com/kloudkit/ws-cli/cmd/clip"
"github.com/kloudkit/ws-cli/cmd/config"
"github.com/kloudkit/ws-cli/cmd/feature"
"github.com/kloudkit/ws-cli/cmd/info"
"github.com/kloudkit/ws-cli/cmd/log"
"github.com/kloudkit/ws-cli/cmd/logs"
"github.com/kloudkit/ws-cli/cmd/serve"
"github.com/kloudkit/ws-cli/cmd/show"
"github.com/kloudkit/ws-cli/cmd/template"
"github.com/kloudkit/ws-cli/internals/styles"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -55,10 +55,10 @@ func init() {

rootCmd.AddCommand(
clip.ClipCmd,
config.ConfigCmd,
feature.FeatureCmd,
serve.ServeCmd,
show.ShowCmd,
template.TemplateCmd,
info.InfoCmd,
log.LogCmd,
logs.LogsCmd,
Expand Down
6 changes: 4 additions & 2 deletions cmd/show/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var ipInternalCmd = &cobra.Command{
ip, err := net.GetInternalIP()

if err == nil {
fmt.Fprintln(cmd.OutOrStdout(), styles.ValueStyle().Render(ip))
fmt.Fprintln(cmd.OutOrStdout(), styles.Value().Render(ip))
}

return err
Expand All @@ -34,7 +34,7 @@ var ipNodeCmd = &cobra.Command{
ip, err := net.GetNodeIP()

if err == nil {
fmt.Fprintln(cmd.OutOrStdout(), styles.ValueStyle().Render(ip))
fmt.Fprintln(cmd.OutOrStdout(), styles.Value().Render(ip))
}

return err
Expand All @@ -43,4 +43,6 @@ var ipNodeCmd = &cobra.Command{

func init() {
ipCmd.AddCommand(ipInternalCmd, ipNodeCmd)

ShowCmd.AddCommand(ipCmd)
}
6 changes: 4 additions & 2 deletions cmd/show/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var pathHomeCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintln(
cmd.OutOrStdout(),
styles.ValueStyle().Render(env.String("WS_SERVER_ROOT", "/workspace")),
styles.Value().Render(env.String("WS_SERVER_ROOT", "/workspace")),
)
},
}
Expand All @@ -37,12 +37,14 @@ var pathVscodeCmd = &cobra.Command{
settingsPath = path.GetHomeDirectory("/.local/share/code-server/User/settings.json")
}

fmt.Fprintln(cmd.OutOrStdout(), styles.ValueStyle().Render(settingsPath))
fmt.Fprintln(cmd.OutOrStdout(), styles.Value().Render(settingsPath))
},
}

func init() {
pathVscodeCmd.Flags().Bool("workspace", false, "Get the workspace settings")

pathCmd.AddCommand(pathHomeCmd, pathVscodeCmd)

ShowCmd.AddCommand(pathCmd)
}
4 changes: 0 additions & 4 deletions cmd/show/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@ var ShowCmd = &cobra.Command{
Use: "show",
Short: "Show information about the current workspace instance",
}

func init() {
ShowCmd.AddCommand(pathCmd, ipCmd)
}
50 changes: 50 additions & 0 deletions cmd/template/apply.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package template

import (
"fmt"

"github.com/kloudkit/ws-cli/internals/styles"
"github.com/kloudkit/ws-cli/internals/template"
"github.com/spf13/cobra"
)

var applyCmd = &cobra.Command{
Use: "apply <template>",
Short: "Apply a configuration template to the current project",
Args: cobra.ExactArgs(1),
ValidArgsFunction: templateCompletion,
RunE: runApply,
}

func runApply(cmd *cobra.Command, args []string) error {
templateName := args[0]
targetPath, _ := cmd.Flags().GetString("path")
force, _ := cmd.Flags().GetBool("force")

if err := template.ApplyTemplate(templateName, targetPath, force); err != nil {
return err
}

config, _ := template.GetTemplate(templateName)
sourcePath := template.SupportedTemplates[templateName].SourcePath

fmt.Fprintf(cmd.OutOrStdout(), "%s\n", styles.Success().Render("Template applied successfully:"))
fmt.Fprintf(cmd.OutOrStdout(), " %s %s\n", styles.Key().Render("Source:"), sourcePath)
fmt.Fprintf(cmd.OutOrStdout(), " %s %s/%s\n", styles.Key().Render("Target:"), targetPath, config.OutputName)

return nil
}

func templateCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
return template.GetTemplateNames(), cobra.ShellCompDirectiveNoFileComp
}

func init() {
applyCmd.Flags().String("path", ".", "Target directory path")
applyCmd.Flags().BoolP("force", "f", false, "Overwrite existing files")

TemplateCmd.AddCommand(applyCmd)
}
43 changes: 43 additions & 0 deletions cmd/template/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package template

import (
"fmt"

"github.com/kloudkit/ws-cli/internals/path"
"github.com/kloudkit/ws-cli/internals/styles"
"github.com/kloudkit/ws-cli/internals/template"
"github.com/spf13/cobra"
)

var listCmd = &cobra.Command{
Use: "list",
Short: "List all available configuration templates",
Aliases: []string{"ls"},
RunE: runList,
}

func runList(cmd *cobra.Command, args []string) error {
templates := template.SupportedTemplates
names := template.GetTemplateNames()

listItems := make([]any, len(names))
for i, name := range names {
config := templates[name]
resolvedPath := path.ResolveConfigPath(config.SourcePath)
location := styles.Muted().Render(fmt.Sprintf("(%s)", path.ShortenHomePath(resolvedPath)))
listItems[i] = fmt.Sprintf("%s %s", styles.Key().Render(name), location)
}

l := styles.List(listItems...)

fmt.Fprintf(cmd.OutOrStdout(), "%s\n\n", styles.Success().Render("Available Templates"))
fmt.Fprintf(cmd.OutOrStdout(), "%s\n\n", l.String())
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", styles.Muted().Render("Use 'ws-cli template apply <name>' to apply a template"))
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", styles.Muted().Render("Use 'ws-cli template show <name>' to view template contents"))

return nil
}

func init() {
TemplateCmd.AddCommand(listCmd)
}
Loading
Loading