diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bf1819f..df2eb36 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 . diff --git a/cmd/config/config.go b/cmd/config/config.go deleted file mode 100644 index e59560e..0000000 --- a/cmd/config/config.go +++ /dev/null @@ -1,15 +0,0 @@ -package config - -import ( - "github.com/kloudkit/ws-cli/cmd/config/copy" - "github.com/spf13/cobra" -) - -var ConfigCmd = &cobra.Command{ - Use: "config", - Short: "Interact with workspace related configurations", -} - -func init() { - ConfigCmd.AddCommand(copy.CopyCmd) -} diff --git a/cmd/config/copy/copy.go b/cmd/config/copy/copy.go deleted file mode 100644 index b7f78a0..0000000 --- a/cmd/config/copy/copy.go +++ /dev/null @@ -1,105 +0,0 @@ -package copy - -import ( - "fmt" - "io" - "os" - "path/filepath" - - "github.com/kloudkit/ws-cli/internals/path" - "github.com/spf13/cobra" -) - -type config struct { - SourcePath string - OutputName string -} - -var configs = map[string]config{ - "markdownlint": { - SourcePath: ".config/markdownlint/config", - OutputName: ".markdownlint.json", - }, - "ruff": { - SourcePath: ".config/ruff/ruff.toml", - OutputName: ".ruff.toml", - }, - "yamllint": { - SourcePath: ".config/yamllint/config", - OutputName: ".yamllint", - }, -} - -var CopyCmd = &cobra.Command{ - Use: "cp", - Short: "Copying workspace defined configurations to a project", -} - -func copy(source, dest string) error { - stats, err := os.Stat(source) - if err != nil { - return err - } - - if !stats.Mode().IsRegular() { - return fmt.Errorf("%s is not a regular file", source) - } - - sourceFile, err := os.Open(source) - if err != nil { - return err - } - defer sourceFile.Close() - - destFile, err := os.Create(dest) - if err != nil { - fmt.Println(err) - return err - } - defer destFile.Close() - - _, err = io.Copy(destFile, sourceFile) - - return err -} - -func createCommand(key string) *cobra.Command { - config := configs[key] - - return &cobra.Command{ - Use: key, - Short: fmt.Sprintf("Copy %s configuration to the project", key), - RunE: func(cmd *cobra.Command, args []string) error { - dest, _ := cmd.Flags().GetString("dest") - force, _ := cmd.Flags().GetBool("force") - - source := path.GetHomeDirectory(config.SourcePath) - - dest, _ = filepath.Abs(dest) - dest = path.AppendSegments(dest, config.OutputName) - - if !path.CanOverride(dest, force) { - return fmt.Errorf("the file [%s] already exists", dest) - } - - if err := copy(source, dest); err != nil { - return fmt.Errorf("the file [%s] could not be written", dest) - } - - fmt.Fprintf(cmd.OutOrStdout(), "Copied [%s] to [%s]\n", source, dest) - - return nil - }, - } -} - -func init() { - CopyCmd.PersistentFlags().String("dest", ".", "Output directory") - CopyCmd.PersistentFlags().BoolP("force", "f", false, "Force the overwriting of an existing file") - - CopyCmd.AddCommand( - createCommand("markdownlint"), - createCommand("ruff"), - createCommand("yamllint"), - ) -} diff --git a/cmd/info/env.go b/cmd/info/env.go index 6b6d5e1..ea439ab 100644 --- a/cmd/info/env.go +++ b/cmd/info/env.go @@ -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() { @@ -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 } diff --git a/cmd/info/extensions.go b/cmd/info/extensions.go index adf1adc..cef8b8d 100644 --- a/cmd/info/extensions.go +++ b/cmd/info/extensions.go @@ -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"). diff --git a/cmd/info/info.go b/cmd/info/info.go index fb622b1..2b4c3f3 100644 --- a/cmd/info/info.go +++ b/cmd/info/info.go @@ -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"). diff --git a/cmd/info/uptime.go b/cmd/info/uptime.go index e863a0a..573dcd3 100644 --- a/cmd/info/uptime.go +++ b/cmd/info/uptime.go @@ -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"). diff --git a/cmd/logs/logs.go b/cmd/logs/logs.go index 29a20d0..a2f18e0 100644 --- a/cmd/logs/logs.go +++ b/cmd/logs/logs.go @@ -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) } @@ -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) } } diff --git a/cmd/root.go b/cmd/root.go index e32bbd8..8974e98 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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" ) @@ -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, diff --git a/cmd/show/ip.go b/cmd/show/ip.go index 73b301e..a224e08 100644 --- a/cmd/show/ip.go +++ b/cmd/show/ip.go @@ -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 @@ -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 @@ -43,4 +43,6 @@ var ipNodeCmd = &cobra.Command{ func init() { ipCmd.AddCommand(ipInternalCmd, ipNodeCmd) + + ShowCmd.AddCommand(ipCmd) } diff --git a/cmd/show/path.go b/cmd/show/path.go index cf833f3..3e9c9e0 100644 --- a/cmd/show/path.go +++ b/cmd/show/path.go @@ -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")), ) }, } @@ -37,7 +37,7 @@ 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)) }, } @@ -45,4 +45,6 @@ func init() { pathVscodeCmd.Flags().Bool("workspace", false, "Get the workspace settings") pathCmd.AddCommand(pathHomeCmd, pathVscodeCmd) + + ShowCmd.AddCommand(pathCmd) } diff --git a/cmd/show/show.go b/cmd/show/show.go index f8990d5..f46900f 100644 --- a/cmd/show/show.go +++ b/cmd/show/show.go @@ -8,7 +8,3 @@ var ShowCmd = &cobra.Command{ Use: "show", Short: "Show information about the current workspace instance", } - -func init() { - ShowCmd.AddCommand(pathCmd, ipCmd) -} diff --git a/cmd/template/apply.go b/cmd/template/apply.go new file mode 100644 index 0000000..44b835d --- /dev/null +++ b/cmd/template/apply.go @@ -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