Skip to content

Commit 8c268c0

Browse files
committed
feat: add visibility selection when uploading snapshots
- Prompt user to choose config visibility: public, unlisted, or private - Customize success message based on visibility level - Only auto-open browser for public configs to avoid 500 errors - Send visibility field to API during upload
1 parent 1047cdf commit 8c268c0

1 file changed

Lines changed: 45 additions & 12 deletions

File tree

internal/cli/snapshot.go

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,28 @@ func uploadSnapshot(snap *snapshot.Snapshot) error {
212212
configName = "My Mac Setup"
213213
}
214214

215+
fmt.Fprintln(os.Stderr)
216+
visibilityOptions := []string{
217+
"Public - Anyone can discover and use this config",
218+
"Unlisted - Only people with the link can access",
219+
"Private - Only you can see this config",
220+
}
221+
visibilityChoice, err := ui.SelectOption("Who can see this config?", visibilityOptions)
222+
if err != nil {
223+
return fmt.Errorf("failed to select visibility: %w", err)
224+
}
225+
226+
visibility := "unlisted"
227+
if strings.HasPrefix(visibilityChoice, "Public") {
228+
visibility = "public"
229+
} else if strings.HasPrefix(visibilityChoice, "Private") {
230+
visibility = "private"
231+
}
232+
215233
reqBody := map[string]interface{}{
216-
"name": configName,
217-
"snapshot": snap,
234+
"name": configName,
235+
"snapshot": snap,
236+
"visibility": visibility,
218237
}
219238
bodyBytes, err := json.Marshal(reqBody)
220239
if err != nil {
@@ -258,18 +277,32 @@ func uploadSnapshot(snap *snapshot.Snapshot) error {
258277
fmt.Fprintln(os.Stderr)
259278
fmt.Fprintln(os.Stderr, snapSuccessStyle.Render("✓ Config uploaded successfully!"))
260279
fmt.Fprintln(os.Stderr)
261-
fmt.Fprintln(os.Stderr, snapBoldStyle.Render(" View your config:"))
262-
fmt.Fprintf(os.Stderr, " %s\n", configURL)
263-
fmt.Fprintln(os.Stderr)
264-
fmt.Fprintln(os.Stderr, snapBoldStyle.Render(" Share with others:"))
265-
fmt.Fprintf(os.Stderr, " %s\n", installURL)
266-
fmt.Fprintln(os.Stderr)
267280

268-
// Auto-open browser
269-
if err := exec.Command("open", configURL).Start(); err != nil {
270-
ui.Warn(fmt.Sprintf("Could not open browser: %v", err))
281+
if visibility == "public" {
282+
fmt.Fprintln(os.Stderr, snapBoldStyle.Render(" View your config:"))
283+
fmt.Fprintf(os.Stderr, " %s\n", configURL)
284+
fmt.Fprintln(os.Stderr)
285+
fmt.Fprintln(os.Stderr, snapBoldStyle.Render(" Share with others:"))
286+
fmt.Fprintf(os.Stderr, " %s\n", installURL)
287+
fmt.Fprintln(os.Stderr)
288+
if err := exec.Command("open", configURL).Start(); err != nil {
289+
ui.Warn(fmt.Sprintf("Could not open browser: %v", err))
290+
}
291+
fmt.Fprintln(os.Stderr, snapMutedStyle.Render(" Opening in browser..."))
292+
} else if visibility == "unlisted" {
293+
fmt.Fprintln(os.Stderr, snapBoldStyle.Render(" View your config:"))
294+
fmt.Fprintf(os.Stderr, " %s\n", configURL)
295+
fmt.Fprintln(os.Stderr)
296+
fmt.Fprintln(os.Stderr, snapBoldStyle.Render(" Share with people who have the link:"))
297+
fmt.Fprintf(os.Stderr, " %s\n", installURL)
298+
fmt.Fprintln(os.Stderr)
299+
fmt.Fprintln(os.Stderr, snapMutedStyle.Render(" (This config is unlisted - only people with the link can access it)"))
300+
} else {
301+
fmt.Fprintln(os.Stderr, snapBoldStyle.Render(" Manage your config:"))
302+
fmt.Fprintf(os.Stderr, " %s\n", configURL)
303+
fmt.Fprintln(os.Stderr)
304+
fmt.Fprintln(os.Stderr, snapMutedStyle.Render(" (This config is private - only you can see it)"))
271305
}
272-
fmt.Fprintln(os.Stderr, snapMutedStyle.Render(" Opening in browser..."))
273306
fmt.Fprintln(os.Stderr)
274307

275308
return nil

0 commit comments

Comments
 (0)