Skip to content

Commit

Permalink
feat: tui redesign
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Dagelic <[email protected]>
  • Loading branch information
idagelic committed Apr 29, 2024
1 parent 65105a1 commit d8ee965
Show file tree
Hide file tree
Showing 74 changed files with 1,281 additions and 488 deletions.
20 changes: 16 additions & 4 deletions pkg/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package cmd

import (
"fmt"
"os"

"github.com/daytonaio/daytona/internal/util"
Expand All @@ -14,8 +13,9 @@ import (
. "github.com/daytonaio/daytona/pkg/cmd/ports"
. "github.com/daytonaio/daytona/pkg/cmd/profile"
. "github.com/daytonaio/daytona/pkg/cmd/server"
apikeyCmd "github.com/daytonaio/daytona/pkg/cmd/server/apikey"
. "github.com/daytonaio/daytona/pkg/cmd/workspace"
view_util "github.com/daytonaio/daytona/pkg/views/util"
view "github.com/daytonaio/daytona/pkg/views/initial"
log "github.com/sirupsen/logrus"

"github.com/spf13/cobra"
Expand All @@ -26,11 +26,23 @@ var rootCmd = &cobra.Command{
Short: "Daytona is a Dev Environment Manager",
Long: "Daytona is a Dev Environment Manager",
Run: func(cmd *cobra.Command, args []string) {
fmt.Print(view_util.GetLongDescription())
err := cmd.Help()
command, err := view.GetCommand()
if err != nil {
log.Fatal(err)
}

switch command {
case "list":
ListCmd.Run(cmd, args)
case "profile add":
ProfileAddCmd.Run(cmd, []string{})
case "server api-key new":
apikeyCmd.GenerateCmd.Run(cmd, []string{})
case "create":
CreateCmd.Run(cmd, []string{})
case "help":
cmd.Help()
}
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/gitprovider/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/daytonaio/daytona/internal/util/apiclient/server"
"github.com/daytonaio/daytona/pkg/serverapiclient"
"github.com/daytonaio/daytona/pkg/views"
gitprovider_view "github.com/daytonaio/daytona/pkg/views/gitprovider"
"github.com/daytonaio/daytona/pkg/views/util"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -43,6 +43,6 @@ var gitProviderAddCmd = &cobra.Command{
log.Fatal(err)
}

util.RenderInfoMessage("Git provider has been registered")
views.RenderInfoMessage("Git provider has been registered")
},
}
6 changes: 3 additions & 3 deletions pkg/cmd/gitprovider/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/daytonaio/daytona/internal/util/apiclient"
"github.com/daytonaio/daytona/internal/util/apiclient/server"
"github.com/daytonaio/daytona/pkg/serverapiclient"
"github.com/daytonaio/daytona/pkg/views"
gitprovider_view "github.com/daytonaio/daytona/pkg/views/gitprovider"
"github.com/daytonaio/daytona/pkg/views/util"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -39,7 +39,7 @@ var gitProviderDeleteCmd = &cobra.Command{
gitProviderData.BaseApiUrl = new(string)

if len(gitProviders) == 0 {
util.RenderInfoMessage("No git providers registered")
views.RenderInfoMessage("No git providers registered")
return
}

Expand All @@ -55,6 +55,6 @@ var gitProviderDeleteCmd = &cobra.Command{
log.Fatal(err)
}

util.RenderInfoMessage("Git provider has been removed")
views.RenderInfoMessage("Git provider has been removed")
},
}
8 changes: 4 additions & 4 deletions pkg/cmd/gitprovider/gitprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/daytonaio/daytona/internal/util/apiclient"
"github.com/daytonaio/daytona/internal/util/apiclient/server"
"github.com/daytonaio/daytona/pkg/cmd/output"
"github.com/daytonaio/daytona/pkg/views"
gitprovider_view "github.com/daytonaio/daytona/pkg/views/gitprovider"
"github.com/daytonaio/daytona/pkg/views/util"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand All @@ -33,11 +33,11 @@ var GitProviderCmd = &cobra.Command{
}

if len(gitProviders) == 0 {
util.RenderInfoMessage("No git providers registered. Add a new git provider by preparing a Personal Access Token and running 'daytona git-providers add'")
views.RenderInfoMessage("No git providers registered. Add a new git provider by preparing a Personal Access Token and running 'daytona git-providers add'")
return
}

util.RenderMainTitle("Registered Git providers:")
views.RenderMainTitle("Registered Git providers:")

supportedProviders := config.GetSupportedGitProviders()
var gitProviderViewList []gitprovider_view.GitProviderView
Expand All @@ -62,7 +62,7 @@ var GitProviderCmd = &cobra.Command{
}

for _, gitProviderView := range gitProviderViewList {
util.RenderListLine(fmt.Sprintf("%s (%s)", gitProviderView.Name, gitProviderView.Username))
views.RenderListLine(fmt.Sprintf("%s (%s)", gitProviderView.Name, gitProviderView.Username))
}
},
}
Expand Down
6 changes: 2 additions & 4 deletions pkg/cmd/ide.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
package cmd

import (
"fmt"

"github.com/daytonaio/daytona/cmd/daytona/config"
"github.com/daytonaio/daytona/pkg/views"
"github.com/daytonaio/daytona/pkg/views/ide"
"github.com/daytonaio/daytona/pkg/views/util"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -45,6 +43,6 @@ var ideCmd = &cobra.Command{
log.Fatal(err)
}

util.RenderInfoMessage(fmt.Sprintf("Default IDE set to: %s", chosenIde.Name))
views.RenderDefaultIdeUpdated(chosenIde.Name)
},
}
10 changes: 5 additions & 5 deletions pkg/cmd/ports/forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/daytonaio/daytona/internal/util/apiclient/server"
"github.com/daytonaio/daytona/pkg/frpc"
"github.com/daytonaio/daytona/pkg/ports"
view_util "github.com/daytonaio/daytona/pkg/views/util"
"github.com/daytonaio/daytona/pkg/views"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -61,9 +61,9 @@ var PortForwardCmd = &cobra.Command{
}
} else {
if *hostPort != uint16(port) {
view_util.RenderInfoMessage(fmt.Sprintf("Port %d already in use.", port))
views.RenderInfoMessage(fmt.Sprintf("Port %d already in use.", port))
}
view_util.RenderInfoMessage(fmt.Sprintf("Port available at http://localhost:%d\n", *hostPort))
views.RenderInfoMessage(fmt.Sprintf("Port available at http://localhost:%d\n", *hostPort))
}

if publicPreview {
Expand Down Expand Up @@ -98,7 +98,7 @@ func init() {
}

func forwardPublicPort(workspaceId, projectName string, hostPort, targetPort uint16) error {
view_util.RenderInfoMessage("Forwarding port to a public URL...")
views.RenderInfoMessage("Forwarding port to a public URL...")

apiClient, err := server.GetApiClient(nil)
if err != nil {
Expand All @@ -117,7 +117,7 @@ func forwardPublicPort(workspaceId, projectName string, hostPort, targetPort uin

go func() {
time.Sleep(1 * time.Second)
view_util.RenderInfoMessage(fmt.Sprintf("Port available at %s", fmt.Sprintf("%s://%s.%s", *serverConfig.Frps.Protocol, subDomain, *serverConfig.Frps.Domain)))
views.RenderInfoMessage(fmt.Sprintf("Port available at %s", fmt.Sprintf("%s://%s.%s", *serverConfig.Frps.Protocol, subDomain, *serverConfig.Frps.Domain)))
}()

return frpc.Connect(frpc.FrpcConnectParams{
Expand Down
8 changes: 4 additions & 4 deletions pkg/cmd/profile/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/spf13/cobra"
)

var profileAddCmd = &cobra.Command{
var ProfileAddCmd = &cobra.Command{
Use: "add",
Short: "Add profile",
Args: cobra.NoArgs,
Expand Down Expand Up @@ -97,7 +97,7 @@ var apiUrlFlag string
var apiKeyFlag string

func init() {
profileAddCmd.Flags().StringVarP(&profileNameFlag, "name", "n", "", "Profile name")
profileAddCmd.Flags().StringVarP(&apiUrlFlag, "api-url", "a", "", "API URL")
profileAddCmd.Flags().StringVarP(&apiKeyFlag, "api-key", "k", "", "API Key")
ProfileAddCmd.Flags().StringVarP(&profileNameFlag, "name", "n", "", "Profile name")
ProfileAddCmd.Flags().StringVarP(&apiUrlFlag, "api-url", "a", "", "API URL")
ProfileAddCmd.Flags().StringVarP(&apiKeyFlag, "api-key", "k", "", "API Key")
}
10 changes: 5 additions & 5 deletions pkg/cmd/profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"fmt"

"github.com/daytonaio/daytona/cmd/daytona/config"
"github.com/daytonaio/daytona/pkg/views"
"github.com/daytonaio/daytona/pkg/views/profile"
"github.com/daytonaio/daytona/pkg/views/util"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand All @@ -27,12 +27,12 @@ var ProfileCmd = &cobra.Command{
profilesList := c.Profiles

if len(profilesList) == 0 {
util.RenderInfoMessage("Add a profile by running `daytona profile add")
views.RenderInfoMessage("Add a profile by running `daytona profile add`")
return
}

if len(profilesList) == 1 {
util.RenderInfoMessage(fmt.Sprintf("You are using profile %s. Add a new profile by running `daytona profile add`", profilesList[0].Name))
views.RenderInfoMessage(fmt.Sprintf("You are using profile %s. Add a new profile by running `daytona profile add`", profilesList[0].Name))
return
}

Expand Down Expand Up @@ -62,14 +62,14 @@ var ProfileCmd = &cobra.Command{
log.Fatal(err)
}

util.RenderInfoMessage(fmt.Sprintf("Active profile set to: %s", chosenProfile.Name))
views.RenderInfoMessage(fmt.Sprintf("Active profile set to: %s", chosenProfile.Name))
},
}

func init() {
ProfileCmd.AddCommand(profileListCmd)
ProfileCmd.AddCommand(ProfileUseCmd)
ProfileCmd.AddCommand(profileAddCmd)
ProfileCmd.AddCommand(ProfileAddCmd)
ProfileCmd.AddCommand(profileEditCmd)
ProfileCmd.AddCommand(profileDeleteCmd)
}
4 changes: 2 additions & 2 deletions pkg/cmd/profile/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
log "github.com/sirupsen/logrus"

"github.com/daytonaio/daytona/pkg/cmd/output"
view_util "github.com/daytonaio/daytona/pkg/views/util"
"github.com/daytonaio/daytona/pkg/views"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -56,6 +56,6 @@ var ProfileUseCmd = &cobra.Command{
return
}

view_util.RenderInfoMessage(fmt.Sprintf("Active profile set to %s", chosenProfile.Name))
views.RenderInfoMessage(fmt.Sprintf("Active profile set to %s", chosenProfile.Name))
},
}
18 changes: 9 additions & 9 deletions pkg/cmd/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package cmd
import (
"github.com/daytonaio/daytona/cmd/daytona/config"
workspace "github.com/daytonaio/daytona/pkg/cmd/workspace"
"github.com/daytonaio/daytona/pkg/views"
profile_view "github.com/daytonaio/daytona/pkg/views/profile"
view "github.com/daytonaio/daytona/pkg/views/purge"
view_util "github.com/daytonaio/daytona/pkg/views/util"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand All @@ -33,7 +33,7 @@ var purgeCmd = &cobra.Command{
if c.ActiveProfileId != "default" {
profile_view.SwitchToDefaultPrompt(&switchProfileCheck)
if !switchProfileCheck {
view_util.RenderInfoMessage("Operation cancelled.")
views.RenderInfoMessage("Operation cancelled.")
return
}
c.ActiveProfileId = "default"
Expand All @@ -46,42 +46,42 @@ var purgeCmd = &cobra.Command{
if !yesFlag {
view.ConfirmPrompt(&confirmCheck)
if !confirmCheck {
view_util.RenderInfoMessage("Operation cancelled.")
views.RenderInfoMessage("Operation cancelled.")
return
}
}

view_util.RenderLine("\nDeleting all workspaces")
views.RenderLine("\nDeleting all workspaces")
err = workspace.DeleteAllWorkspaces()
if err != nil {
log.Fatal(err)
}

view_util.RenderLine("Deleting the SSH configuration file")
views.RenderLine("Deleting the SSH configuration file")
err = config.UnlinkSshFiles()
if err != nil {
log.Fatal(err)
}

view_util.RenderLine("Deleting autocompletion data")
views.RenderLine("Deleting autocompletion data")
err = config.DeleteAutocompletionData()
if err != nil {
log.Fatal(err)
}

view.ServerStoppedPrompt(&serverStoppedCheck)
if !serverStoppedCheck {
view_util.RenderInfoMessage("Operation cancelled.")
views.RenderInfoMessage("Operation cancelled.")
return
}

view_util.RenderLine("Deleting the Daytona config directory")
views.RenderLine("Deleting the Daytona config directory")
err = config.DeleteConfigDir()
if err != nil {
log.Fatal(err)
}

view_util.RenderInfoMessage("All Daytona data has been successfully cleared from the device.\nYou may now delete the binary.")
views.RenderInfoMessage("All Daytona data has been successfully cleared from the device.\nYou may now delete the binary.")
},
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/server/apikey/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var ApiKeyCmd = &cobra.Command{
}

func init() {
ApiKeyCmd.AddCommand(generateCmd)
ApiKeyCmd.AddCommand(GenerateCmd)
ApiKeyCmd.AddCommand(revokeCmd)
ApiKeyCmd.AddCommand(listCmd)
}
10 changes: 5 additions & 5 deletions pkg/cmd/server/apikey/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
"github.com/daytonaio/daytona/cmd/daytona/config"
"github.com/daytonaio/daytona/internal/util/apiclient"
"github.com/daytonaio/daytona/internal/util/apiclient/server"
"github.com/daytonaio/daytona/pkg/views"
"github.com/daytonaio/daytona/pkg/views/server/apikey"
"github.com/daytonaio/daytona/pkg/views/util"
)

var saveFlag bool

var generateCmd = &cobra.Command{
var GenerateCmd = &cobra.Command{
Use: "generate [NAME]",
Short: "Generate a new API key",
Aliases: []string{"g", "new"},
Expand Down Expand Up @@ -60,11 +60,11 @@ var generateCmd = &cobra.Command{
if err != nil {
log.Fatal(err)
}
util.RenderBorderedMessage("API key saved to your default profile")
views.RenderBorderedMessage("API key saved to your default profile")
return
}

util.RenderBorderedMessage(fmt.Sprintf("Generated API key: %s\n\nYou can add it to a profile by running:\n\ndaytona profile edit -k %s\n\nMake sure to copy it as you will not be able to see it again.", key, key))
views.RenderBorderedMessage(fmt.Sprintf("Generated API key: %s\n\nYou can add it to a profile by running:\n\ndaytona profile edit -k %s\n\nMake sure to copy it as you will not be able to see it again.", key, key))
},
}

Expand All @@ -85,5 +85,5 @@ func saveKeyToDefaultProfile(key string) error {
}

func init() {
generateCmd.Flags().BoolVarP(&saveFlag, "save", "s", false, "Save the API key to your default profile on this machine")
GenerateCmd.Flags().BoolVarP(&saveFlag, "save", "s", false, "Save the API key to your default profile on this machine")
}
3 changes: 1 addition & 2 deletions pkg/cmd/server/apikey/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/daytonaio/daytona/pkg/serverapiclient"
"github.com/daytonaio/daytona/pkg/views"
"github.com/daytonaio/daytona/pkg/views/server/apikey"
"github.com/daytonaio/daytona/pkg/views/util"
)

var yesFlag bool
Expand Down Expand Up @@ -97,7 +96,7 @@ var revokeCmd = &cobra.Command{
log.Fatal(apiclient.HandleErrorResponse(nil, err))
}

util.RenderInfoMessage("API key revoked")
views.RenderInfoMessage("API key revoked")
} else {
fmt.Println("Operation canceled.")
}
Expand Down
Loading

0 comments on commit d8ee965

Please sign in to comment.