Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CodeCmd = &cobra.Command{ Use: "code [WORKSPACE] [PROJECT]", Short: "Open a workspace in your preferred IDE", Args: cobra.RangeArgs(0, 2), Aliases: []string{"open"}, Run: func(cmd *cobra.Command, args []string) { c, err := config.GetConfig() if err != nil { log.Fatal(err) } ctx := context.Background() var workspaceId string var projectName string var ideId string activeProfile, err := c.GetActiveProfile() if err != nil { log.Fatal(err) } ideId = c.DefaultIdeId apiClient, err := server.GetApiClient(&activeProfile) if err != nil { log.Fatal(err) } if len(args) == 0 { workspaceList, res, err := apiClient.WorkspaceAPI.ListWorkspaces(ctx).Execute() if err != nil { log.Fatal(apiclient.HandleErrorResponse(res, err)) } workspace := selection.GetWorkspaceFromPrompt(workspaceList, "open") if workspace == nil { return } workspaceId = *workspace.Id } else { workspace, err := server.GetWorkspace(args[0]) if err != nil { log.Fatal(err) } workspaceId = *workspace.Id } if len(args) == 0 || len(args) == 1 { selectedProject, err := selectWorkspaceProject(workspaceId, &activeProfile) if err != nil { log.Fatal(err) } if selectedProject == nil { return } projectName = *selectedProject } if len(args) == 2 { projectName = args[1] } if ideFlag != "" { ideId = ideFlag } view_util.RenderInfoMessage(fmt.Sprintf("Opening the workspace project '%s' in your preferred IDE.", projectName)) err = openIDE(ideId, activeProfile, workspaceId, projectName) if err != nil { log.Fatal(err) } }, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) >= 2 { return nil, cobra.ShellCompDirectiveNoFileComp } if len(args) == 1 { return getProjectNameCompletions(cmd, args, toComplete) } return getWorkspaceNameCompletions() }, }
View Source
var CreateCmd = &cobra.Command{ Use: "create [WORKSPACE_NAME]", Short: "Create a workspace", Args: cobra.RangeArgs(0, 1), Run: func(cmd *cobra.Command, args []string) { ctx := context.Background() var repos []types.Repository var workspaceName string apiClient, err := server.GetApiClient(nil) if err != nil { log.Fatal(err) } c, err := config.GetConfig() if err != nil { log.Fatal(err) } activeProfile, err := c.GetActiveProfile() if err != nil { log.Fatal(err) } view_util.RenderMainTitle("WORKSPACE CREATION") if len(args) == 0 { processPrompting(cmd, apiClient, &workspaceName, &repos, ctx) } else { processCmdArguments(cmd, args, apiClient, &workspaceName, &repos, ctx) } if workspaceName == "" || len(repos) == 0 { log.Fatal("workspace name and repository urls are required") return } visited := make(map[string]bool) for _, repo := range repos { if visited[repo.Url] { log.Fatalf("Error: duplicate repository url: %s", repo.Url) } visited[repo.Url] = true } target, err := getTarget(activeProfile.Name) if err != nil { log.Fatal(err) } activeProfile, err = c.GetActiveProfile() if err != nil { log.Fatal(err) } tsConn, err := tailscale.GetConnection(&activeProfile) if err != nil { log.Fatal(err) } var requestRepos []serverapiclient.Repository for _, repo := range repos { requestRepo := serverapiclient.Repository{ Name: &repo.Name, Url: &repo.Url, Branch: &repo.Branch, } requestRepos = append(requestRepos, requestRepo) } statusProgram := tea.NewProgram(status.NewModel()) started := false go scanWorkspaceLogs(activeProfile, workspaceName, statusProgram, &started) go func() { if _, err := statusProgram.Run(); err != nil { fmt.Println("Error running status program:", err) statusProgram.Send(status.ClearScreenMsg{}) statusProgram.Send(tea.Quit()) err := statusProgram.ReleaseTerminal() if err != nil { log.Error(err) } os.Exit(1) } }() createdWorkspace, res, err := apiClient.WorkspaceAPI.CreateWorkspace(ctx).Workspace(serverapiclient.CreateWorkspace{ Name: &workspaceName, Target: target.Name, Repositories: requestRepos, }).Execute() if err != nil { cleanUpTerminal(statusProgram, apiclient.HandleErrorResponse(res, err)) } dialStartTime := time.Now() dialTimeout := 3 * time.Minute statusProgram.Send(status.ResultMsg{Line: "Establishing connection with the workspace"}) waitForDial(tsConn, *createdWorkspace.Id, *createdWorkspace.Projects[0].Name, dialStartTime, dialTimeout, statusProgram) started = true cleanUpTerminal(statusProgram, nil) wsInfo, res, err := apiClient.WorkspaceAPI.GetWorkspace(ctx, workspaceName).Execute() if err != nil { cleanUpTerminal(statusProgram, apiclient.HandleErrorResponse(res, err)) return } fmt.Println() info.Render(wsInfo) codeFlag, _ := cmd.Flags().GetBool("code") if !codeFlag { return } ide := c.DefaultIdeId if ideFlag != "" { ide = ideFlag } view_util.RenderInfoMessage(fmt.Sprintf("Opening the workspace project '%s' in your preferred IDE.", *wsInfo.Projects[0].Name)) err = openIDE(ide, activeProfile, *createdWorkspace.Id, *wsInfo.Projects[0].Name) if err != nil { log.Fatal(err) } }, }
View Source
var DeleteCmd = &cobra.Command{ Use: "delete [WORKSPACE]", Short: "Delete a workspace", Aliases: []string{"remove", "rm"}, Run: func(cmd *cobra.Command, args []string) { if allFlag { if yesFlag { fmt.Println("Deleting all workspaces.") err := DeleteAllWorkspaces() if err != nil { log.Fatal(err) } } else { form := huh.NewForm( huh.NewGroup( huh.NewConfirm(). Title("Delete all workspaces?"). Description("Are you sure you want to delete all workspaces?"). Value(&yesFlag), ), ).WithTheme(views.GetCustomTheme()) err := form.Run() if err != nil { log.Fatal(err) } if yesFlag { err := DeleteAllWorkspaces() if err != nil { log.Fatal(err) } } else { fmt.Println("Operation canceled.") } } return } c, err := config.GetConfig() if err != nil { log.Fatal(err) } activeProfile, err := c.GetActiveProfile() if err != nil { log.Fatal(err) } ctx := context.Background() var workspace *serverapiclient.WorkspaceDTO apiClient, err := server.GetApiClient(nil) if err != nil { log.Fatal(err) } if len(args) == 0 { workspaceList, res, err := apiClient.WorkspaceAPI.ListWorkspaces(ctx).Execute() if err != nil { log.Fatal(apiclient.HandleErrorResponse(res, err)) } workspace = selection.GetWorkspaceFromPrompt(workspaceList, "delete") } else { workspace, err = server.GetWorkspace(args[0]) if err != nil { log.Fatal(err) } } if workspace == nil { return } res, err := apiClient.WorkspaceAPI.RemoveWorkspace(ctx, *workspace.Id).Execute() if err != nil { log.Fatal(apiclient.HandleErrorResponse(res, err)) } err = config.RemoveWorkspaceSshEntries(activeProfile.Id, *workspace.Id) if err != nil { log.Fatal(err) } util.RenderInfoMessage(fmt.Sprintf("Workspace %s successfully deleted", *workspace.Name)) }, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) > 0 { return nil, cobra.ShellCompDirectiveNoFileComp } return getWorkspaceNameCompletions() }, }
View Source
var InfoCmd = &cobra.Command{ Use: "info", Short: "Show workspace info", Aliases: []string{"view"}, Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { ctx := context.Background() apiClient, err := server.GetApiClient(nil) if err != nil { log.Fatal(err) } var workspace *serverapiclient.WorkspaceDTO if util.WorkspaceMode() { workspace, err = server.GetWorkspace(os.Getenv("DAYTONA_WS_ID")) if err != nil { log.Fatal(err) } } else if len(args) == 0 { workspaceList, res, err := apiClient.WorkspaceAPI.ListWorkspaces(ctx).Verbose(true).Execute() if err != nil { log.Fatal(apiclient.HandleErrorResponse(res, err)) } workspace = selection.GetWorkspaceFromPrompt(workspaceList, "view") } else { workspace, err = server.GetWorkspace(args[0]) if err != nil { log.Fatal(err) } } if workspace == nil { return } if output.FormatFlag != "" { output.Output = workspace return } info.Render(workspace) }, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) > 0 { return nil, cobra.ShellCompDirectiveNoFileComp } return getWorkspaceNameCompletions() }, }
View Source
var ListCmd = &cobra.Command{ Use: "list", Short: "List workspaces", Args: cobra.ExactArgs(0), Aliases: []string{"ls"}, Run: func(cmd *cobra.Command, args []string) { ctx := context.Background() var specifyGitProviders bool apiClient, err := server.GetApiClient(nil) if err != nil { log.Fatal(err) } workspaceList, res, err := apiClient.WorkspaceAPI.ListWorkspaces(ctx).Verbose(verbose).Execute() if err != nil { log.Fatal(apiclient.HandleErrorResponse(res, err)) } serverConfig, res, err := apiClient.ServerAPI.GetConfig(ctx).Execute() if err != nil { log.Fatal(apiclient.HandleErrorResponse(res, err)) } if len(serverConfig.GitProviders) > 1 { specifyGitProviders = true } if output.FormatFlag != "" { output.Output = workspaceList return } if len(workspaceList) == 0 { views_util.RenderInfoMessage("The workspace list is empty. Start off by running 'daytona create'.") return } list_view.ListWorkspaces(workspaceList, specifyGitProviders) }, }
View Source
var SshCmd = &cobra.Command{ Use: "ssh [WORKSPACE] [PROJECT]", Short: "SSH into a project using the terminal", Args: cobra.RangeArgs(0, 2), Run: func(cmd *cobra.Command, args []string) { c, err := config.GetConfig() if err != nil { log.Fatal(err) } activeProfile, err := c.GetActiveProfile() if err != nil { log.Fatal(err) } ctx := context.Background() var workspaceId string var projectName string apiClient, err := server.GetApiClient(&activeProfile) if err != nil { log.Fatal(err) } if len(args) == 0 { workspaceList, res, err := apiClient.WorkspaceAPI.ListWorkspaces(ctx).Execute() if err != nil { log.Fatal(apiclient.HandleErrorResponse(res, err)) } workspace := selection.GetWorkspaceFromPrompt(workspaceList, "ssh into") if workspace == nil { return } workspaceId = *workspace.Id } else { workspace, err := server.GetWorkspace(args[0]) if err != nil { log.Fatal(err) } workspaceId = *workspace.Id } if len(args) == 0 || len(args) == 1 { projectName, err = util.GetFirstWorkspaceProjectName(workspaceId, projectName, &activeProfile) if err != nil { log.Fatal(err) } } if len(args) == 2 { projectName = args[1] } err = ide.OpenTerminalSsh(activeProfile, workspaceId, projectName) if err != nil { log.Fatal(err) } }, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) >= 2 { return nil, cobra.ShellCompDirectiveNoFileComp } if len(args) == 1 { return getProjectNameCompletions(cmd, args, toComplete) } return getWorkspaceNameCompletions() }, }
View Source
var SshProxyCmd = &cobra.Command{ Use: "ssh-proxy [PROFILE_ID] [WORKSPACE_ID] [PROJECT]", Args: cobra.RangeArgs(2, 3), Hidden: true, Run: func(cmd *cobra.Command, args []string) { c, err := config.GetConfig() if err != nil { log.Fatal(err) } profileId := args[0] workspaceId := args[1] projectName := "" profile, err := c.GetProfile(profileId) if err != nil { log.Fatal(err) } if len(args) == 3 { projectName = args[2] } else { projectName, err = util.GetFirstWorkspaceProjectName(workspaceId, projectName, &profile) if err != nil { log.Fatal(err) } } tsConn, err := tailscale.GetConnection(&profile) if err != nil { log.Fatal(err) } errChan := make(chan error) dialConn, err := tsConn.Dial(context.Background(), "tcp", fmt.Sprintf("%s-%s:2222", workspaceId, projectName)) if err != nil { log.Fatal(err) } go func() { _, err := io.Copy(os.Stdout, dialConn) if err != nil { errChan <- err } errChan <- nil }() go func() { _, err := io.Copy(dialConn, os.Stdin) if err != nil { errChan <- err } errChan <- nil }() if err := <-errChan; err != nil { log.Fatal(err) } }, }
View Source
var StartCmd = &cobra.Command{ Use: "start [WORKSPACE]", Short: "Start a workspace", Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { if allFlag { err := startAllWorkspaces() if err != nil { log.Fatal(err) } } ctx := context.Background() var workspaceId string apiClient, err := server.GetApiClient(nil) if err != nil { log.Fatal(err) } if len(args) == 0 { workspaceList, res, err := apiClient.WorkspaceAPI.ListWorkspaces(ctx).Execute() if err != nil { log.Fatal(apiclient.HandleErrorResponse(res, err)) } workspace := selection.GetWorkspaceFromPrompt(workspaceList, "start") if workspace == nil { return } workspaceId = *workspace.Id } else { workspaceId = args[0] } if startProjectFlag == "" { res, err := apiClient.WorkspaceAPI.StartWorkspace(ctx, workspaceId).Execute() if err != nil { log.Fatal(apiclient.HandleErrorResponse(res, err)) } } else { res, err := apiClient.WorkspaceAPI.StartProject(ctx, workspaceId, startProjectFlag).Execute() if err != nil { log.Fatal(apiclient.HandleErrorResponse(res, err)) } } util.RenderInfoMessage(fmt.Sprintf("Workspace %s successfully started", workspaceId)) }, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) != 0 { return nil, cobra.ShellCompDirectiveNoFileComp } return getAllWorkspacesByState(WORKSPACE_STATUS_STOPPED) }, }
View Source
var StopCmd = &cobra.Command{ Use: "stop", Short: "Stop a workspace", Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { if allFlag { err := stopAllWorkspaces() if err != nil { log.Fatal(err) } return } ctx := context.Background() var workspaceId string apiClient, err := server.GetApiClient(nil) if err != nil { log.Fatal(err) } if internal_util.WorkspaceMode() { workspaceId = os.Getenv("DAYTONA_WS_ID") } else if len(args) == 0 { workspaceList, res, err := apiClient.WorkspaceAPI.ListWorkspaces(ctx).Execute() if err != nil { log.Fatal(apiclient.HandleErrorResponse(res, err)) } workspace := selection.GetWorkspaceFromPrompt(workspaceList, "stop") if workspace == nil { return } workspaceId = *workspace.Id } else { workspaceId = args[0] } if stopProjectFlag == "" { res, err := apiClient.WorkspaceAPI.StopWorkspace(ctx, workspaceId).Execute() if err != nil { log.Fatal(apiclient.HandleErrorResponse(res, err)) } } else { res, err := apiClient.WorkspaceAPI.StopProject(ctx, workspaceId, stopProjectFlag).Execute() if err != nil { log.Fatal(apiclient.HandleErrorResponse(res, err)) } } util.RenderInfoMessage(fmt.Sprintf("Workspace %s successfully stopped", workspaceId)) }, ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { if len(args) >= 1 { return nil, cobra.ShellCompDirectiveNoFileComp } return getAllWorkspacesByState(WORKSPACE_STATUS_RUNNING) }, }
Functions ¶
func DeleteAllWorkspaces ¶ added in v0.7.0
func DeleteAllWorkspaces() error
Types ¶
type WorkspaceState ¶ added in v0.4.0
type WorkspaceState string
const ( WORKSPACE_STATUS_RUNNING WorkspaceState = "Running" WORKSPACE_STATUS_STOPPED WorkspaceState = "Unavailable" )
Click to show internal directories.
Click to hide internal directories.