Skip to content

Commit 1df219f

Browse files
authored
feat(cli): add server command to start Acontext server with sandbox and docker services (#206)
* feat(cli): add server command to start Acontext server with sandbox and docker services * refactor(cli): clean up comments and improve code readability in sandbox and server commands * refactor(platform): abstract process management for Unix and Windows environments * feat(cli): enhance server command with Docker status display and polling functionality
1 parent 6c41ecf commit 1df219f

13 files changed

Lines changed: 1047 additions & 43 deletions

File tree

src/client/acontext-cli/cmd/create_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,3 @@ func TestValidateProjectName(t *testing.T) {
9090
})
9191
}
9292
}
93-

src/client/acontext-cli/cmd/sandbox.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func init() {
3939
}
4040

4141
func runSandboxStart(cmd *cobra.Command, args []string) error {
42-
// Get current working directory
4342
cwd, err := os.Getwd()
4443
if err != nil {
4544
return fmt.Errorf("failed to get current directory: %w", err)
@@ -48,23 +47,19 @@ func runSandboxStart(cmd *cobra.Command, args []string) error {
4847
fmt.Println("📦 Scanning for existing sandbox projects...")
4948
fmt.Println()
5049

51-
// Scan for existing projects
5250
existingProjects, err := sandbox.ScanSandboxProjects(cwd)
5351
if err != nil {
5452
return fmt.Errorf("failed to scan sandbox projects: %w", err)
5553
}
5654

57-
// Get available create options
5855
createOptions, err := sandbox.GetAvailableCreateOptions(cwd)
5956
if err != nil {
6057
return fmt.Errorf("failed to get available create options: %w", err)
6158
}
6259

63-
// Build options list for user selection
6460
var options []string
6561
var optionMap = make(map[string]sandboxOption)
6662

67-
// Add existing projects
6863
for _, p := range existingProjects {
6964
label := fmt.Sprintf("%s (Local) - %s", p.Name, p.Path)
7065
options = append(options, label)
@@ -74,9 +69,7 @@ func runSandboxStart(cmd *cobra.Command, args []string) error {
7469
}
7570
}
7671

77-
// Add create options
7872
for _, p := range createOptions {
79-
// Capitalize first letter
8073
name := p.Name
8174
if len(name) > 0 {
8275
name = strings.ToUpper(string(name[0])) + name[1:]
@@ -93,7 +86,6 @@ func runSandboxStart(cmd *cobra.Command, args []string) error {
9386
return fmt.Errorf("no sandbox options available")
9487
}
9588

96-
// Prompt user to select
9789
var selected string
9890
prompt := &survey.Select{
9991
Message: "Select a sandbox project:",
@@ -110,7 +102,6 @@ func runSandboxStart(cmd *cobra.Command, args []string) error {
110102
return fmt.Errorf("selected option not found")
111103
}
112104

113-
// Handle the selection
114105
if option.isCreate {
115106
return handleCreate(option.project, cwd)
116107
} else {
@@ -124,7 +115,6 @@ type sandboxOption struct {
124115
}
125116

126117
func handleCreate(project sandbox.SandboxProject, baseDir string) error {
127-
// Check if project already exists and prompt for overwrite
128118
if project.Exists {
129119
var overwrite bool
130120
prompt := &survey.Confirm{
@@ -143,7 +133,6 @@ func handleCreate(project sandbox.SandboxProject, baseDir string) error {
143133
}
144134
}
145135

146-
// Prompt for package manager
147136
fmt.Println()
148137
fmt.Println("📦 Select package manager:")
149138
pmOptions := []string{"pnpm", "npm", "yarn", "bun"}
@@ -158,12 +147,6 @@ func handleCreate(project sandbox.SandboxProject, baseDir string) error {
158147
return fmt.Errorf("failed to get package manager selection: %w", err)
159148
}
160149

161-
// Check if package manager is installed
162-
if !isPackageManagerInstalled(selectedPM) {
163-
return fmt.Errorf("package manager '%s' is not installed. Please install it first", selectedPM)
164-
}
165-
166-
// Create the project
167150
if project.Exists {
168151
if err := sandbox.CreateSandboxProjectWithOverwrite(project.Name, selectedPM, baseDir); err != nil {
169152
return fmt.Errorf("failed to create project: %w", err)
@@ -176,29 +159,19 @@ func handleCreate(project sandbox.SandboxProject, baseDir string) error {
176159

177160
fmt.Println()
178161

179-
// Get the project directory
180162
projectDir, err := sandbox.GetProjectDir(baseDir, project.Path)
181163
if err != nil {
182164
return fmt.Errorf("failed to get project directory: %w", err)
183165
}
184166

185-
// Start the project
186167
return sandbox.StartProject(projectDir)
187168
}
188169

189170
func handleStart(project sandbox.SandboxProject, baseDir string) error {
190-
// Get the project directory
191171
projectDir, err := sandbox.GetProjectDir(baseDir, project.Path)
192172
if err != nil {
193173
return fmt.Errorf("failed to get project directory: %w", err)
194174
}
195175

196-
// Start the project
197176
return sandbox.StartProject(projectDir)
198177
}
199-
200-
func isPackageManagerInstalled(pm string) bool {
201-
// This is a simple check - we'll let the actual command execution handle errors
202-
// For now, just return true and let the create command fail if not installed
203-
return true
204-
}

0 commit comments

Comments
 (0)