Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 8 additions & 7 deletions cli/cmd/create_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cmd
import (
"errors"
"fmt"
"log"
"os"
"slices"
"strings"
Expand Down Expand Up @@ -65,13 +66,13 @@ func (c *CreateWorkspaceCmd) RunE(_ *cobra.Command, args []string) error {
branch = *ws.InitialBranch.Get()
}

fmt.Println("Workspace created:")
fmt.Printf("\nID: %d\n", ws.Id)
fmt.Printf("Name: %s\n", ws.Name)
fmt.Printf("Team ID: %d\n", ws.TeamId)
fmt.Printf("Git Repository: %s\n", giturl)
fmt.Printf("Branch: %s\n", branch)
fmt.Printf("To open it in the Codesphere IDE run '%s open workspace -w %d'", os.Args[0], ws.Id)
log.Println("Workspace created:")
log.Printf("\nID: %d\n", ws.Id)
log.Printf("Name: %s\n", ws.Name)
log.Printf("Team ID: %d\n", ws.TeamId)
log.Printf("Git Repository: %s\n", giturl)
log.Printf("Branch: %s\n", branch)
log.Printf("To open it in the Codesphere IDE run '%s open workspace -w %d'", os.Args[0], ws.Id)

return nil
}
Expand Down
5 changes: 3 additions & 2 deletions cli/cmd/delete_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cmd
import (
"errors"
"fmt"
"log"

"github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -65,7 +66,7 @@ func (c *DeleteWorkspaceCmd) DeleteWorkspace(client Client, wsId int) error {
}

if !*c.Opts.Confirmed {
fmt.Printf("Please confirm deletion of workspace '%s', ID %d, in team %d by entering its name:\n", workspace.Name, workspace.Id, workspace.TeamId)
log.Printf("Please confirm deletion of workspace '%s', ID %d, in team %d by entering its name:\n", workspace.Name, workspace.Id, workspace.TeamId)
confirmation := c.Prompt.InputPrompt("Confirmation delete")

if confirmation != workspace.Name {
Expand All @@ -78,6 +79,6 @@ func (c *DeleteWorkspaceCmd) DeleteWorkspace(client Client, wsId int) error {
return err
}

fmt.Printf("Workspace %d deleted successfully\n", wsId)
log.Printf("Workspace %d deleted successfully\n", wsId)
return nil
}
9 changes: 5 additions & 4 deletions cli/cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cmd

import (
"fmt"
"log"
"os"
"strings"

Expand All @@ -28,7 +29,7 @@ type ExecOptions struct {

func (c *ExecCmd) RunE(_ *cobra.Command, args []string) error {
command := strings.Join(args, " ")
fmt.Printf("running command %s\n", command)
log.Printf("running command %s\n", command)

client, err := NewClient(c.Opts.GlobalOptions)
if err != nil {
Expand Down Expand Up @@ -74,10 +75,10 @@ func (c *ExecCmd) ExecCommand(client Client, command string) error {

stdout, stderr, err := client.ExecCommand(wsId, command, *c.Opts.WorkDir, envVarMap)

fmt.Println("STDOUT:")
fmt.Println(stdout)
log.Println("STDOUT:")
log.Println(stdout)
if stderr != "" {
fmt.Println("STDERR:")
log.Println("STDERR:")
fmt.Fprintln(os.Stderr, stderr)
}
return errors.FormatAPIError(err)
Expand Down
27 changes: 14 additions & 13 deletions cli/cmd/generate_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cmd
import (
"errors"
"fmt"
"log"
"path"

"github.com/codesphere-cloud/cs-go/pkg/cs"
Expand All @@ -27,7 +28,7 @@ type GenerateDockerOpts struct {
}

func (c *GenerateDockerCmd) RunE(cc *cobra.Command, args []string) error {
fmt.Println(c.Opts.Force)
log.Println(c.Opts.Force)
fs := cs.NewOSFileSystem(".")
git := git.NewGitService(fs)

Expand All @@ -41,17 +42,17 @@ func (c *GenerateDockerCmd) RunE(cc *cobra.Command, args []string) error {
return fmt.Errorf("failed to generate docker: %w", err)
}

fmt.Println("docker artifacts created:")
fmt.Printf("Input: %s\n", c.Opts.Input)
fmt.Printf("Output: %s\n", c.Opts.Output)
log.Println("docker artifacts created:")
log.Printf("Input: %s\n", c.Opts.Input)
log.Printf("Output: %s\n", c.Opts.Output)

fmt.Println("To start with docker-compose, run:")
fmt.Printf("cd %s && docker compose up\n\n", c.Opts.Output)
log.Println("To start with docker-compose, run:")
log.Printf("cd %s && docker compose up\n\n", c.Opts.Output)

fmt.Println("To build and push images, run:")
fmt.Println("export REGISTRY=<your-registry>")
fmt.Println("export IMAGE_PREFIX=<some-prefix>")
fmt.Printf("%s generate images --reporoot %s -r $REGISTRY -p $IMAGE_PREFIX -i %s -o %s\n\n", io.BinName(), c.Opts.RepoRoot, c.Opts.Input, c.Opts.Output)
log.Println("To build and push images, run:")
log.Println("export REGISTRY=<your-registry>")
log.Println("export IMAGE_PREFIX=<some-prefix>")
log.Printf("%s generate images --reporoot %s -r $REGISTRY -p $IMAGE_PREFIX -i %s -o %s\n\n", io.BinName(), c.Opts.RepoRoot, c.Opts.Input, c.Opts.Output)

return nil
}
Expand Down Expand Up @@ -101,7 +102,7 @@ func (c *GenerateDockerCmd) GenerateDocker(fs *cs.FileSystem, exp exporter.Expor

ciInput := path.Join(c.Opts.RepoRoot, c.Opts.Input)
if !fs.FileExists(ciInput) {
fmt.Printf("Input file %s not found attempting to clone workspace repository...\n", c.Opts.Input)
log.Printf("Input file %s not found attempting to clone workspace repository...\n", c.Opts.Input)

if err := c.CloneRepository(csClient, fs, git, c.Opts.RepoRoot); err != nil {
return fmt.Errorf("failed to clone repository: %w", err)
Expand All @@ -125,7 +126,7 @@ func (c *GenerateDockerCmd) GenerateDocker(fs *cs.FileSystem, exp exporter.Expor
}

func (c *GenerateDockerCmd) CloneRepository(client Client, fs *cs.FileSystem, git git.Git, clonedir string) error {
fmt.Printf("Cloning repository into %s...\n", clonedir)
log.Printf("Cloning repository into %s...\n", clonedir)

wsId, err := c.Opts.GetWorkspaceId()
if err != nil {
Expand All @@ -152,6 +153,6 @@ func (c *GenerateDockerCmd) CloneRepository(client Client, fs *cs.FileSystem, gi
return fmt.Errorf("failed to clone repository %s branch %s: %w", repoUrl, repoBranch, err)
}

fmt.Printf("Repository %s, branch %s cloned.\n", repoUrl, repoBranch)
log.Printf("Repository %s, branch %s cloned.\n", repoUrl, repoBranch)
return nil
}
9 changes: 5 additions & 4 deletions cli/cmd/generate_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"log"
"path"

"github.com/codesphere-cloud/cs-go/pkg/cs"
Expand Down Expand Up @@ -34,10 +35,10 @@ func (c *GenerateImagesCmd) RunE(_ *cobra.Command, args []string) error {
return fmt.Errorf("failed to generate images: %w", err)
}

fmt.Println("Images created:")
fmt.Printf("Container images from %s pushed to %s\n", c.Opts.Input, c.Opts.Registry)
fmt.Println("To generate kubernetes artifacts next, run:")
fmt.Printf("%s generate kubernetes --reporoot %s -r %s -p %s -i %s -o %s", io.BinName(), c.Opts.RepoRoot, c.Opts.Registry, c.Opts.ImagePrefix, c.Opts.Input, c.Opts.Output)
log.Println("Images created:")
log.Printf("Container images from %s pushed to %s\n", c.Opts.Input, c.Opts.Registry)
log.Println("To generate kubernetes artifacts next, run:")
log.Printf("%s generate kubernetes --reporoot %s -r %s -p %s -i %s -o %s", io.BinName(), c.Opts.RepoRoot, c.Opts.Registry, c.Opts.ImagePrefix, c.Opts.Input, c.Opts.Output)

return nil
}
Expand Down
5 changes: 3 additions & 2 deletions cli/cmd/generate_kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package cmd
import (
"errors"
"fmt"
"log"
"path"

"github.com/codesphere-cloud/cs-go/pkg/cs"
Expand Down Expand Up @@ -37,8 +38,8 @@ func (c *GenerateKubernetesCmd) RunE(_ *cobra.Command, args []string) error {
return fmt.Errorf("failed to generate kubernetes: %w", err)
}

fmt.Println("Kubernetes artifacts export successful. You can apply the resources with the following command:")
fmt.Printf("kubectl apply -f %s\n", path.Join(c.Opts.RepoRoot, c.Opts.Output, "kubernetes"))
log.Println("Kubernetes artifacts export successful. You can apply the resources with the following command:")
log.Printf("kubectl apply -f %s\n", path.Join(c.Opts.RepoRoot, c.Opts.Output, "kubernetes"))
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/git_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cmd

import (
"fmt"
"log"

"github.com/codesphere-cloud/cs-go/pkg/io"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -38,7 +39,7 @@ func (c *GitPullCmd) RunE(_ *cobra.Command, args []string) error {
return err
}

fmt.Printf("Git pull completed successfully for workspace %d\n", wsId)
log.Printf("Git pull completed successfully for workspace %d\n", wsId)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"compress/gzip"
_ "embed"
"encoding/base64"
"fmt"
"io"
"log"
"strings"

"github.com/codesphere-cloud/cs-go/pkg/tmpl"
Expand All @@ -23,7 +23,7 @@ func (c *GoCmd) RunE(_ *cobra.Command, args []string) error {
x, _ := gzip.NewReader(strings.NewReader(tmpl.GoData()))
s, _ := io.ReadAll(x)
d, _ := base64.StdEncoding.DecodeString(string(s))
fmt.Print(string(d))
log.Print(string(d))
return nil
}

Expand Down
12 changes: 6 additions & 6 deletions cli/cmd/licenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package cmd

import (
_ "embed"
"fmt"
"log"

"github.com/codesphere-cloud/cs-go/pkg/tmpl"
"github.com/spf13/cobra"
Expand All @@ -16,13 +16,13 @@ type LicensesCmd struct {
}

func (c *LicensesCmd) RunE(_ *cobra.Command, args []string) error {
fmt.Println("Codesphere CLI License:")
fmt.Println(tmpl.License())
log.Println("Codesphere CLI License:")
log.Println(tmpl.License())

fmt.Println("=================================")
log.Println("=================================")

fmt.Println("Codesphere CLI licenses included work:")
fmt.Println(tmpl.Notice())
log.Println("Codesphere CLI licenses included work:")
log.Println(tmpl.Notice())

return nil
}
Expand Down
7 changes: 4 additions & 3 deletions cli/cmd/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/json"
"fmt"
"io"
stdlog "log"
"log/slog"
"net/http"
"strings"
Expand Down Expand Up @@ -105,7 +106,7 @@ func (l *LogCmd) RunE(_ *cobra.Command, args []string) (err error) {
}

func (l *LogCmd) printAllLogs() error {
fmt.Println("Printing logs of all replicas")
stdlog.Println("Printing logs of all replicas")

replicas, err := cs.GetPipelineStatus(l.scope.workspaceId, *l.scope.stage)
if err != nil {
Expand All @@ -124,7 +125,7 @@ func (l *LogCmd) printAllLogs() error {
prefix := fmt.Sprintf("|%-10s|%s", replica.Server, replica.Replica[len(replica.Replica)-11:])
err = l.printLogsOfReplica(prefix)
if err != nil {
fmt.Printf("Error printling logs: %s\n", err.Error())
stdlog.Printf("Error printling logs: %s\n", err.Error())
}
}()
}
Expand Down Expand Up @@ -251,7 +252,7 @@ func printLogsOfEndpoint(prefix string, endpoint string) error {
}

for i := 0; i < len(log); i++ {
fmt.Printf("%s%s| %s", log[i].Timestamp, prefix, log[i].Data)
stdlog.Printf("%s%s| %s", log[i].Timestamp, prefix, log[i].Data)
}
}
}
4 changes: 2 additions & 2 deletions cli/cmd/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package cmd_test

import (
"context"
"fmt"
"log"
"time"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -90,7 +90,7 @@ var _ = Describe("Monitor", func() {
It("Restarts immediately", func() {
mockExec.EXPECT().ExecuteCommand(mock.Anything, mock.Anything).RunAndReturn(
func(ctx context.Context, args []string) (int, error) {
fmt.Println("lol")
log.Println("lol")
mockTime.Sleep(300 * time.Millisecond)
return 0, nil
}).Twice()
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package cmd

import (
"fmt"
"log"

"github.com/spf13/cobra"

Expand All @@ -16,7 +16,7 @@ type OpenCmd struct {
}

func (c *OpenCmd) RunE(_ *cobra.Command, args []string) error {
fmt.Println("Opening Codesphere IDE")
log.Println("Opening Codesphere IDE")
return cs.NewBrowser().OpenIde("")
}

Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/open_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cmd

import (
"fmt"
"log"

"github.com/codesphere-cloud/cs-go/pkg/cs"
"github.com/codesphere-cloud/cs-go/pkg/io"
Expand Down Expand Up @@ -57,7 +58,7 @@ func (cmd *OpenWorkspaceCmd) OpenWorkspace(browser Browser, client Client, wsId
return fmt.Errorf("failed to get workspace: %w", err)
}

fmt.Printf("Opening workspace %d in Codesphere IDE\n", wsId)
log.Printf("Opening workspace %d in Codesphere IDE\n", wsId)

err = browser.OpenIde(fmt.Sprintf("teams/%d/workspaces/%d", workspace.TeamId, wsId))
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/set_env_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cmd

import (
"fmt"
"log"

"github.com/codesphere-cloud/cs-go/pkg/cs"
"github.com/codesphere-cloud/cs-go/pkg/io"
Expand Down Expand Up @@ -67,6 +68,6 @@ func (l *SetEnvVarCmd) SetEnvironmentVariables(client Client) (err error) {
return fmt.Errorf("failed to set environment variables %v: %w", envVarMap, err)
}

fmt.Printf("Environment variables set successfully on workspace %d\n", wsId)
log.Printf("Environment variables set successfully on workspace %d\n", wsId)
return nil
}
Loading